Re: luabind: problem retrieving values from table indexed by non-built-in classes
qwer 1304 <[email protected]> Sun, 29 Apr 2012 07:17:22 +0300
| Newsgroups | gmane.comp.lang.lua.bind.user |
|---|---|
| Message-ID | <[email protected]> |
As the following simple test case shows, there's definitely a bug in Luabind's 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; // create new table tabc = newtable(L); // set tabc[tp] = 5; // o k v settable( tabc, tp, 5); // get access to entry through iterator() API iterator zzi(tabc); // get the key object zzk = zzi.key(); // read back the value through gettable() API //
o k zzv = gettable(tabc, zzk); // check the entry has the same value // irrespective of access method TEST_CHECK ( *zzi == 5 && object_cast<int>(zzv) == 5 ); // convert key to its REAL type (test_param) tp1 = object_cast<test_param>(zzk); // check two keys are the same TEST_CHECK( tp == tp1 ); // read the value back from table using REAL key type zzv = gettable(tabc, tp1); // check the value TEST_CHECK( object_cast<int>(zzv) == 5 ); // the previous call FAILS with // Terminated with exception: "unable to make cast" // this is because gettable() doesn't return // a TRUE value, but nil instead } Hopefully, someone smarter than me can figure this out, Thx
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
luabind-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/luabind-user