[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Interesting C++ way to allocate user data (placement new)
- From: Gé Weijers <ge@...>
- Date: Wed, 16 May 2012 09:47:24 -0700
On Wed, May 16, 2012 at 12:14 AM, Patrick Rapin <email@example.com>
One could then get a step further and specify the metatable registry
name typically associated with the userdata.
void * operator new( size_t size , lua_State * L, const char* metaname )
void* obj = lua_newuserdata( L , size );
I usually delay setting the metatable until the object is in a defined state, which is hard to do with this idiom. If the constructor of the object throws a C++ exception and you catch it the "__gc" routine the metatable refers to may call the destructor, which is a bad idea because the constructor failed.