lua-users home
lua-l archive

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


Cool thanks, but it will be possible also with lua 5.0?I'm planning to switch to it
before we release the game

ciao
Alberto

-------------------------------
Alberto Demichelis
alberto@crytek.de
www.crytek.com

-----Original Message-----
From: Edgar Toernig [mailto:froese@gmx.de]
Sent: Wednesday, August 07, 2002 3:13 PM
To: Multiple recipients of list
Subject: Re: CALLS DISPATCHER


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.