[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Adding local variables to lua functions, called from C.
- From: Dan Laufer <dlaufer@...>
- Date: Fri, 12 Mar 2004 12:34:54 -0000
Hello there, all.
I was wondering if anyone can help me with the following :
I'm calling a Lua function from C, and wish to set up some local variables
for that function, pre-calling it. In my current implementation, I'm
setting the variables in the global table, but for garbage collection
reasons, I'd rather not be leaving references floating around in the global
namespace, i.e. I'd like those references cleared up when the locals go out
And all without stopping that function from having access to the variables
stored in the global scope, of course...
My question is how do I go about this?
Currently, I'm doing something along the lines of :
// This global set is the bit that I want to remove in favour of adding a
// to the lua function in question.
s32 top = lua_gettop(s); // Store the stack top.
lua_settop(s,top); // Restore the stack
// Now call the function.
// push the function reference on the stack:
lua_getref (s, funcRef);
// get the function from the global table:
lua_rawget (s, LUA_GLOBALSINDEX);
// test if the function exists:
if(lua_isfunction (s, -1))
// call the function:
lua_call (s, nArgs, nResults);
bRetVal = true;
Thanks in advance,
Plotting the Downfall of Humanity, since 1974...