lua-users home
lua-l archive

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


Alberto Demichelis wrote:
> 
> What I think is not really elegant (and also a bit dangerous) is
> storing the index into the table without being sure that
> a call is going to be done on it.

Not ony dangerous, it will not work in all cases - i.e.:

  mdp:OnUpdate(mdp:foo())

> Somebody can see any better solution?

Your index method should return a function that when called
will call all the functions in the mdp.  Something like:

function mdp_index(mdp, name)
    local f = function(...)
        for i=1,getn(%mdp) do
          call(%mdp[i][%name], arg)
        end
    end
    mdp[name] = f  -- cache result
    return f
end

Ciao, ET.