[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Callback functions
- From: "Andreas Falkenhahn" <andreas@...>
- Date: Sun, 02 Jan 2005 12:01:45 +0100
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.
Any help appreciated.
"Remember: It's nice to be important but it's more important to be nice!"