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.12k stars 500 forks source link

Correct way to bind nested classes #1419

Closed deadlocklogic closed 1 year ago

deadlocklogic commented 1 year ago

Code:

struct type1 {
    struct type2 {
    };
};

Binding:

auto utype1 = state.new_usertype<::type1>(
    "type1"
);
auto utype2 = state["type1"].get<sol::table>().new_usertype<::type1::type2>(
    "type2"
);

This works thought but the indirection feels smelly, is there a cleaner way to do so? Thanks.

ThePhD commented 1 year ago

At the moment, this is the way to handle it, yes. It is clunky, and it would be nice if there was a relationship I could automatically build here, but unfortunately the way this work is that each of those types are entirely different even though they're visually / lexically "related" by one being nested in another.