Re: [ANN] luabind 0.9-rc1

Daniel Wallin <[email protected]>
Newsgroups gmane.comp.lang.lua.bind.user
Message-ID <[email protected]>
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

------------------------------------------------------------------------------
Return on Information:
Google Enterprise Search pays you back
Get the facts.
http://p.sf.net/sfu/google-dev2dev
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.