lua-users home
lua-l archive

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

Ignacio Burgueño wrote:

Will this work for you?

mt = {
  __index = function(tab, k)
    local function f()
      print("You called " .. k .." on "..tostring(tab))
      tab.test = 20 * math.random()
    return f

o = setmetatable({ test=1 }, mt)
o2 = setmetatable({ test=1 }, mt)

Thanks to you and David for this suggestion. To answer David's question, yes, it was intentional, however since it doesn't work the way I need it to I suppose I'll just have to change my intention. :-)

I'll try this approach. If I can't get it to work I'll come back for more advice. Thanks to you both!