lua-users home
lua-l archive

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

> To do that you need to make sure any allocated object is 
> allocated with lua_newuserdata. In C that is easy, you can 
> create a malloc/free interface around that function. In C++ 
> this is slightly more tricky since you need to override the 
> new operator. 

Overloading new is not necessary, just use placement new:

class A {...}

void *p = lua_newuserdata(sizeof(A));
A *a = new(p) A;