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

Function main

examples/source/tutorials/writing_template_functions.cpp:9–33  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7}
8
9int main() {
10
11 sol::state lua;
12
13 // adds 2 integers
14 auto int_function_pointer = &my_add<int, int>;
15 lua["my_int_add"] = int_function_pointer;
16
17 // concatenates 2 strings
18 auto string_function_pointer
19 = &my_add<std::string, std::string>;
20 lua["my_string_combine"] = string_function_pointer;
21
22 lua.script("my_num = my_int_add(1, 2)");
23 int my_num = lua["my_num"];
24 SOL_ASSERT(my_num == 3);
25
26 lua.script(
27 "my_str = my_string_combine('bark bark', ' woof "
28 "woof')");
29 std::string my_str = lua["my_str"];
30 SOL_ASSERT(my_str == "bark bark woof woof");
31
32 return 0;
33}

Callers

nothing calls this directly

Calls 1

scriptMethod · 0.80

Tested by

no test coverage detected