Slicing / Object identity problem
ArnaudChapalain <[email protected]>
| Newsgroups | gmane.comp.lang.lua.bind.user |
|---|---|
| Message-ID | <[email protected]> |
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; }
...
module(pLua)
[
def("Identity", &Identity),
class_<A, A_wrap>("A")
.def(constructor<>())
.def(const_self == const_self)
];
********* Lua *********
class 'B' (A)
function B:__init()
A.__init(self)
end
function B:Test()
print("OK")
end
x = B()
x.foo = 0
y = Identity(x)
assert(x == y) -- no problem but doesn't help for next tests
print(x.foo) -- print "0"
print(y.foo) -- 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.
Thanks
------------------------------------------------------------------------------
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.
http://p.sf.net/sfu/intelisp-dev2dev
_______________________________________________
luabind-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/luabind-user