sol2
sol2 copied to clipboard
sol::overload incompatible with sol::policies
Compiler: g++ (GCC) 14.2.1 20240805
Using sol::policies around sol::overload results in the function arguments missing from the stack when it gets to the policy function.
Using sol::overload around sol::policies results in a runtime error from the function resolution failing.
#define SOL_ALL_SAFETIES_ON 1
#include <sol/sol.hpp>
struct CppObject {};
void overload1(CppObject&) {}
void overload2(CppObject&, int) {}
int main() {
sol::state lua;
lua.open_libraries(sol::lib::base);
CppObject x;
lua["x"] = &x;
lua["overload1"] = sol::policies(overload1, sol::returns_self());
lua["overload2"] = sol::policies(overload2, sol::returns_self());
lua["policies_overload"] = sol::policies(
sol::overload(
overload1,
overload2
),
sol::returns_self());
lua["overload_policies"] = sol::overload(
sol::policies(overload1, sol::returns_self()),
sol::policies(overload2, sol::returns_self())
);
// good
lua.script("print(overload1(x))");
// good
lua.script("print(overload2(x, 10))");
// nil
lua.script("print(policies_overload(x))");
// sol: no matching function call takes this number of arguments and the specified types
lua.script("print(overload_policies(x))");
return 0;
}