[ create a new paste ] login | about

Link: http://codepad.org/uCNKZQh8    [ raw code | output | fork ]

Trass3r - D, pasted on Jan 18:
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
	}
}


Output:
1
2
3
4
5
Line 10: Error: identifier 'LuaState' is not defined
Line 10: Error: LuaState is used as a type
Line 10: Error: identifier 'cstring' is not defined
Line 10: Error: cstring is used as a type
Line 10: Error: cannot have parameter of type void


Create a new paste based on this one


Comments: