Closed Sahnvour closed 8 years ago
Oh, OK. Static member looked like it was adding a function to the class metatable to me.
But it does not check for the type it receives before trying to call the function right ?
We can do better, at least for free functions and std::function
s.
It is type checked for function overload.
please see
template<typename F>struct FunInvoker;
and
kaguya::nativefunction::cpp11impl::call
kaguya::nativefunction::cpp11impl::checkArgTypes
etc..
Or you want Improvement compile error message?
Yes, I think it is better to forbid some things at compile time. I haven't looked deeply at your implementation yet (complicated job :D), but at the moment we can register functions with bad arguments.
hmm. for example, what kind of function?
we can register object is contain one operator() . It is equal to lambda. It does not have the type of a lambda
lambda is can convert to std::function ,and register limitation to std::function.
but std::function has calling cost.
and will not be written like .addStaticMember("abc",[]{return 1;})
.
to write .addStaticMember("abc",std::function<int()>([]{return 1;}))
.
I wan't fixing compile error message. but can not avoid MSVC bug now. https://github.com/satoren/kaguya/blob/master/include/kaguya/native_function_cxx11.hpp#L89 has_operator_fn wont work at MSVC.
ah ok. I'm sorry. I understand now about you want. register non member function, but first arguments limitation to class type.
Yes, what do you think ?
I thought about can register non function type.
i wrote c++11 implements for it. https://github.com/satoren/kaguya/commit/104674ba73f6003af573a72cd133e63bb263fc34 your implements has problem if derived class.
I also wanted to make it work with lambdas, but wrapping them in FunctorType is not type safe at compile time and crafting a
is_callable_as_member
looks a bit complicated.see this SO answer for reference, I could not get it to work with multiple parameters.