lua-users home
lua-l archive

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


Thanks for your suggestions.

I am aware of the technique of using a proxy table, a shadow table to hold values and subscribers, and a metatable to intercept gets/sets to perform notifications. That's what I'm doing now.

What I'm wondering is if there is a way to use the information already present in the runtime to infer the subscribers, instead of explicitly storing them. It seems there is not, but if there were, it could simplify this technique.


On Sat, Sep 14, 2013 at 12:03 AM, Andrew Starks <andrew.starks@trms.com> wrote:
I'm sorry. One more thing and then I'll leave you alone:

If you are dealing with functions and you want something to happen
after they are called, such that:

model.method = function(...) return ... end


then your __newindex function can contain this construct:


if type(v) == "function" then
    v = function(...)
      local retval = {v(...)} --unless you know the number of return
values, you need to pack them in a table.

      ---do crazy stuff notify the callbacks in your subs table


       return table.unpack(...)
    end
end


----

Okay. Sorry for the noise. Hope this helps and again, if I'm missing
something, please let me know!

-Andrew