satoren / kaguya

C++ binding to Lua
Boost Software License 1.0
345 stars 70 forks source link

Make free functions registerable as members. #10

Closed Sahnvour closed 8 years ago

Sahnvour commented 8 years ago

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.

Sahnvour commented 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::functions.

satoren commented 8 years ago

It is type checked for function overload.

satoren commented 8 years ago

please see template<typename F>struct FunInvoker; and kaguya::nativefunction::cpp11impl::call kaguya::nativefunction::cpp11impl::checkArgTypes etc..

satoren commented 8 years ago

Or you want Improvement compile error message?

Sahnvour commented 8 years ago

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.

satoren commented 8 years ago

hmm. for example, what kind of function?

satoren commented 8 years ago

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.

satoren commented 8 years ago

ah ok. I'm sorry. I understand now about you want. register non member function, but first arguments limitation to class type.

Sahnvour commented 8 years ago

Yes, what do you think ?

satoren commented 8 years ago

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.