usertypes

Perhaps the most powerful feature of sol2, usertypes are the way sol2 and C++ communicate your classes to the Lua runtime and bind things between both tables and to specific blocks of C++ memory, allowing you to treat Lua userdata and other things like classes.

To learn more about usertypes, visit:

The examples folder also has a number of really great examples for you to see. There are also some notes about guarantees you can find about usertypes, and their associated userdata, below:

Note

Note that to use many of sol2’s features, such as automatic constructor creation, sol::property, and similar, one must pass these things to the usertype as part of its initial creation and grouping of arguments. Attempting to do so afterwards will result in unexpected and wrong behavior, as the system will be missing information it needs. This is because many of these features rely on __index and __newindex Lua metamethods being overridden and handled in a special way!

Here are some other general advice and tips for understanding and dealing with usertypes: