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

Function main

examples/source/tutorials/reading_functions.cpp:4–29  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2#include <sol/sol.hpp>
3
4int main() {
5
6 sol::state lua;
7
8 lua.script(R"(
9 function f (a)
10 return a + 5
11 end
12 )");
13
14 // Get and immediately call
15 int x = lua["f"](30);
16 SOL_ASSERT(x == 35);
17
18 // Store it into a variable first, then call
19 sol::unsafe_function f = lua["f"];
20 int y = f(20);
21 SOL_ASSERT(y == 25);
22
23 // Store it into a variable first, then call
24 sol::protected_function safe_f = lua["f"];
25 int z = safe_f(45);
26 SOL_ASSERT(z == 50);
27
28 return 0;
29}

Callers

nothing calls this directly

Calls 1

scriptMethod · 0.80

Tested by

no test coverage detected