[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Registering function
- From: "Jens Wessling" <wessling@...>
- Date: Tue, 9 Oct 2001 21:13:31 -0400
> I'd like to register a function to be called from Lua, however there are
> two issues I'm running into:
> 1. I'd like to avoid passing a lua_state
> Granted, this isn't going to be directly possible, but basically I'd
> like to hide Lua from the rest of my application and instead have it go
> through a proxy. So instead of:
> int callback( struct lua_State *pLua );
> I'd like to be able have something more like:
> int callback( MyProxy *pProxy )
> Where "callback" would query pProxy for the arguments supplied. This
> way I don't have external code dependent on Lua directly.
> Is there a clean way of doing this or should I just handle the double
> indirection myself (i.e. the proxy is called back, and then it calls the
> real function with appropriately parsed args)?
> 2. How to pass a "this" pointer?
> Is there a standard way of passing a "this" pointer when calling C++
> objects from Lua? Right now I'm using a global, which seems rather
I have found a way to deal with both of these issues. I am not sure that it
is exactly what you are looking for, but...
I register all of my C++ functions so they call the same callback handler.
Then I look up the name of the function that was called in a database of all
C++ functions and use the function database to validate all of the
arguments, then call the appropriate function.
I pass the 'this' pointer as the first argument to the function.
I can elaborate on this if you have any questions.