[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: metatables
- From: "Walter Cruz" <walter.php@...>
- Date: Tue, 18 Jul 2006 16:06:16 -0300
Hi all. I wanna make a simple thing with a metatable: when I insert something, It goes to the member value of object.
But my method save doesn't word :(
Look:
__
mt = {} -- metatable
materia ={}
function materia:new()
local new = {
values={}
}
setmetatable(new, mt)
return new
end
mt.__index = function(t,key,value)
return t.values[key]
end
mt.__newindex = function (t, key, value)
t.values[key] = value
end
function mt:save()
table.foreach(self.values,print)
end
m = materia:new()
m.materia_titulo = 'materia_titulo'
m.materia_keywords='materia_keywords'
m.materia_publicacao='materia_publicacao
'
m.texto='materia_texto'
m:save()
print(m.texto)
__
I got the error on m:save()
"attempt to call method 'save' (a nil value)"
Can someone help me ?
[]'s
- Walter