[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Res: How do you implement Lua event handlers in your game?
- From: Jose Marin <jose_marin2@...>
- Date: Tue, 10 Apr 2007 11:22:25 -0700 (PDT)
This is good!
But justo to increase my knowledge on Lua, it's possible to save the result of lua_getglobal(L, "OnTimer"); ?
This way, on the beggining of the game I could do this
FUNC_ONTIMER it's an index on an array, where the reference to Lua funcsions would be saved.
Then, the evente handler would be like this:
PushFunctionToStack(L, FUNC_ONTIMER); // Just takes the contents of the array at position FUNC_ONTIMER and pushes it on the Lua stack
lua_call(L, 1, 0);
----- Mensagem original ----
De: Ashwin Hirschi <firstname.lastname@example.org>
Para: Lua list <email@example.com>
Enviadas: Terça-feira, 10 de Abril de 2007 14:52:16
Assunto: Re: How do you implement Lua event handlers in your game?
> 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.
Jose, there really is no problem with performance here.
We've done this wiring of Lua handlers to Windows messages for years (and on very old hardware, too). Never had any problems whatsoever.
So, your particular scenario will work just fine. Don't hold back for fear of lack of speed, and just go for it!
P.S. Of course, if you can come up with something that'll work faster... hey, that's okay too [;-)].
no signature is a signature.
Fale com seus amigos de graça com o novo Yahoo! Messenger