Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extra argument when using sol::environment with sol::variadic_args in call #1458

Open
ricosolana opened this issue Feb 20, 2023 · 0 comments

Comments

@ricosolana
Copy link

ricosolana commented Feb 20, 2023

When calling a c-bound function from Lua under a sol::this_environment with sol::variadic_args, the final parameter appears duplicated when passed to the function.

#include <sol/sol.hpp>

int main() {
    sol::state state;
    state.open_libraries();

    sol::environment env(state, sol::create, state.globals());

    /*
    // This works fine
    state["OnState"] = [](sol::this_state ts, sol::variadic_args args) {
        sol::state_view view(ts);
        auto&& typefx(view["type"]);
        for (int i = 0; i < args.size(); i++) {
            std::string s = typefx(args[i]);
            std::cout << i << " " << s << "\n";
        }
        assert(args.size() == 1);
    };

    state.script("OnState(function() end)", env);
    */

    // A lambda signature with the variadic_args and this_environment swapped does appear to work as intended
    // [&](sol::variadic_args args, sol::this_environment te)

    // This does not work fine
    state["OnEnv"] = [](sol::this_environment ts, sol::variadic_args args) {
        sol::environment& view(ts);
        auto&& typefx(view["type"]);
        for (int i = 0; i < args.size(); i++) {
            std::string s = typefx(args[i]);
            std::cout << i << " " << s << "\n";
        }
        assert(args.size() == 1);
    };
    
    state.script("OnEnv(function() end)", env);

    return 0;
}

This does not happen however when this_environment is the last parameter (the variadic_args in this case contains the correct size).

As shown in the commented-out portion, this does not happen with sol::state.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant