lua-users home
lua-l archive

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


I would have to say, no. Not without some additional work.
I have a modified tolua++ which supports our reference counting.
I had to add a few macros:

template <typename T>
void Mtolua_reference( T *p )
{
  x::Referenced *r = dynamic_cast<x::Referenced *>(p);
  r->reference();
}

template <typename T>
void Mtolua_unreference( T *p )
{
  x::Referenced *r = dynamic_cast<x::Referenced *>(p);
  if (r && r->getReferenceCount())
    r->unreference();
}

Then modify the tolua executable so that the collect functions are generated as:

static int tolua_collect_x__Class (lua_State* tolua_S)
{
 x::Class* self = (x::Class*) tolua_tousertype(tolua_S,1,0);
Mtolua_unreference(self);
return 0;
}

And constructors are generated as:

   x::Class* tolua_ret =  Mtolua_new((x::Class)(*center,*axis));


To summarize, tolua++ does not support reference counting.
Not by default. And certainly not without some effort.

Still to this day, I'm waiting for something that has the generality of tolua++, the scalability of tolua++, but the languesupport of luabind.
Exporting a large C++ API with Luabind...that would be an enormous effort, same as for SWIG.
With tolua++, just copy the headers, clean them (semiautomatic) and run tolua on them.

I was working with LQT for a while. But it was hard to get all the way. As it was using a C++toXML parser, something that is close to impossible to get through all our code. It chokes on quite a few things.

/A



On Fri, Dec 10, 2010 at 11:42 PM, Tim Mensch <tim-lua-l@bitgems.com> wrote:
Does anyone know whether toLua++ support classes wrapped by smart
pointers? Specifically the boost::shared_ptr class. If I have to I can
run some tests, but I've burned a lot of time on trying various other
binding libraries already, and I'm hoping someone has a quick answer.

I see that it supports class templates, which is a start, but is not
necessarily sufficient, depending on implementation. Specifically, say I
have this:

class Base;
class Derived;
typedef shared_ptr<Base> BaseRef;
typedef shared_ptr<Derived> DerivedRef;

class Base
{
public:
 void foo( BaseRef b );
}

class Derived: public Base
{
 ...
}

Now I have an object of type Derived that I want to pass into
Base::foo(). In C++ this works fine:

DerivedRef d = ...;
BaseRef b = ... ;

b->foo(d); // will work

But will it work in ToLua++? I ask because DerivedRef is not actually a
derived class of BaseRef, though in C++ they convert correctly. LuaBind
does handle this, but is causing so much code bloat that I'd like to
avoid using it.

Thanks in advance,

Tim




--