lua-users home
lua-l archive

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


For the Lua-impaired, can you explain how this works?  From looking at
it, I don't see where "this" is being passed?

Brian

> typedef int (*LuaStateCFunction)(LuaState state);
> 
> class LuaState
> {
> public:
> 	// 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);
> 	}
> 
> protected:
> 	lua_State* m_state;
> };
> 
> 
> static int Callback(LuaState state)
> {
> 	printf("Hi\n");
> 	return 0;
> }
> 
> 
> LuaState state;
> state.Register("Callback", Callback);
> 
> -Josh
>