Rapptz / sol

A C++11 Lua wrapper
MIT License
208 stars 32 forks source link

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

Open Nava2 opened 8 years ago

Nava2 commented 8 years ago

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 commented 8 years ago

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\" }");
ThePhD commented 8 years ago

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.