function entry()
print( "Hello Lua\npiss 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"])
--
"Forgive and forget. I forgot."
--
"If at first you don't succeed, destroy all evidence."
Previous PageNext Page