Add support for foreign types to get()

wren::get() can now be used to get foreign types by pointer.
Invoking get<A>() will return an A*. With this change it's
now possible to use variables() to get mixed foreign
and core types.
This commit is contained in:
King_DuckZ 2020-05-03 11:32:43 +02:00
parent 90d93d2583
commit 34d2317f11
3 changed files with 49 additions and 16 deletions

View file

@ -130,13 +130,13 @@ cale.add_appointment("go get a haircut")
} //unnamed namespace
int main() {
typedef wren::ModuleAndName MN;
MyConf conf;
wren::VM vm(&conf, nullptr);
vm.interpret("main", g_test_script);
vm.ensure_slots(1);
wren::variable(vm, {"main", "cale"}, 0);
const auto cale = wren::foreign<Calendar>(vm, 0);
Calendar* const cale = std::get<0>(wren::variables<Calendar>(vm, MN{"main", "cale"}));
cale->print_appointments();
return 0;