[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: How do you implement Lua event handlers in your game?
- From: Jose Marin <jose_marin2@...>
- Date: Mon, 9 Apr 2007 04:29:41 -0700 (PDT)
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).
... check error
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:
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