lua-users home
lua-l archive

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


Just wanted to share this idea:

void * operator new( size_t size , lua_State * L )
{
  return lua_newuserdata( L , size );
}

Then:

Foo * foo = new ( L ) Foo( constructor arguments );

Of course, you can never:

delete foo;

And in __gc you have to:

( static_cast< Foo * >( lua_touserdata( L , 1 ) ) )->~Foo();

It looks elegant but also dangerous ( in a good way, I think :)

Pablo

P.S. You also have to have a delete operator to deal with exceptions.