lua-users home
lua-l archive

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


I'm trying to determine whether a lua value is a C function, but it's not working. I have boiled down the problem to this:
 
    int cfunc(lua_State* L)
    { return 0; }
 
    lua_pushcfunction(L, cfunc);
    lua_pushcfunction(L, cfunc);
    int ret = lua_rawequal(L, -1, -2);
    // ret == 0
 
It seems as though lua was not intended to compare C functions, since stepping into lua_rawequal reveals that LUA_TFUNCTION is given the default treatment:
 
    default:
      lua_assert(iscollectable(t1));
      return gcvalue(t1) == gcvalue(t2);
 
I looked inside t1 and t2 and found where the C function's addresses are stored, and added the following lines:
 
    case LUA_TFUNCTION:
      return t1->value.gc->cl.c.f == t2->value.gc->cl.c.f;
 
Modifying lua code is obviously not something I want to be doing, so I would like to know if there's a better way.
 
Thank you


Invite your mail contacts to join your friends list with Windows Live Spaces. It's easy! Try it!