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

Can't pass nil for smart pointers like std::shared_ptr #1629

Open
deadlocklogic opened this issue Sep 23, 2024 · 2 comments
Open

Can't pass nil for smart pointers like std::shared_ptr #1629

deadlocklogic opened this issue Sep 23, 2024 · 2 comments

Comments

@deadlocklogic
Copy link
Contributor

Why we can't pass nil to std::shared_ptr without registering a new overload. This behavior used to work previously according to my old tests, not anymore.
Consider this example:

#define SOL_ALL_SAFETIES_ON 1
#include <sol/sol.hpp>

struct Test {};

int main() {
    sol::state lua;
    lua.open_libraries(sol::lib::base);
    lua.new_usertype<::Test>("Test");

    lua["f"] = [](std::shared_ptr<Test> arg) {};
    lua.script("f(nil)");

    return 0;
}

Throws this error:

[sol2] An error occurred and has been passed to an error handler: sol: runtime error: stack index 1, expected userdata, received nil: value is not a userdata (bad argument into 'void(std::shared_ptr<Test>)')
stack traceback:
	[C]: in function 'base.f'
	[string "f(nil)"]:1: in main chunk
terminate called after throwing an instance of 'sol::error'
  what():  sol: runtime error: stack index 1, expected userdata, received nil: value is not a userdata (bad argument into 'void(std::shared_ptr<Test>)')
stack traceback:
	[C]: in function 'base.f'
	[string "f(nil)"]:1: in main chunk
Program terminated with signal: SIGSEGV

@ThePhD Any thoughts?

@deadlocklogic
Copy link
Contributor Author

@Smertig Ever noticed this behavior change or I am missing something?

@Smertig
Copy link
Contributor

Smertig commented Sep 25, 2024

@deadlocklogic I worked with this library too long ago, don't remember anything. Sorry.

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