Closed GasimGasimzada closed 7 months ago
If you dont want to explicitly declare the return types with std::variant
(which should also work AFAIK), you can create a sol::object
with sol::make_object(lua, anything_here)
.
And you can get lua from within a function bound with sol by using sol::this_state
.
Here is an example that should work
struct Foo {};
sol::object exampleFunction(sol::this_state const& s, int value)
{
sol::state_view lua(s);
if (value == 1)
return sol::make_object(lua, "something");
if (value == 2)
return sol::make_object(lua, 123);
if (value == 3)
return sol::make_object(lua, Foo());
return sol::make_object(lua, sol::lua_nil);
}
Thank you!
I want to create the following interface:
To make the code more maintainable, I want to create a function that returns anything and internall, return the needed user types and tables:
Currently, I need to return
std::variadic
for this but I do not want to think about this part and want to just return anything. Is it possible to do it in Sol?