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.18k stars 515 forks source link

Cannot directly bind b2Vec2 to a table entry #1596

Open linsyking opened 5 months ago

linsyking commented 5 months ago

Hi, I met with a problem when using sol with box2d.

Box2d has a class called b2Vec2, and I want to set an entry of a table to a b2Vec2.

I tried:

sol::table nt = s.create_table();
nt["a"] = b2Vec2(1, 2);

The compiler then complains an error:

sol.hpp:18406:143: error: no type named ‘function_pointer_type’ in ‘sol::wrapper<b2Vec2, void>::traits_type’ {aka ‘struct sol::lua_bind_traits<b2Vec2>’}
[build] 18406 |                                                 return agnostic_lua_call_wrapper<fp_t, is_index, is_variable, checked, boost, clean_stack> {}.call(

However, if I change the code to:

sol::table nt = s.create_table();
sol::object o = sol::make_object(s, b2Vec2(1, 2));
nt["a"] = o;

Then it works.

I wonder why this happens and can it be fixed? Thanks!

andipeer commented 4 months ago

Running into the same problem, and your solution helped!