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.
When calling a c-bound function from Lua under a
sol::this_environment
withsol::variadic_args
, the final parameter appears duplicated when passed to the function.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
.