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

Function main

examples/source/variadic_args_shifted.cpp:6–35  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4#include <iostream>
5
6int main() {
7
8 std::cout << "=== variadic_args shifting constructor ==="
9 << std::endl;
10
11 sol::state lua;
12 lua.open_libraries(sol::lib::base);
13
14 lua.set_function("f", [](sol::variadic_args va) {
15 int r = 0;
16 sol::variadic_args shifted_va(va.lua_state(), 3);
17 for (auto v : shifted_va) {
18 int value = v;
19 r += value;
20 }
21 return r;
22 });
23
24 lua.script("x = f(1, 2, 3, 4)");
25 lua.script("x2 = f(8, 200, 3, 4)");
26 lua.script("x3 = f(1, 2, 3, 4, 5, 6)");
27
28 lua.script("print(x)"); // 7
29 lua.script("print(x2)"); // 7
30 lua.script("print(x3)"); // 18
31
32 std::cout << std::endl;
33
34 return 0;
35}

Callers

nothing calls this directly

Calls 3

open_librariesMethod · 0.80
scriptMethod · 0.80
lua_stateMethod · 0.45

Tested by

no test coverage detected