[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Callback functions
- From: Shmuel Zeigerman <shmuz@...>
- Date: Sun, 02 Jan 2005 18:50:14 +0200
See functions luaL_ref and luaL_unref.
Andreas Falkenhahn wrote:
I've a question concering callback functions that do not get deleted
after they were passed to a function. Imagine the following code:
createbutton("About", function() print("About button clicked!") end)
The createbutton() function is a function that I've implemented in C.
Now the question is: How do I preserve the function that the user
passed to my createbutton() function? IIRC, lua would normally
delete the function I passed as parameter 2 because it is not needed
any more after createbutton() returns. But this is not the case in
this specific example because createbutton() just creates a button
and does not need to call the function specified but it needs to
store it somewhere.
I somehow need to store the function that the user passed
(in this case: function() print("About button clicked!") end), tell
lua that it should not delete it and I must be able to call it later
when that button is clicked. How can all this be done?
Is there any documentation about how to implement callback
functions which must stay valid _after_ the function that they were
passed to exited? Or example code?
I saw in the lua book in chapter 6.1 that there is an example
just like mine above but it does not tell me how to implement those
callbacks on the C side.