lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

On 9/30/07, Gerald Franz <> wrote:
> Dear Lua users,
> I was just wondering whether it is possible for a C extension function to to
> determine the name it was called by Lua.
> My idea would be to register a single C extension function multiple times to
> a Lua state, but behave (slightly) differently depending on the name it is
> called.
> For example, this would allow to unify all glue code between a C++ class and
> a Lua state within a single static method and facilitate a sharing of common
> code parts (e.g., converting the first argument to the pointer to the object
> instance).

One idea is to set up a pointer to a C++ object (some kind of Command
object) as an upvalue when defining the closure; the single C callback
function can then retrieve it, and call through it to tell the C++
Command object to execute.

-- James