ThePhD / sol2

Sol3 (sol2 v3.0) - a C++ <-> Lua API wrapper with advanced features and top notch performance - is here, and it's great! Documentation:
http://sol2.rtfd.io/
MIT License
4.06k stars 492 forks source link

attempt to call field 'new' (a nil value) #1540

Open zulqarnain1337 opened 8 months ago

zulqarnain1337 commented 8 months ago

lua_state.new_usertype<Vector_t>("vector",
    sol::constructors <Vector_t(), Vector_t(float, float, float)>(),
    "x", &Vector_t::x,
    "y", &Vector_t::y,
    "z", &Vector_t::z
);

local vec = vector.new(0,0,0); -- attempt to call field 'new' (a nil value)
Rochet2 commented 8 months ago

Can you provide more information? For example what version of sol you are using, what version of lua, how Vector_t looks like exactly?

I tried to replicate the issue in godbolt but I did not succeed: https://godbolt.org/z/6Yxz7o6od Everything seems to work fine.

```cpp #include #define SOL_ALL_SAFETIES_ON 1 #include struct Vector_t { int x,y,z; }; int main() { sol::state lua; lua.open_libraries(); lua.new_usertype("vector", sol::constructors (), "x", &Vector_t::x, "y", &Vector_t::y, "z", &Vector_t::z ); lua.script(R"( local v = vector.new() print(v.x, v.y, v.z) local v = vector.new(1,2,3) print(v.x, v.y, v.z) local v = vector.new(0,0,0) print(v.x, v.y, v.z) )"); return 0; } ```