[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: How do you implement Lua event handlers in your game?
- From: "Jeremy Darling" <jeremy.darling@...>
- Date: Tue, 10 Apr 2007 15:18:05 -0500
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: http://eonclash.com/ViewProduct.php?ProductID=23
It comes down to the Lua Registry and testing for global and local (table/metatable) method existence and calls.
On 4/9/07, Jose Marin <
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
"Help I suffer from the oxymoron Corporate Security."