lua-users home
lua-l archive

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


IIRC, a couple of people (myself included) reviewed the implementation of
luaL_ref when you posted this earlier, and no one saw anything suggestive.
Have you debugged into lua_Lref to see what is going on in your
installation/implementation?


I guess related to that line of thought is the question of how you are
accessing Lua (what distribution/build/statically linked library/direct
source in your program compilation).

luaL_ref really should not be producing the behavior you are seeing, so
something has to be wrong with the environment in which you are seeing this.

Good Luck!

-----Original Message-----
From: lua-bounces@bazar2.conectiva.com.br
[mailto:lua-bounces@bazar2.conectiva.com.br]On Behalf Of Chris Chapman
Sent: Thursday, November 06, 2003 9:57 AM
To: lua@bazar2.conectiva.com.br
Subject: lua_ref problem


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