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

Collections of usertypes? #1529

Closed davidchisnall closed 9 months ago

davidchisnall commented 9 months ago

I am possibly not understanding how usertypes work. Here is my mental model:

When you register a usertype, you define the relationship between a C++ type and a Lua type such that instances of one can be translated to the other.

I have followed created a sol3 usertype for my C++ type and then passed a std::vector of this type to a Lua function. I can iterate over the collection using pairs but attempting to call any of the methods on the values panics with this message:

[sol3] An error occurred and panic has been invoked: stack index 1, expected string, received no value: bad get from protected_function_result (is not an error) 

Do I need to do something extra to be able to use a usertype from within a C++ collection?

davidchisnall commented 9 months ago

User error. I was exposing fields and then calling them as methods in Lua.