diff options
author | Clyne Sullivan <clyne@bitgloo.com> | 2022-08-19 19:48:10 -0400 |
---|---|---|
committer | Clyne Sullivan <clyne@bitgloo.com> | 2022-08-19 19:48:10 -0400 |
commit | c467671ae8b6ec161c17e86f3383fd0625f755b8 (patch) | |
tree | fd126d5721256b15c0d71e4c47033e341bdb7816 /lib/sol2/examples/source/variadic_args.cpp | |
parent | da0913771538fd9b1ca538615fd9aa0388608466 (diff) |
remove sol2 (will re-add as submodule)
Diffstat (limited to 'lib/sol2/examples/source/variadic_args.cpp')
-rw-r--r-- | lib/sol2/examples/source/variadic_args.cpp | 45 |
1 files changed, 0 insertions, 45 deletions
diff --git a/lib/sol2/examples/source/variadic_args.cpp b/lib/sol2/examples/source/variadic_args.cpp deleted file mode 100644 index 2d9e557..0000000 --- a/lib/sol2/examples/source/variadic_args.cpp +++ /dev/null @@ -1,45 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include <sol/sol.hpp> - -#include <iostream> - -int main() { - std::cout << "=== variadic_args ===" << std::endl; - - sol::state lua; - lua.open_libraries(sol::lib::base); - - // Function requires 2 arguments - // rest can be variadic, but: - // va will include everything after "a" argument, - // which means "b" will be part of the varaidic_args list too - // at position 0 - lua.set_function("v", [](int a, sol::variadic_args va, int /*b*/) { - int r = 0; - for (auto v : va) { - int value = v; // get argument out (implicit conversion) - // can also do int v = v.as<int>(); - // can also do int v = va.get<int>(i); with index i - r += value; - } - // Only have to add a, b was included from variadic_args and beyond - return r + a; - }); - - lua.script("x = v(25, 25)"); - lua.script("x2 = v(25, 25, 100, 50, 250, 150)"); - lua.script("x3 = v(1, 2, 3, 4, 5, 6)"); - // will error: not enough arguments - //lua.script("x4 = v(1)"); - - lua.script("assert(x == 50)"); - lua.script("assert(x2 == 600)"); - lua.script("assert(x3 == 21)"); - lua.script("print(x)"); // 50 - lua.script("print(x2)"); // 600 - lua.script("print(x3)"); // 21 - - std::cout << std::endl; - - return 0; -}
\ No newline at end of file |