Foreign function callbacks now receive a ModuleAndName parameter too.

This commit breaks the ARM64 version, I will fix it next.

Lots going on here. DynafuncMaker got updated to store strings
to back the ModuleAndName objects that get hardcoded in the
assembly glue function.
ModuleAndName is not a typedef to a tuple anymore, because I
discovered that tuples suck. They get always pushed on the stack
when passed as parameter, instead the new implementation gets
passed into 2 registers being it a standard layout type.

dhandy::bt::string got updated so it can be used as a literal
value for non-type template parameters, which allowed for a
really easy to use `wren::MN<>` helper. Code now fully requires
c++20.
This commit is contained in:
King_DuckZ 2022-05-17 01:00:00 +02:00
commit eadd25b827
16 changed files with 247 additions and 53 deletions

View file

@ -69,7 +69,7 @@ System.print("You have %(cale.appointment_count()) appointment(s)")
}
}
static void today (wren::VM& vm) {
static void today (wren::VM& vm, wren::ModuleAndName) {
vm.set_slot_string(0, today_unique_str().get());
}
@ -116,7 +116,7 @@ System.print("You have %(cale.appointment_count()) appointment(s)")
} //unnamed namespace
int main() {
typedef wren::ModuleAndName MN;
using wren::MN;
MyConf conf;
wren::VM vm(&conf, nullptr);
@ -127,7 +127,7 @@ int main() {
vm.interpret("main", g_test_script);
Calendar* const cale = std::get<0>(wren::variables<Calendar>(vm, MN{"main", "cale"}));
Calendar* const cale = std::get<0>(wren::variables<Calendar>(vm, MN<"main", "cale">));
cale->print_appointments();
return 0;

View file

@ -37,13 +37,13 @@ namespace {
std::uniform_int_distribution<int> distrib;
};
void user_input(wren::VM& vm) {
void user_input(wren::VM& vm, wren::ModuleAndName) {
std::string retval;
std::cin >> retval;
set(vm, 0, retval);
}
void random_num(wren::VM& vm) {
void random_num(wren::VM& vm, wren::ModuleAndName) {
auto* const cust_data = vm.user_data<CustomData>();
set(vm, 0, cust_data->distrib(cust_data->generator));
}
@ -69,7 +69,7 @@ int main() {
.add_callback(true, "main", "Game", "random()", &random_num);
interpret(vm, "main", load_file("main.wren"));
wren::call<void>(vm, {"main", "the_game"}, "play_game");
wren::call<void>(vm, wren::MN<"main", "the_game">, "play_game");
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
return 0;

View file

@ -56,7 +56,7 @@ const char* raw_fetch_env (const char* name) noexcept {
return val_ptr;
}
void user_get_env (wren::VM& vm) {
void user_get_env (wren::VM& vm, wren::ModuleAndName) {
set(vm, 0, raw_fetch_env(wren::get<const char*>(vm, 1)));
}
} //unnamed namespace
@ -70,7 +70,7 @@ int main() {
vm.interpret("main", g_script);
wren::call<void>(vm, {"main", "the_user"}, "greet");
wren::call<void>(vm, wren::MN<"main", "the_user">, "greet");
std::cout << "Quitting in 1 sec" << std::endl;
std::this_thread::sleep_for(std::chrono::milliseconds(1000));