private void wrapClass(T)(T instance)
{
auto ptr = cast (Object *) newUserdata ( (Object *).sizeof);
*ptr = instance;
loadClassMetatable (typeid(T).toString()); // leaves the metatable on the stack
setMetatable (-2); // pops table and sets it as metatable of the userdata
}
public LuaState loadClassMetatable (cstring class_name)
{
class_name = mangleClass (class_name);
getMetatable (class_name);
if (isNil (-1)) // if the metatable hasn't been loaded yet, create it
{
pop (); // remove the nil
newMetatable (class_name); // create a new metatable t, push it and assoc. it with class_name in the registry
pushString ("__index"); // table index
pushValue (-2); // pushes the metatable
setTable (-3); // metatable.__index = metatable
}
}