satoren / kaguya

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

function object cannot bind right? #35

Closed ThePhD closed 8 years ago

ThePhD commented 8 years ago

Visua Studio 2015, Update 3, latest Kaguya

struct func_obj {
     int x;
     int operator()( int i ) { x = i; return i; }
};

int main (int argc, char*[] argv ) {
     kaguya::State state;
     // Fails Line 408, native_function.hpp
     // is_callable KAGUYA_STATIC_ASSERT assertion
     //state["f"] = kaguya::function( func_obj() );

     // works fine
     state["f"] = kaguya::function( [](int i){ func_obj o; return o(i); } );

     // also fine
     func_obj fo; 
     state["f"] = kaguya::function( [&](int i){ return fo(i); } );
}

Is something wrong with is_callable trait?

ThePhD commented 8 years ago

Can fix with:

native_function_cxx11.hpp, line 99, add specialization for non-const function:

template <typename T, typename Ret, typename... Args>
struct functor_f_signature<Ret(T::*)(Args...)> {
    typedef invoke_signature_type<Ret, Args...> type;
};
satoren commented 8 years ago

Thanks.