[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: lua_ref problem
- From: Chris Chapman <Chris.chapman@...>
- Date: Thu, 6 Nov 2003 15:56:38 -0000
Okay, I'm having to revisit this problem, because my original workaround is
insufficient for the other issues that have arisen because of it. I hope
someone here can see what I'm doing wrong.
Given the script:
do
function foo()
print("foo\n");
end
function bar()
print("bar\n");
end
print (GetFunctionReference(foo) .. "\n");
print (GetFunctionReference(foo) .. "\n");
print (GetFunctionReference(bar) .. "\n");
print (GetFunctionReference(foo) .. "\n");
end
and "GetFunctionReference" being a C function registered with lua which
looks like:
int GetFunctionReference(lua_State* L)
{
//get a reference to the first argument on the stack
//check the argument is a lua function
if (lua_type(L, -1) == LUA_TFUNCTION)
{
int iReference = lua_ref(L, 1);
//1 indicates a locked reference
//return the reference index as a number
lua_pushnumber(L, iReference);
return 1;
}
else
{
return 0;
}
}
Running this script produces the output:
3
3
3
3
I.e. no matter what I try to pass to lua_ref, I always get 3 back as a
reference. Breakpointing the C code indicates that it is indeed 3 being
returned from lua_ref each time. Tracing the lua code follows the same path
each call.
Again, this is a difference between 4.0.1 and 5.0.
Thanks
ChrisC