Re: luabind: problem retrieving values from table indexed by non-built-in classes

qwer1304 <[email protected]> Thu, 26 Apr 2012 07:45:43 -0700 (PDT)
Newsgroups gmane.comp.lang.lua.bind.user
Message-ID <[email protected]>
I switched to settable() and gettable() from the [] operator: results are the
same.

I can see in debugger that conversion routines are called to convert the
key. I guess the error is somewhere therein: there's some inconsistency
between the set... and the get... paths.

Unfortunately, it's way beyond me to figure out exactly what's wrong.


qwer1304 wrote:
> 
> Did a bit more digging and experimentation:
> 
> 1.You can access Lua tables (global or local) from C++/Luabind with keys
> that are primitive (int, string) and object (provided object wraps a valid
> entity).
> 
> 2.Trying to access tables w/ non-primitive (compound) keys from
> C++/Luabind doesn't retrieve the right value.
> 
> 3.The following happens:
> a.bind a compound class to Lua (say MyClass)
> b.create an instance of that class in Lua (say x = MyClass() )
> c.In Lua, put a value into a table at key=x (i.e., tab[x] = 1)
> d.In C++ get tab and x objects: tab = globals(L)["tab"]; x =
> globals(L)["x"];
> e.check what's in tab[x]? (it's 1, as it should be
> object_cast<int>(tab[x]) == 1)
> f.convert x to MyClass: MyClass xx = object_cast<MyClass>(x)
> g.check what's in tab[xx]? (it's nil!!!!)
> 
> 
> qwer1304 wrote:
>> 
>> 
>> I tried overloading the == operator like this:
>> 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)
>>     ];
>> It didn't change anything.
>> As for using a local object for a key: first, it's a valid test, which
>> still shouldn't failsecond, I moved it out from the stack to heap, but it
>> didn't change the result.
>> The weird thing is that the data is there in the table and can be
>> retrieved using iterate().
>> David
>>> From: [email protected]
>>> Date: Wed, 25 Apr 2012 16:32:28 +0100
>>> To: [email protected]
>>> Subject: Re: [luabind] luabind: problem retrieving values from table
>>> indexed by non-built-in classes
>>> 
>>> 2012/4/25 qwer 1304 <[email protected]>:
>>> > Ryan Pavlik says that his version passes now all tests.
>>> >
>>> > In any case, IMHO it's important to figure out why such a simple test
>>> as I
>>> > put in my original message fails.
>>> > I.e., I'd expect a true application to be able to enter a value into a
>>> table
>>> > for a given key in an object and to be able to retrieve it.
>>> >
>>> > As the test case shows - it cannot.
>>> >
>>> > Thx,
>>> > David
>>> >
>>> >> Date: Wed, 25 Apr 2012 16:49:45 +0200
>>> >> From: [email protected]
>>> >> To: [email protected]
>>> >> Subject: Re: [luabind] luabind: problem retrieving values from table
>>> >> indexed by non-built-in classes
>>> >
>>> >>
>>> >> The object identity test failing is a known issue as far as I know,
>>> >> the commit message from when it was added states so.
>>> >>
>>> >>
>>> >>
>>> ------------------------------------------------------------------------------
>>> >> 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
>>> >
>>> >
>>> ------------------------------------------------------------------------------
>>> > 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
>>> >
>>> 
>>> Personally I would take a wild stab in the dark and say your object
>>> does not have a comparison operator and what does it mean to put a
>>> stack object in a container?
>>> 
>>> Liam
>>> 
>>> ------------------------------------------------------------------------------
>>> 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
>>  		 	   		  
>> ------------------------------------------------------------------------------
>> 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
>> 
>> 
> 

-- 
View this message in context: http://old.nabble.com/luabind%3A-problem-retrieving-values-from-table-indexed-by-non-built-in-classes-tp33746417p33753304.html
Sent from the Lua C++ Bind mailing list archive at Nabble.com.


------------------------------------------------------------------------------
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/