[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: How do I pass a pointer to a lua function into C++?
- From: Steven Johnson <steve@...>
- Date: Thu, 6 Aug 2009 13:45:00 -0500
> //C++ code
> Timer::Timer(int x, int y, ??? luaFunction1, ??? luaFunction2)// I
> don't know what object they'd be
> {
> //is any of this right?
> lua_pushvalue( L, -1 ); // this is meant to push the function onto the stack
> m_timerFunction2 = luaL_ref( L, LUA_REGISTRYINDEX ); //which I then
> move to the registry
> lua_pushvalue( L, -1 );
> m_timerFunction1 = luaL_ref( L, LUA_REGISTRYINDEX );
> }
If you don't need to do anything more with the functions once they're bound (and
assuming they're at the top of the stack), you can just remove the
lua_pushvalue()
calls. Otherwise, your indices should be -1 and -2, respectively (as
is, you end up
making both refs to function #2).
The last two parameters are only needed if the functions aren't on top of the
stack. In that case, they would just be the stack indices passed to
the lua_pushvalue()
calls before the refs.