lua-users home
lua-l archive

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



On 12 Dec 2008, at 07:09, Robert Stehwien wrote:

I've got a C program that Lua could return a function to and I'd like to save that function to call later when an event occurs. What do I need to
save so I can call the function?  How do I call the function?


Something like

	lua_getfield(aLua, -1, "function");
	if (!lua_isnil(aLua, -1))
	{
		lua_pushvalue(aLua, -1);		// Push it because luaL_ref pops
		int		fnRef = luaL_ref(aLua, LUA_REGISTRYINDEX);

and

	lua_rawgeti(lua, LUA_REGISTRYINDEX, m_Ref);
	int			error = lua_pcall(lua, 0, 0, - 2);

David Dunham   Macintosh Game Developer
GameHouse Studios     +1 206 926 5722     www.gamehouse.com
    "They said it couldn't be done but sometimes it doesn't
     work out that way." -- Casey Stengel