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

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

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

qwer1304
Hi,

I'm using luabind 0.9.1 from Ryan Pavlik's master distribution with Lua 5.1, cygwin on Win XP SP3 + latest patches x86, boost 1.48, gcc 4.3.4. Lua and boost are cygwin pre-compiled versions.

I've successfully built luabind in both static and shared versions.

Both versions pass all the tests EXCEPT for the test_object_identity.cpp test which fails in both versions.

I've tracked down the problem to the following issue:
If an entry in a table is created for NON built-in class (i.e., not int, string, etc), the value CANNOT be retrieved.

Here's a code piece 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 indeed 10 while tabc[temp_object] is NOT 30! (actually, it seems to be nil)

However, if I use iterate to go over tabc entries, there're the two entries with the CORRECT key/value pairs.

Any ideas?

Thx,
David


------------------------------------------------------------------------------
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

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

Willi Schinmeyer
  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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

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

qwer1304
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: [hidden email]
> To: [hidden email]
> 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
> [hidden email]
> 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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

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

liam mail
2012/4/25 qwer 1304 <[hidden email]>:

> 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: [hidden email]
>> To: [hidden email]
>> 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
>> [hidden email]
>> 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
> [hidden email]
> 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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

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

qwer1304
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 fail
second, 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: [hidden email]

> Date: Wed, 25 Apr 2012 16:32:28 +0100
> To: [hidden email]
> Subject: Re: [luabind] luabind: problem retrieving values from table indexed by non-built-in classes
>
> 2012/4/25 qwer 1304 <[hidden email]>:
> > 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: [hidden email]
> >> To: [hidden email]
> >> 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
> >> [hidden email]
> >> 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
> > [hidden email]
> > 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
> [hidden email]
> 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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

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

qwer1304
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: liam.list@googlemail.com
> Date: Wed, 25 Apr 2012 16:32:28 +0100
> To: luabind-user@lists.sourceforge.net
> Subject: Re: [luabind] luabind: problem retrieving values from table indexed by non-built-in classes
>
> 2012/4/25 qwer 1304 <qwer1304@hotmail.com>:
> > 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: willi@schinmeyer.de
> >> To: luabind-user@lists.sourceforge.net
> >> 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
> >> luabind-user@lists.sourceforge.net
> >> 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
> > luabind-user@lists.sourceforge.net
> > 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
> luabind-user@lists.sourceforge.net
> 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
luabind-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

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

qwer1304
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: liam.list@googlemail.com
> Date: Wed, 25 Apr 2012 16:32:28 +0100
> To: luabind-user@lists.sourceforge.net
> Subject: Re: [luabind] luabind: problem retrieving values from table indexed by non-built-in classes
>
> 2012/4/25 qwer 1304 <qwer1304@hotmail.com>:
> > 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: willi@schinmeyer.de
> >> To: luabind-user@lists.sourceforge.net
> >> 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
> >> luabind-user@lists.sourceforge.net
> >> 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
> > luabind-user@lists.sourceforge.net
> > 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
> luabind-user@lists.sourceforge.net
> 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
luabind-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

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

qwer1304

As the following simple test case show, there're 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;
        tabc = newtable(L);           // get new table
        //            o      k   v
        settable( tabc,  tp, 5);       // tabc[tp] = 5;
        iterator zzi(tabc);              // get access to entry through iterator()
API
        zzk = zzi.key();                 // get the key object
        //                    o      k
        zzv = gettable(tabc, zzk);   // read back the value through gettable() API
        // check the entry has the same value irrespective of access method
        TEST_CHECK ( *zzi == 5 && object_cast<int>(zzv) == 5 );
        tp1 = object_cast<test_param>(zzk); // convert key to its REAL type
(test_param)
        TEST_CHECK( tp == tp1 );                // check two keys are the same
        zzv = gettable(tabc, tp1);                // read the value back from table
using REAL key type
        // 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


qwer1304 wrote:

>
> 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: [hidden email]
>>>> Date: Wed, 25 Apr 2012 16:32:28 +0100
>>>> To: [hidden email]
>>>> Subject: Re: [luabind] luabind: problem retrieving values from table
>>>> indexed by non-built-in classes
>>>>
>>>> 2012/4/25 qwer 1304 <[hidden email]>:
>>>> > 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: [hidden email]
>>>> >> To: [hidden email]
>>>> >> 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
>>>> >> [hidden email]
>>>> >> 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
>>>> > [hidden email]
>>>> > 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
>>>> [hidden email]
>>>> 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
>>> [hidden email]
>>> 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-tp33746417p33763248.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/
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

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

qwer1304
In reply to this post by qwer1304
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

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

qwer1304
I've traced the problem to the fact that Luabind creates a NEW DISTINCT object EVERY time you use a complex value as key (but it does NOT if you use a primitive one or an object).

Here's a small test case that demonstrates 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);
//         o     k   v
settable( tabc,  tp, 5);
iterator zzi(tabc), end;
std::cerr << "value = " << *zzi << "\n";
zzk = zzi.key();
//         o     k    v
settable( tabc,  tp,  6);
settable( tabc,  zzk, 7);
for (zzi = iterator(tabc); zzi != end; ++zzi)
{
std::cerr << "value = " << *zzi << "\n";
}
}

Notice how tabc[tp] first has the value 5 and then is overwritten with 7 when accessed through the key object. However, when accessed AGAIN through tp, a new entry gets created. This is why gettable() fails subsequently.

Any ideas?


From: [hidden email]
To: [hidden email]
Date: Sun, 29 Apr 2012 07:17:22 +0300
Subject: Re: [luabind] luabind: problem retrieving values from table indexed by non-built-in classes

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 [hidden email] 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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user