#include "wrenpp/vm_fun.hpp" #include "wrenpp/def_configuration.hpp" #include #include #include namespace { const constexpr char g_script[] = "" R"(class Math { construct new() {} foreign add(a, b) static sum_params(a,b) { return a + b } } System.print("I am running in a VM!") var myvar = Math.new() var name = "some_test" var number = 123 myvar.add(5, 6) System.print("Script done") )"; } //unnamed namespace int main() { typedef wren::ModuleAndName MN; using wren::variables; std::cout << "hello world\n"; wren::DefConfiguration config; wren::VM vm(&config); vm.interpret("my_module", g_script); std::this_thread::sleep_for(std::chrono::milliseconds(2000)); auto vars = variables(vm, MN{"my_module", "name"}, MN{"my_module","number"}); std::cout << "name = \"" << std::get<0>(vars) << "\", number = " << std::get<1>(vars) << '\n'; const int sum = wren::call(vm, {"my_module", "Math"}, "sum_params", MN{"my_module", "number"}, 90); std::cout << "wren method returned " << sum << " (expected " << std::get<1>(vars) + 90 << ")\n"; return 0; }