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

Wrong userdata type detected #1642

Open
s13n opened this issue Nov 5, 2024 · 1 comment
Open

Wrong userdata type detected #1642

s13n opened this issue Nov 5, 2024 · 1 comment

Comments

@s13n
Copy link

s13n commented Nov 5, 2024

I am struggling with a case where several different factory functions return a std::shared_ptr to different user defined types. The factory functions are implemented in C++ and bound with sol 3.3.1 to be called from Lua. The problem is that when I pass a shared_ptr thus obtained to another function as a parameter, the type of the object is reported to be wrong. This is roughly what happens:

-- Lua code:
require 'MyFactories'
local objA = makeObjA()
local objB = makeObjB(objA)    -- error here: objA is a shared_ptr to the wrong type

// C++ code (in shared object that gets loaded with the above require):
std::shared_ptr<A> makeObjA() { ... }
std::shared_ptr<B> makeObjB(std::shared_ptr<A> a) { ... }
lua["makeObjA"] = &makeObjA;
lua["makeObjB"] = &makeObjB;

The puzzling thing is that Lua complains about the parameter passed to makeObjB is some other type X that is not related to either A or B. Something like expected userdata, received sol.sol::d::u<X>: value is a userdata but is not the correct unique usertype (bad argument into 'std::shared_ptr<B>(std::shared_ptr<A>)')

Also puzzling is that the error happens with GCC on Linux, regardless of the version of GCC (I tested all versions from 10 to 14), but it doesn't happen with clang18 on the same Linux system. On Windows with MSVC 2022 it doesn't show up, either. I'm using CMake to control the build, and I use Lua 5.4.7 compiled as C++ as part of the same build.

Before I work to produce a complete test case, has somebody encountered something similar? Any hints as to how to proceed?

@deadlocklogic
Copy link
Contributor

Possibly related to #1556

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