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

Function main

examples/source/variadic_args_storage.cpp:7–46  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5#include <functional>
6
7int main() {
8
9 std::cout << "=== variadic_args serialization/storage ==="
10 << std::endl;
11
12 sol::state lua;
13 lua.open_libraries(sol::lib::base);
14
15 std::function<void()> function_storage;
16
17 auto store_routine = [&function_storage](sol::function f,
18 sol::variadic_args va) {
19 function_storage =
20 [f,
21 args = std::vector<sol::object>(va.begin(),
22 va.end())]() { f(sol::as_args(args)); };
23 };
24
25 lua.set_function("store_routine", store_routine);
26
27 lua.script(R"(
28function a(name)
29 print(name)
30end
31store_routine(a, "some name")
32)");
33 function_storage();
34
35 lua.script(R"(
36function b(number, text)
37 print(number, "of", text)
38end
39store_routine(b, 20, "these apples")
40)");
41 function_storage();
42
43 std::cout << std::endl;
44
45 return 0;
46}

Callers

nothing calls this directly

Calls 5

as_argsFunction · 0.85
open_librariesMethod · 0.80
scriptMethod · 0.80
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected