Closed aster2013 closed 8 years ago
Current in kaguya, __index meta method is using for property. This is a good idea.
Property using newindex. All member's using index
And please add another function:
template<typename ... Funcs>
UserdataMetatable<T>::addStaticOverloadedFunctions(const char* name, Funcs... f)
{
}
Why?
For example:
class Viewport
{
};
Viewport* CreateViewport1();
Viewport* CreateViewport2(Scene*);
Viewport* CreateViewport3(Scene*, Camera*);
lua["Viewport"].setClass(UserdataMetatable<Viewport>()
.addStaticFunction("new", CreateViewport1, &CreateViewport2, &CreateViewport3)
// ...
Currently.
template<typename... Funcs>
UserdataMetatable& addOverloadedFunctions(const char* name, Funcs... f)
And the future that does not change.
Bad performance.
LuaFunction indexfun = kaguya::LuaFunction::loadstring(state, "local arg = {...};local metatable = arg[1];"
"return function(table, index)"
// " if type(table) == 'userdata' then "
" local propfun = metatable['_prop_'..index];"
" if propfun then return propfun(table) end "
// " end "
" return metatable[index]"
" end")(metatable);
the function may call muiti-times, with index like this: prop'name' _propprop_'name' _propprop_prop'name'
you can write print(index)
to view it.
index and newindex rewrite on C.
If allow to add index and newindex, do you need what kind of work? Propery and function will not work if it is to overwrite.
the index and newindex method is using for HashMap in urho3d. like std::map<std::string, variant>.
It can not be convert to lua table?
Maybe better performance lua-table than userdata, If the HashMap modify a lot.
Current the VariantMap is defines as HashMap<StringHash, Variant>, the key is a string hash not a string. and the VariantMap is just for event data. it will not modify a lot.
OK. I understand now.
Hi, the function with default argument value is not working now.
default argument value can not detect in C++ code.#17
Added support for default argument value.
e.g.