[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: How do you deal with event functions?
- From: Jose Marin <jose_marin2@...>
- Date: Tue, 5 Dec 2006 11:27:32 +0000 (GMT)
Hi.
With Lua 5.1, is there some "proper" way of store
references to user Lua functions, to be called later?
I know that this was already discussed, but it was
before the 5.1 version. I wonder if this version has a
better solution to this problem.
For example, the user could create a function to deal
with keys pressed, like this:
function OnKeyPressed(key)
...
end
So, what's the best way to register this function to
C, to be later called?
I see 2 ways of do this:
1) provide a "SetOnKeyPressed" to Lua, and in the code
it would be called like this:
SetOnKeyPressed(OnKeyPressed)
Then, in the C main window callback, in the message
WM_KEYDOWN, the function would be called, passing the
key pressed code.
2)provide the same SetOnKeyPressed function, but the
user would pass a string, like this:
SetOnKeyPressed("OnKeyPressed")
Then, in the C main window callback, in the message
WM_KEYDOWN, the function would be called, using the
lua_getglobal function, passing the function name
provided by the user. And then calling the function
lua_pcall.
In Lua 5.1, what's the pro's and con's of these 2
methods?
Is there a better way of do this?
Thanks for any tip!
Jose
_______________________________________________________
Novidade no Yahoo! Mail: receba alertas de novas mensagens no seu celular. Registre seu aparelho agora!
http://br.mobile.yahoo.com/mailalertas/