deviant art





Login
Join deviantART for FREE Take the Tour Lost Password?
Deviant Login
Shop  Join deviantART for FREE Take the Tour
About Me Member Software Developer MitigationMale/United States Recent Activity
Deviant for 4 Years
Needs Premium Membership
Statistics 0 Deviations 4 Comments 503 Pageviews
function entry()
   print( "Hello Luanpiss off" )
   return 1
end

--Table Constructor
tblTest = {}

--Data is added to table
tblTest.TblData = "I have teh chills"
tblTest["TblData1"] = "This is a string"

--Data in table is printed
print(tblTest.TblData)
print(tblTest["Greg"])

--Test to determine passed values
print(entry(data))

--Table Constructor with data??(ask mark)
tblTest2 = {
test = "thisvalue",
nothertest = "thatvalue",
}
--Test
print(tblTest2.test)

-- This next part refrences code completed in earlier chapters so
-- bear with it

tblbob = {}
function tblbob.convert_c2f(celsius)
   return ((celsius * 1.8) + 32)
end

print(tblbob.convert_c2f(-40))

--Simple implementation of a counter, controlled with get and inc

counter = {
   count = 0
}
  
function counter.get(self)
return self.count
end

function counter.inc(self)
    self.count = self.count + 1
end

print(counter.get(counter))

--MetaTables and MetaMethods.  WTF am I doing.

tbl1 = {"alpha", "Beta", "Cappa"}
tbl2 = {"Mark", "Stephanie", "Greg"}
tbl3 = {}
mt = {}

--Metamethod __add

function mt.__add(a, b)
local result = setmetatable({}, mt)

for i=1, a do
    table.insert(result, a[i])
    end
    
for i=1, b do
    table.insert(result, b[i])

    end
    
    return result
end

--Metamethod __unm(unary minus)

function mt.__unm(a)
local result = setmetatable({}, mt)

for i=#a,1,-1 do
table.insert(result, a[i])
end

return result
end

--Metamethod __tostring

function mt.__tostring(tbl1)
local result = "{"

for i=1, tbl1 do
if i > 1 then
  result = result .. ", "
end

result = result .. tos tring(tbl[1])

end
result = result .. "}"

return result
end

-- Metamethod __concat

--mt.__concat = mt.__add
--print(tbl1 .. tbl2)

setmetatable(tbl1, mt)

print(#tbl1)
print(getmetatable(tbl1) == mt)
print(getmetatable(tbl2) == mt)

--Metamethod __index

deDE_races = {
["Night Elf"] = "Nachtelf" --MARK:)  {"Nachtelf"}  --This should not be a SET!
}

mt2 = {}
setmetatable(deDE_races, mt2)

enUS_races = {
["Human"] = "Human",
["Night Elf"] = "Night Elf",
}

mt2.__index = enUS_races

print(deDE_races["Night Elf"]) --Outputs table ID, not sure why
print(deDE_races["Human"])
  • Listening to: Bright Eyes
  • Reading: 1984
  • Watching: TV sucks

deviantID

No deviantID yet.

Devious Info

  • Current Residence: Woodland appts. Midland MI
  • Interests: Deep contemplation. Finite State Automatia, Music, Differential equations,
  • Favourite band or musician: http://www.youtube.com/watch?v=HFytzNhPsoM&feature=related
  • Favourite genre of music: Classical
  • Favourite poet or writer: Orson Scott Card, George Orwell
  • Operating System: Unix
  • MP3 player of choice: Laptop
  • Shell of choice: Linux Secure Shell
  • Wallpaper of choice: yellow
  • Skin of choice: The kind you wear
  • Favourite game: there are so many.
  • Favourite gaming platform: PC
  • Favourite cartoon character: The turtle from looney toons
  • Personal Quote: "Only your enemy can show you where you are weak and he is strong"
  • Tools of the Trade: C++, .Net platform, Sqrt[-1]

AdCast - Ads from the Community

[x]

Comments


:iconstill-faith:
Heya! Thanks for the fave!

--
"Forgive and forget. I forgot."
Reply
:iconbladesofthevalkyrie:
Thank you! :D

--
"If at first you don't succeed, destroy all evidence."
Reply
:icon:
Add a Comment: