Skip to content

bind lambda method failed #72

@zeroxer

Description

@zeroxer
  • I want to bind a lambda function as class method, because there is a method with overlap.
class Button {
public:
        virtual void setPosition(const Layout2d& position);
        void setPosition(Layout x, Layout y)
        {
            setPosition({std::move(x), std::move(y)});
        }
}

try direct bind

    module.class_<tgui::Button>("Button")
        .constructor<>()
        .fun<&tgui::Button::setPosition>("setPosition")
  • error
src\binding\javascript\js_tgui.cpp(184): error C2672: 'qjs::Context::Module::class_registrar<tgui::Button>::fun': no matching overloaded function found
F:\gp09\g9s1repo\client\engine\src\script/jsscript/quickjspp.hpp(1652): note: could be 'qjs::Context::Module::class_registrar<tgui::Button> &qjs::Context::Module::class_registrar<tgui::Button>::fun(const char *)'
F:\gp09\g9s1repo\client\engine\src\script/jsscript/quickjspp.hpp(1652): note: 'F': cannot deduce the type of the placeholder
src\binding\javascript\js_tgui.cpp(184): note: cannot deduce type for 'auto' from 'overloaded-function'
src\binding\javascript\js_tgui.cpp(184): note: 'F': invalid template argument for 'qjs::Context::Module::class_registrar<tgui::Button>::fun', expected compile-time constant expression
F:\gp09\g9s1repo\client\engine\src\script/jsscript/quickjspp.hpp(1640): note: or       'qjs::Context::Module::class_registrar<tgui::Button> &qjs::Context::Module::class_registrar<tgui::Button>::fun(const char *,F &&)'
src\binding\javascript\js_tgui.cpp(184): note: 'qjs::Context::Module::class_registrar<tgui::Button>::fun': invalid template argument for 'F', type expected
scons: *** [build\obj\js_tgui.obj] Error 2
scons: building terminated because of errors.

try to use lambda

    module.class_<tgui::Button>("Button")
        .constructor<>()
        .fun("setPosition",
             [](tgui::Button& self, double x, double y) {   //
                 self.setPosition(x, y);
             });
  • compile error
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\include\tuple(1057): error C2672: 'invoke': no matching overloaded function found
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\include\type_traits(1674): note: could be 'unknown-type std::invoke(_Callable &&,_Ty1 &&,_Types2 ...) noexcept(<expr>)'
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\include\tuple(1057): note: Failed to specialize function template 'unknown-type std::invoke(_Callable &&,_Ty1 &&,_Types2 ...) noexcept(<expr>)'
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\include\tuple(1057): note: With the following template arguments:
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\include\tuple(1057): note: '_Callable=js_bind_tgui::<lambda_7> &'
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\include\tuple(1057): note: '_Ty1=tgui::Button'
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\include\tuple(1057): note: '_Types2={double, double}'
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\include\type_traits(1677): note: 'std::_Invoker_functor::_Call': no matching overloaded function found
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\include\type_traits(1574): note: could be 'unknown-type std::_Invoker_functor::_Call(_Callable &&,_Types ...) noexcept(<expr>)'
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\include\type_traits(1668): note: or       'unknown-type std::invoke(_Callable &&) noexcept(<expr>)'
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\include\tuple(1057): note: 'unknown-type std::invoke(_Callable &&) noexcept(<expr>)': expects 1 arguments - 4 provided
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\include\tuple(1057): note: the template instantiation context (the oldest one first) is
src\binding\javascript\js_tgui.cpp(197): note: see reference to function template instantiation 'qjs::Context::Module::class_registrar<tgui::Button> &qjs::Context::Module::class_registrar<tgui::Button>::fun<js_bind_tgui::<lambda_7>>(const char *,F &&)' being compiled
        with
        [
            F=js_bind_tgui::<lambda_7>
        ]
src\binding\javascript\js_tgui.cpp(232): note: see the first reference to 'qjs::Context::Module::class_registrar<tgui::Button>::fun' in 'js_bind_tgui'
F:\gp09\g9s1repo\client\engine\src\script/jsscript/quickjspp.hpp(1642): note: see reference to function template instantiation 'qjs::detail::property_proxy<const char *> &qjs::detail::property_proxy<const char *>::operator =<_Ty>(T &&)' being compiled
        with
        [
            _Ty=js_bind_tgui::<lambda_7>,
            T=js_bind_tgui::<lambda_7>
        ]
