lua-users home
lua-l archive

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

> 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.

>From my C++ wrapper, LuaState, whose link is currently broken right now
or you could download it.  :)  Note that your class can NOT have virtual
functions and the lua_State* member variable must be first.

typedef int (*LuaStateCFunction)(LuaState state);

class LuaState
	// Functions...
	void Register(const char* funcName, LuaStateCFunction function)
		lua_pushstring(m_state, funcName);
		lua_pushcclosure(m_state, (lua_CFunction)function, 0);
		lua_settable(m_state, m_stackIndex);

	lua_State* m_state;

static int Callback(LuaState state)
	return 0;

LuaState state;
state.Register("Callback", Callback);