lua-users home
lua-l archive

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


Hi,

I'm new to Lua, so apologies for the basic nature of this question.  I want
to define a function in Lua, and register it in a C program, so that it can
be called back at a later date.

In Lua...
------------------------

function MyFunction()

	-- do something here

end

RegisterCallback(MyFunction)

------------------------


Then in C...

I can call the Lua function like this...

	lua_pushstring(L, "TestFn");
	lua_gettable(L, LUA_GLOBALSINDEX);
	lua_call(L, 0, 0);


... but I also want to do this....

int RegisterCallback(lua_state* L)
{
	// Get function from stack and store it somewhere

	// How do I do this??
}

void CallCallback(lua_state* L)
{
	// Call the previously stored lua function here

	// How do I do this??
}


Can anyone point me in the right direction?
Many thanks,

Will