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

Function main

examples/source/any_return.cpp:26–53  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

24}
25
26int main() {
27 sol::state lua;
28
29 lua["f"] = fancy_func;
30
31 int result = lua["f"](1, 2);
32 // result == 3
33 SOL_ASSERT(result == 3);
34 double result2 = lua["f"](false, 2.5);
35 // result2 == 2.5
36 SOL_ASSERT(result2 == 2.5);
37
38 // call in Lua, get result
39 // notice we only need 2 arguments here, not 3
40 // (sol::this_state is transparent)
41 lua.script("result3 = f(true, 5.5)");
42 double result3 = lua["result3"];
43 // result3 == 16.5
44 SOL_ASSERT(result3 == 16.5);
45
46 std::cout << "=== any_return ===" << std::endl;
47 std::cout << "result : " << result << std::endl;
48 std::cout << "result2: " << result2 << std::endl;
49 std::cout << "result3: " << result3 << std::endl;
50 std::cout << std::endl;
51
52 return 0;
53}

Callers

nothing calls this directly

Calls 1

scriptMethod · 0.80

Tested by

no test coverage detected