ThePhD / sol2

Sol3 (sol2 v3.0) - a C++ <-> Lua API wrapper with advanced features and top notch performance - is here, and it's great! Documentation:
http://sol2.rtfd.io/
MIT License
4.18k stars 515 forks source link

operator== that does not return a bool makes vector unable to bind #1516

Open smbape opened 1 year ago

smbape commented 1 year ago
#define SOL_ALL_SAFETIES_ON 1
#include <sol/sol.hpp>

struct A {
    bool val;
    A() = default;
    A(bool val) : val(val) {}

    std::vector<A> vector_as_object() {
        return { *this };
    }
};

A operator == (const A& a, const A& b) {
    return A(a.val == b.val);
}

int main(int, char* []) {
    sol::state lua;

    sol::usertype<A> usertype_table = lua.new_usertype<A>("A");
    usertype_table.set_function("vector_as_object", &A::vector_as_object);
    return 0;
}

/opt/dev/lua-sol2/build_linux/_deps/sol2-src/include/sol/usertype_container.hpp:860:51: error: could not convert ‘operator==((*(const A*)(& value)), (*(const A*)(& sol::container_detail::get_value<A&>((sol::container_detail::usertype_container_default<std::vector<A>, void>::is_associative{std::integral_constant<bool, false>()}, std::integral_constant<bool, false>()), (* & it.__gnu_cxx::__normal_iterator<A*, std::vector<A> >::operator*())))))’ from ‘A’ to ‘bool’

Version : 3.3.0 OS : WSL Ubuntu 22.04.2 LTS

In the actual issue, I have no control over A, which prevents me from defining an operator bool() const. Is there a workaround?