diff options
Diffstat (limited to 'deps/sol2/examples/source/variadic_args_storage.cpp')
-rw-r--r-- | deps/sol2/examples/source/variadic_args_storage.cpp | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/deps/sol2/examples/source/variadic_args_storage.cpp b/deps/sol2/examples/source/variadic_args_storage.cpp new file mode 100644 index 0000000..fb1a94b --- /dev/null +++ b/deps/sol2/examples/source/variadic_args_storage.cpp @@ -0,0 +1,43 @@ +#define SOL_ALL_SAFETIES_ON 1
+#include <sol/sol.hpp>
+
+#include <iostream>
+#include <functional>
+
+int main() {
+
+ std::cout << "=== variadic_args serialization/storage ===" << std::endl;
+
+ sol::state lua;
+ lua.open_libraries(sol::lib::base);
+
+ std::function<void()> function_storage;
+
+ auto store_routine = [&function_storage] (sol::function f, sol::variadic_args va) {
+ function_storage = [f, args = std::vector<sol::object>(va.begin(), va.end())]() {
+ f(sol::as_args(args));
+ };
+ };
+
+ lua.set_function("store_routine", store_routine);
+
+ lua.script(R"(
+function a(name)
+ print(name)
+end
+store_routine(a, "some name")
+)");
+ function_storage();
+
+ lua.script(R"(
+function b(number, text)
+ print(number, "of", text)
+end
+store_routine(b, 20, "these apples")
+)");
+ function_storage();
+
+ std::cout << std::endl;
+
+ return 0;
+}
|