Closed aster2013 closed 8 years ago
Can it but a little troublesome.
state["Vector3"].setClass(kaguya::UserdataMetatable<Vector3>()
.setConstructors<ABC(float,float,float)>()
);
kaguya::LuaTable call_con_table = state.newTable();
call_con_table["__call"] = kaguya::LuaCodeChunkResult("return function(t,...) return t.new(...) end");
state["Vector3"].setMetatable(call_con_table);
If you want set to multiple metatable, only need one call_con_table.
Add a fucntion to TableKeyReference::setCallable()
So it can change to
state["Vector3"].setClass(kaguya::UserdataMetatable<Vector3>()
.setConstructors<ABC(float,float,float)>()
);
state["Vector3"].setCallable();
How about this?
state["Vector3"].setClass(kaguya::UserdataMetatable<Vector3>()
.setConstructors<Vector3(float,float,float)>()
.enableCallConstruct()
);
Cool!
class Base
{
...
};
class Derived : public Base
{
...
};
state["Derived"].setClass(kaguya::UserdataMetatable<Derived>()
.setConstructors< ... >()
.enableCallConstruct()
);
Please note: When set the callable metatable to Derived class, please make it also call Base member functions.
Thanks, you are so nice.
Or
state["Vector3"].setClass(kaguya::UserdataMetatable<Vector3>()
.setConstructors<Vector3(float,float,float)>(true)
);
But this is true for what don't know at first look.
or make callable is always enabled in kaguya.
It adopted.
Leave new
, because for compatibility and __call
has extra cost.
for example:
It can call
to create a vector3 object. but sometimes I want to create the user data with