Skip to content

Commit

Permalink
Remove the failing object identity test.
Browse files Browse the repository at this point in the history
The test attemts to index Lua tables with Luabind objects and tests if
logically equal objects are treated as denoting the same table element when
used as key. But that is not and *cannot* be the case, as the Lua Reference
Manual points out (http://www.lua.org/manual/5.2/manual.html#2.1):

> The indexing of tables follows the definition of raw equality in the
> language. The expressions a[i] and a[j] denote the same table element if and
> only if i and j are raw equal (that is, equal without metamethods).

Note especially the last, parenthesized statement.

It follows that the test does not show a bug in Luabind but rather the
"limitations" of the Lua language.
  • Loading branch information
Oberon00 committed Jun 29, 2013
1 parent 0067571 commit 1c89c79
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 92 deletions.
1 change: 0 additions & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ set(TESTS
"lua_classes"
"null_pointer"
"object"
"object_identity"
"operators"
"package_preload"
"policies"
Expand Down
91 changes: 0 additions & 91 deletions test/test_object_identity.cpp

This file was deleted.

4 comments on commit 1c89c79

@rpavlik
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The way of fixing this is to use a lightuserdata as a key into a weak table that stores the original created objects, to preserve their identity. Hopefully that makes sense.

@Oberon00
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it does make sense, but I don't think it's worth the performance overhead and added complexity. This was also discussed a bit in #4 (comment). Now that #6 is implemented, I think this is even less urgent.

@rpavlik
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My primary use case for this was for table keys (as the test probably indicates), so the metamethod doesn't help. Does #4 mean that now this works if objects are held by shared pointers?

@Oberon00
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only under certain circumstances and only as side effect. Maybe you can create objects derived from wrap_base: documentation says, that object identity is preserved then (although I can't find any tests for it).
EDIT: I just saw that you have added this in 6dc62e4. Does it work then?
EDIT2: You are creating copies of the object! Assign/pass by pointer, then it should work (see https://github.com/Oberon00/luabind/blob/master/luabind/detail/policy.hpp#L225)

Please sign in to comment.