F:\gp09\g9s1repo\client\engine\src\script/jsscript/quickjspp.hpp(1207): note: see reference to function template instantiation 'JSValue qjs::js_traits<js_bind_tgui::<lambda_7>,void>::wrap<_Ty>(JSContext *,Functor &&)' being compiled
        with
        [
            _Ty=js_bind_tgui::<lambda_7>,
            Functor=js_bind_tgui::<lambda_7>
        ]
F:\gp09\g9s1repo\client\engine\src\script/jsscript/quickjspp.hpp(1974): note: see reference to function template instantiation 'JSValue qjs::js_traits<std::function<_Ty>,int>::wrap<js_bind_tgui::<lambda_7>>(JSContext *,Functor &&) noexcept' being compiled      
        with
        [
            _Ty=void (tgui::Button &,double,double),
            Functor=js_bind_tgui::<lambda_7>
        ]
F:\gp09\g9s1repo\client\engine\src\script/jsscript/quickjspp.hpp(1933): note: see reference to function template instantiation 'JSValue qjs::detail::wrap_call<_Ret,tgui::Button&,double,double,js_bind_tgui::<lambda_7>&>(JSContext *,Callable,int,JSValue *) noexcept' being compiled
        with
        [
            _Ret=void,
            Callable=js_bind_tgui::<lambda_7> &
        ]
F:\gp09\g9s1repo\client\engine\src\script/jsscript/quickjspp.hpp(575): note: see reference to function template instantiation 'decltype(auto) std::apply<js_bind_tgui::<lambda_7>&,std::tuple<tgui::Button,double,double>>(_Callable,_Tuple &&) noexcept(<expr>)' being compiled
        with
        [
            _Callable=js_bind_tgui::<lambda_7> &,
            _Tuple=std::tuple<tgui::Button,double,double>
        ]
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\include\tuple(1067): note: see reference to function template instantiation 'decltype(auto) std::_Apply_impl<js_bind_tgui::<lambda_7>&,_Ty,0,1,2>(_Callable,_Tuple &&,std::integer_sequence<size_t,0,1,2>) noexcept(<expr>)' being compiled
        with
        [
            _Ty=std::tuple<tgui::Button,double,double>,
            _Callable=js_bind_tgui::<lambda_7> &,
            _Tuple=std::tuple<tgui::Button,double,double>
        ]
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\include\tuple(1058): error C2672: 'invoke': no matching overloaded function found
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\include\type_traits(1674): note: could be 'unknown-type std::invoke(_Callable &&,_Ty1 &&,_Types2 ...) noexcept(<expr>)'
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\include\tuple(1058): note: Failed to specialize function template 'unknown-type std::invoke(_Callable &&,_Ty1 &&,_Types2 ...) noexcept(<expr>)'
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\include\tuple(1058): note: With the following template arguments:
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\include\tuple(1058): note: '_Callable=js_bind_tgui::<lambda_7> &'
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\include\tuple(1058): note: '_Ty1=tgui::Button'
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\include\tuple(1058): note: '_Types2={double, double}'
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\include\type_traits(1677): note: 'std::_Invoker_functor::_Call': no matching overloaded function found
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\include\type_traits(1574): note: could be 'unknown-type std::_Invoker_functor::_Call(_Callable &&,_Types ...) noexcept(<expr>)'
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\include\type_traits(1668): note: or       'unknown-type std::invoke(_Callable &&) noexcept(<expr>)'
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\include\tuple(1058): note: 'unknown-type std::invoke(_Callable &&) noexcept(<expr>)': expects 1 arguments - 4 provided
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\include\tuple(1058): note: the template instantiation context (the oldest one first) is
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\include\tuple(1067): note: see reference to function template instantiation 'decltype(auto) std::_Apply_impl<js_bind_tgui::<lambda_7>&,_Ty,0,1,2>(_Callable,_Tuple &&,std::integer_sequence<size_t,0,1,2>)' being compiled
        with
        [
            _Ty=std::tuple<tgui::Button,double,double>,
            _Callable=js_bind_tgui::<lambda_7> &,
            _Tuple=std::tuple<tgui::Button,double,double>
        ]
scons: *** [build\obj\js_tgui.obj] Error 2
scons: building terminated because of errors.

it seems that ref lost when try to match

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions