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

How to pass Lua Closures into C++ Functions in Sol3 ? #1583

Closed
theanimatorspal opened this issue Feb 22, 2024 · 4 comments
Closed

How to pass Lua Closures into C++ Functions in Sol3 ? #1583

theanimatorspal opened this issue Feb 22, 2024 · 4 comments

Comments

@theanimatorspal
Copy link

This is inside a new_usertype

		"SetDrawCallback",
		[](Jkr::WindowMulT& inWindow, sol::function& inFunction) {
			inWindow.SetDrawCallBack([&inFunction](void*) { inFunction(); });
		},

but it isn't working. I also tried setting sol::function instead of sol::function&, it compiled but gave runtime error in lua_gettop() function.

@skaarj1989
Copy link

Have you tried capturing inFunction by value? maybe it's a lifetime issue?

@theanimatorspal
Copy link
Author

Yup. " I also tried setting sol::function instead of sol::function&," I said.

@skaarj1989
Copy link

I also tried setting sol::function instead of sol::function&,

This means that you have a temporary argument sol::function inFunction and then you capture that temporary argument by reference in the next lambda (inWindow.SetDrawCallBack).

@theanimatorspal
Copy link
Author

Ah man, thank You.

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

2 participants