sol icon indicating copy to clipboard operation
sol copied to clipboard

Passing a `sol::table` fails as a parameter for `usertype` ctor

Open Nava2 opened this issue 9 years ago • 2 comments

Currently, sol fails to pass a sol::table as a parameter to a usertype.

Minimum example:

class Foo {

public:
    Foo(sol::table /*table*/) { }
};

int main() {
    sol::state lua; 
    lua.new_usertype<Foo, sol::table>("Foo");
    lua.script("a = Foo.new { a = \"wat\" }");
}

The error message is: lua: error: No matching constructor for the arguments provided

Nava2 avatar Feb 17 '16 16:02 Nava2

Interestingly, this works fine:

        _lua.set_function("test_table", [](sol::table table) {
            std::string a = table["a"];
            std::cout << "table.a = " << a << std::endl;
        });
        _lua.script("test_table { a = \"wat\" }");

Nava2 avatar Feb 17 '16 16:02 Nava2

There was a bug in the logic for detecting whether or not a table was called with .new versus :new. This is fixed in sol2.

ThePhD avatar Feb 19 '16 20:02 ThePhD