[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: A Question of Style
- From: HyperHacker <hyperhacker@...>
- Date: Tue, 29 Nov 2011 19:32:46 -0700
On Tue, Nov 29, 2011 at 10:18, jiang yu <email@example.com> wrote:
> I prefer 2)
> 1. It is simpler than 1)
> 2. If there is bug in 2), you can correct it and just dofile() —— no
> need restart the program.
> 2011/11/26 Marc Balmer <firstname.lastname@example.org>:
>> I have a stylistic question wrt/ calling Lua "callbacks" from a C
>> program. I see two obvious approaches:
>> 1) Lua code registers callbacks explicitely using a RegisterCallback
>> function that is provided by the C program; the C program later calls
>> the callback function when one is registered.
>> 2) Lua code does not register callbacks, but the callbacks must be
>> functions with a certain name, e.g. "MouseMovedCallback"; C code will
>> then see if a function with the correct name is available in the Lua
>> state, and if so, call it.
>> Are there advantages of one approach over the other? Are there other
>> approaches? If you also use callback written in Lua, which you call
>> from C, I'd like you to share your opinion (and/or experience).
>> I experienced with both forms, I am unsure for which form to go...
You can do that with method 1 too, by just having the script
unregister and reregister its handlers at startup.
Sent from my toaster.