I am using luabind 0.9.1 from the main Ryan Pavlik distribution with Lua 5.1, cygwin on Win XP SP3 + latest x86 fixes, boost 1.48, gcc 4.3.4. Lua and boost are precompiled versions of cygwin.
I have successfully created luabind in both static and general versions.
Both versions pass all EXCEPT tests for the test_object_identity.cpp test, which does not work in both versions.
I tracked the problem to the following problem: If a table entry is created for the NON built-in class (i.e. Not int, string, etc.), the value CANNOT be retrieved.
Here is a piece of code that demonstrates this:
#include "test.hpp" #include <luabind/luabind.hpp> #include <luabind/detail/debug.hpp> using namespace luabind; struct test_param { int obj; }; void test_main(lua_State* L) { using namespace luabind; module(L) [ class_<test_param>("test_param") .def_readwrite("obj", &test_param::obj) ]; test_param temp_object; object tabc = newtable(L); tabc[1] = 10; tabc[temp_object] = 30; TEST_CHECK( tabc[1] == 10 ); // passes TEST_CHECK( tabc[temp_object] == 30 ); // FAILS!!! }
tabc [1] is really 10, and tabc [temp_object] is NOT 30! (actually it's nothing)
However, if I use iteration to step through tabc entries, there are two entries with CORRECT key / value pairs.
Any ideas?
BTW, overloading the == operator as follows:
#include <luabind/operator.hpp> struct test_param { int obj; bool operator==(test_param const& rhs) const { return obj == rhs.obj; } };
and
module(L) [ class_<test_param>("test_param") .def_readwrite("obj", &test_param::obj) .def(const_self == const_self) ];
Does not change the result.
I also tried switching to settable () and gettable () from the [] operator. The result is the same. I see that the default call to the key is called with the debugger, so I assume that the error occurs somewhere there, but it's outside of me to find out what the problem is.
As shown in the following simple test case, a specific error in Luabind conversion for complex types:
struct test_param : wrap_base { int obj; bool operator==(test_param const& rhs) const { return obj == rhs.obj ; } }; void test_main(lua_State* L) { using namespace luabind; module(L) [ class_<test_param>("test_param") .def(constructor<>()) .def_readwrite("obj", &test_param::obj) .def(const_self == const_self) ]; object tabc, zzk, zzv; test_param tp, tp1; tp.obj = 123456;
Hope someone smarter than me can figure it out, thanks
I traced the problem that Luabind creates a NEW DISTINCT object EVERY time you use a complex value as a key (but this is NOT if you use a primitive object or an object).
Here is a small test case demonstrating this:
struct test_param : wrap_base { int obj; bool operator==(test_param const& rhs) const { return obj == rhs.obj ; } }; void test_main(lua_State* L) { using namespace luabind; module(L) [ class_<test_param>("test_param") .def(constructor<>()) .def_readwrite("obj", &test_param::obj) .def(const_self == const_self) ]; object tabc, zzk, zzv; test_param tp; tp.obj = 123456; tabc = newtable(L);
Note that tabc [tp] is first set to 5, and then overwritten with 7 when accessed via the key object. However, when accessing AGAIN via tp, a new entry is created. This is why gettable () subsequently fails.
thanks david