Derive C++ Class in Lua
Emmanuel Barroga <[email protected]>
| Newsgroups | gmane.comp.lang.lua.bind.user |
|---|---|
| Message-ID | <[email protected]> |
I am trying to derive my base class in Lua. My code in Lua looks like this:
class 'square' (shape)
function square:__init()
print("Square constructor")
shape:__init()
end
a = shape()
local v = a:area()
print(v)
b = square()
v = b:area()
print(v)
The output is:
Shape Constructor
100
Square Constructor
Shape Constructor
<crash>
Here's my code in C++:
class shape
{
public:
shape(): x(10), y(10) { cout << "Shape constructor.\n"; }
virtual int area() { return (x*y); }
int x, y;
};
class shape_wrapper: public shape,public luabind::wrap_base
{
public:
shape_wrapper(): shape() { }
virtual int area() { return luabind::call_member<int>(this, "area"); }
static int def_area(shape* p) { return p->shape::area(); }
};
...
module( L )
[
class_<shape, shape_wrapper>("shape")
.def(constructor<>())
.def("area", &shape::area, &shape_wrapper::def_area)
.def_readwrite("x", &shape::x)
.def_readwrite("y", &shape::y)
];
I am not sure why it is crashing.
--
Regards,
Emmanuel Barroga
------------------------------------------------------------------------------
ThinkGeek and WIRED's GeekDad team up for the Ultimate
GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the
lucky parental unit. See the prize list and enter to win:
http://p.sf.net/sfu/thinkgeek-promo
_______________________________________________
luabind-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/luabind-user