Colm Sloan wrote:
> Fantastic work. I didn't realize how much had been done. Where can I read
> more about these two points?:
Both of these features are actually not documented due to lack of time.
Here's a short explanation though:
> * Automatically perform down-casts as well as up-casts when converting
> arguments from Lua to C++.
Rather than just cast up to base types, we search the graph in both
directions. See example below.
> * When converting from C++ to Lua, polymorphic instances are
> automatically cast to their most derived type.
This means that code like this:
struct X
{
virtual ~X() {}
};
struct Y : X
{
void f();
};
X* make()
{
return new Y;
}
void take(Y*);
...
class_<X>("X"),
class_<Y, X>("Y")
.def("f", &Y::f, adopt(result)),
def("make", &make),
def("take", &take)
.. and later in Lua:
x = make()
x:f()
will work. The dynamic type of the instance returned from make() will be
used to determine the class.
take(x)
will also work, because luabind can cast the held X* down to a Y*.
HTH,
--
Daniel Wallin
BoostPro Computing
http://www.boostpro.com
|