Slicing / Object identity problem

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Slicing / Object identity problem

Hi everyone,
I'm trying to use some classe instances from Lua to C++ then back to Lua, and I'm having trouble to preserve my Lua content.
Here is my test:

********* C++ *********
    struct A
        bool operator == (const A& ref) const {return this == &ref;}
    struct A_wrap : A, luabind::wrap_base

    A* Identity(A* ptr) { return ptr; }
        def("Identity", &Identity),
        class_<A, A_wrap>("A")
        .def(const_self == const_self)

********* Lua *********
class 'B' (A)
function B:__init()
function B:Test()

x = B() = 0
y = Identity(x)
assert(x == y)    -- no problem but doesn't help for next tests
print(    -- print "0"
print(    -- print "nil"
x:Test()        -- print "OK"
y:Test()        -- error "attempt to call method 'Test' (a nil value)"

The problem is that I would like to achieve "y" still having the "foo" and "Test()" members.
Is there any way to prevent this slicing loss and having "y" still being a real lua identity of "x" ?
The example is quite simple but I'm looking for any possible solution : some wrapper on my pointers, instance manager in C++, etc.


Increase Visibility of Your 3D Game App & Earn a Chance To Win $500!
Tap into the largest installed PC base & get more eyes on your game by
optimizing for Intel(R) Graphics Technology. Get started today with the
Intel(R) Software Partner Program. Five $500 cash prizes are up for grabs.
luabind-user mailing list
[hidden email]