lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


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