2

When overriding equality operators in Lua (via the "__eq" metamethod), is there a way to still check for primitive equality (ie. not calling the overridden __eq, but checking if the two table values are referentially the same?) I need to do this from the C API, but I cannot find a suitable function there.

For example:

lua_newtable(L);
lua_newtable(L);
assert(!some_comparison());
lua_pushvalue(L,-1);
assert(some_comparison());

Where some_comparison() does not invoke the __eq metamethod.

(Please note lua_compare() does not satisfy this, in particular. I want a lua_rawcompare(), if you will - or rather a trick or workaround that will give me the equivalent. The idea is to prevent infinite recursion in a __eq implementation...)

hjpotter92
  • 78,589
  • 36
  • 144
  • 183
BadZen
  • 4,083
  • 2
  • 25
  • 48

1 Answers1

4

If I understand your question correctly, I think you mean to use lua_rawequal:

int lua_rawequal (lua_State *L, int index1, int index2);

Returns 1 if the two values in indices index1 and index2 are primitively equal (that is, without calling metamethods). Otherwise returns 0. Also returns 0 if any of the indices are not valid.

hjpotter92
  • 78,589
  • 36
  • 144
  • 183