[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: A Question of Style
- From: Henk Boom <henk@...>
- Date: Tue, 29 Nov 2011 00:48:27 -0500
On 26 November 2011 08:03, Marc Balmer <email@example.com> wrote:
> 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.
The GLFW bindings use 2). It's somewhat awkward when you're using
strict.lua, though, as you need to do a rawset(_G, "callbackname",
Personally I would always prefer 1), and can't think of any advantages
for 2), other than being _slightly_ easier to implement in c.