lua-users home
lua-l archive

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

On 07/26/2013 03:45 AM, William Ahern wrote:
On Thu, Jul 25, 2013 at 08:34:35PM -0700, William Ahern wrote:
If I do

	lua_pushcfunction(L, &foo);
	lua_pushcfunction(L, &foo);

	rc = lua_equal(L, -1, -2);

is the value of `rc' guaranteed to be 1 in Lua 5.1, Lua 5.2, and LuaJIT?
That is, is it part of the language that C functions without upvalues are
compared according to their C function pointer values?

D'uh. The answer is no. I abstained from checking with actual code because I
assumed it would work, but my assumption was wrong, at least for Lua 5.1.

I also thought it must always be 0. Because you push the c function twice, means you have two references in the Lua world, and then you compare the references and not the values. I don't see why Lua should check if this C function was already pushed before at the second call of lua_pushcfunction. It would be quite an overhead.

As the manual says: lua_pushcfunction(L, f) is just a makro for lua_pushcclosure(L, f, 0)