Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sol::overload incompatible with sol::policies #1631

Open
nimble0 opened this issue Sep 26, 2024 · 0 comments
Open

sol::overload incompatible with sol::policies #1631

nimble0 opened this issue Sep 26, 2024 · 0 comments

Comments

@nimble0
Copy link

nimble0 commented Sep 26, 2024

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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant