lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


> 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
name*.
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.