-
Posted by aradel on Sun, 02 Aug 2009 01:20:22
I input the following into my wow lua addon and got the following message(line 1) attempt to index global 'mt' (a nil value) I tried to add local before function mt.__add (a,b) on line 1 and i got this message '(' expected near '.' and now i'm out of ideas. Also if someone could give me an example of how meta tables are being used and what can be done with them I'm having a hard time putting 1 and 2 together with this so much to take in 0.o
function mt.__add (a,b) local result result = setmetatable({},mt) a = {"Alpha", "Beta", "Gamma"} for i=1, #a do table.insert(result,a[i]) end b = {"Delta", "Epsilon", "Zeta"} for i=1, #b do table.insert(result,a[i]) end return result end
addtest = a + b print(#addtest)
EDIT: sry for the messed up code/post
-
Posted by Zeksie on Sun, 02 Aug 2009 09:05:01
I input the following into my wow lua addon and got the following message(line 1) attempt to index global 'mt' (a nil value) I tried to add local before function mt.__add (a,b) on line 1 and i got this message '(' expected near '.' and now i'm out of ideas. Also if someone could give me an example of how meta tables are being used and what can be done with them I'm having a hard time putting 1 and 2 together with this so much to take in 0.o
function mt.__add (a,b) local result result = setmetatable({},mt) a = {"Alpha", "Beta", "Gamma"} for i=1, #a do table.insert(result,a[i]) end b = {"Delta", "Epsilon", "Zeta"} for i=1, #b do table.insert(result,a[i]) end return result end
addtest = a + b print(#addtest)
EDIT: sry for the messed up code/post
'mt' must be a valid table before you try to add a function declaration to it. Before the function mt.__add line:
local mt = {}
-
Posted by aradel on Fri, 07 Aug 2009 23:19:24
oh that makes sense =D ty, gonna try it now updating later to see if this fixed it