[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: How to bind inherited C++ classes?
- From: Patrick Rapin <toupie300@...>
- Date: Sat, 31 Dec 2011 09:32:05 +0100
> How do I bind C++ classes to Lua so that when I try to convert a Lua
> object to a C++ class, it succeeds even if the object contains a C++
> class that's derived from the one I want?
There are probably plenty of ways to do this. I don't know if major
automatic binding libraries like Swig or toLua support this.
What I can tell is how the custom binding of our Pipeline library works.
Each Lua object is represented by a full userdata consisting of a
pointer to the C++ object, and a string buffer to store the *class
There is also a shared table, used as a hash table, with the class
names as keys and the base class names as values (or nil if the class
does not derive from another one).
Having that, Pipeline can check whether a given Lua object is
compatible with the required argument class type.