[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Lua - C++ Bindings
- From: Jose Luis Hidalgo <joseluis.hidalgo@...>
- Date: Wed, 21 Jan 2009 10:12:19 +0100
On Wed, Jan 21, 2009 at 7:01 AM, Anders Backman <email@example.com> wrote:
> Ok, I know OSG by heart, and its a loot of classes, you dont think you need
> an automatic parser then?
I see your point, but I really think the problem of wrapping C++
only be done under some circumstances. I'll try to explain it better,
from the SLB's point of view (or mine).
SLB was simple, very simple indeed, it was something like a template
specialization pattern like
SLB::push<Type>(L, Type& obj); // to push objects
Type& SLB::get<Type>(L, int pos); // to get objects
For basic types is straightforward, but what we should do with
instances of classes ? The problem is basically C++, it's far too
flexible, you can have different kind of constructors, copy operators,
destructors, public, protected, or private methods, and so on.
Moreover one can do a push of an object, a pointer to an object, a
reference to an object, a const reference to an object, or a const
pointer to an object... in each case what should we do? how should we
handle the object? how should we handle memory?
When writing wrappers we can not suppose the object will have a proper
copy operator, or copy constructor, because even if is never used in
practice the code will be generated and then the compiler will raise
an error. But, also, there are objects that maybe we don't want to be
copied, for smart pointer for example what we really want is to
increase and decrease the reference counter, ...
The problem is even bigger when we allow to create objects from within
the Script and then we return those objects from the script to the C++
side. Who should handle the memory then?
For that reason I let SLB to have policies, when you do a wrapper of a
class you choose or write a policy to control how should the object be
handled when goes into the script, when comes out, when is created
inside the script, or when then the garbage collectors claims its
memory in the script... SLB/include/Instance.hpp to see examples.
That's why I think is quite difficult to write a GENERIC wrapper
generator for C++ to lua, for particular libraries maybe its easy, and
for "good"/"normal" code is also possible, but complete generic... I
don't really think so, there is no generic policy that could cope with
all possible classes.
I will try to have a look at cpp2xml, and lqt, and see what we can do
there. For OSG, just in case you need it, the best solution I can come
with is using osgIntrospection to generate the wrappers (that should
be easy, for most classes but I bet there are lots of exceptions).
Hope is clearer now :)
Jose L. Hidalgo Valiño (PpluX)
---- http://www.pplux.com ----