lua-users home
lua-l archive

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

Well, without spamming a bunch of code around (and sense I just noticed this thread) the basic way we are handling it can be seen in the demo on our site:

It comes down to the Lua Registry and testing for global and local (table/metatable) method existence and calls.

 - Jeremy

On 4/9/07, Jose Marin <> wrote:

I see two main ways of implementing Lua event handlers in a game:

1) Use the lua_getglobal and them lua_call (or lua_pcall).


In Lua:

function OnTimer(timerID)

In C:

    case WM_TIMER:
        lua_getglobal(L, "OnTimer");
        ... check error

        lua_pushnumber(L, wParam);`

        lua_call(L, 1, 0);


The problem here it's the performance of the lua_getglobal function, if I use it to implement event handlers to actors (will have many of them), too.

2) Store the reference to the function that will handle each event, and call it later, when needed.

Again, I could use the lua_getglobal to find the reference to the callback functions (there will be many of them, because actors will hare their callbacks too) at the start of the game, and store it in C variables.

The problem is how to store these references, and how to call them later.

I could use a registered C function to do that, for example:

In Lua:

function OnTimer(timerID)

RegisterEventHandler(EV_TIMER, OnTimer)

In C:
    How to get the reference on the OnTimer function? And how call it later?

I think there is already a thread about this subject, but I couldn't find it.

Thanks for any tip!


Fale com seus amigos  de graça com o novo Yahoo! Messenger


"Help I suffer from the oxymoron Corporate Security."