MCPcopy Create free account
hub / github.com/ThePhD/sol2 / fancy_func

Function fancy_func

examples/source/any_return.cpp:9–24  ·  view source on GitHub ↗

Uses some of the fancier bits of sol2, including the "transparent argument", sol::this_state, which gets the current state and does not increment function arguments

Source from the content-addressed store, hash-verified

7// "transparent argument", sol::this_state, which gets the
8// current state and does not increment function arguments
9sol::object fancy_func(
10 sol::object a, sol::object b, sol::this_state s) {
11 sol::state_view lua(s);
12 if (a.is<int>() && b.is<int>()) {
13 return sol::object(
14 lua, sol::in_place, a.as<int>() + b.as<int>());
15 }
16 else if (a.is<bool>()) {
17 bool do_triple = a.as<bool>();
18 return sol::object(lua,
19 sol::in_place_type<double>,
20 b.as<double>() * (do_triple ? 3 : 1));
21 }
22 // Can also use make_object
23 return sol::make_object(lua, sol::lua_nil);
24}
25
26int main() {
27 sol::state lua;

Callers

nothing calls this directly

Calls 2

make_objectFunction · 0.85
objectClass · 0.70

Tested by

no test coverage detected