2020-04-30 20:50:46 +00:00
|
|
|
#include "wrenpp/vm_fun.hpp"
|
|
|
|
#include "wrenpp/def_configuration.hpp"
|
2020-04-24 23:49:46 +00:00
|
|
|
#include <iostream>
|
|
|
|
#include <chrono>
|
|
|
|
#include <thread>
|
|
|
|
|
|
|
|
namespace {
|
2020-04-26 15:19:02 +00:00
|
|
|
const constexpr char g_script[] = ""
|
|
|
|
R"(class Math {
|
|
|
|
construct new() {}
|
|
|
|
foreign add(a, b)
|
2020-04-30 17:58:09 +00:00
|
|
|
|
|
|
|
static sum_params(a,b) {
|
|
|
|
return a + b
|
|
|
|
}
|
2020-04-26 15:19:02 +00:00
|
|
|
}
|
|
|
|
System.print("I am running in a VM!")
|
|
|
|
var myvar = Math.new()
|
2020-04-30 17:58:09 +00:00
|
|
|
var name = "some_test"
|
|
|
|
var number = 123
|
2020-04-26 15:19:02 +00:00
|
|
|
myvar.add(5, 6)
|
|
|
|
System.print("Script done")
|
|
|
|
)";
|
|
|
|
|
2020-04-24 23:49:46 +00:00
|
|
|
} //unnamed namespace
|
|
|
|
|
|
|
|
int main() {
|
2020-04-30 17:58:09 +00:00
|
|
|
typedef wren::ModuleAndName MN;
|
|
|
|
using wren::variables;
|
|
|
|
|
2020-04-24 23:49:46 +00:00
|
|
|
std::cout << "hello world\n";
|
2020-04-25 18:45:59 +00:00
|
|
|
wren::DefConfiguration config;
|
|
|
|
wren::VM vm(&config);
|
2020-04-26 15:19:02 +00:00
|
|
|
vm.interpret("my_module", g_script);
|
2020-04-24 23:49:46 +00:00
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(2000));
|
|
|
|
|
2020-04-30 17:58:09 +00:00
|
|
|
auto vars = variables<std::string, int>(vm, MN{"my_module", "name"}, MN{"my_module","number"});
|
|
|
|
std::cout << "name = \"" << std::get<0>(vars) << "\", number = " << std::get<1>(vars) << '\n';
|
2020-04-30 19:18:29 +00:00
|
|
|
const int sum = wren::call<int>(vm, {"my_module", "Math"}, "sum_params", MN{"my_module", "number"}, 90);
|
2020-04-30 17:58:09 +00:00
|
|
|
std::cout << "wren method returned " << sum << " (expected " << std::get<1>(vars) + 90 << ")\n";
|
|
|
|
|
2020-04-24 23:49:46 +00:00
|
|
|
return 0;
|
|
|
|
}
|