Add default __eq implementation

* Renamed SWIG_Lua_equal to SWIG_Lua_class_equal
* If class has no __eq implemented, then default __eq is provided.
  Default __eq compares actual pointers stored inside Lua userdata
This commit is contained in:
Artem Serebriyskiy 2014-05-16 13:00:14 +04:00
commit 2b4c49d017
3 changed files with 41 additions and 18 deletions

View file

@ -86,3 +86,14 @@ f4_name = tostring(f4)
assert( f2_name == "Foo" )
assert( f3_name == "Foo" )
assert( f4_name == "FooSubSub" )
-- Test __eq implementation supplied by default
-- eq_f1 and eq_f2 must be different userdata with same Foo* pointer. If eq_f1 and eq_f2 are the same userdata (e.g.)
-- > eq_f1 = smth
-- > eq_f2 = eq_f1
-- then default Lua equality comparison kicks in and considers them equal. Access to global_fptr is actually a
-- function call (internally) and it returns new userdata each time.
eq_f1 = cb.Bar.global_fptr
eq_f2 = cb.Bar.global_fptr
assert( eq_f1 == eq_f2 )