Bugfixes and improvements, simplify examples
This commit is contained in:
parent
fa0183a3bf
commit
c2089568f3
4 changed files with 18 additions and 53 deletions
|
@ -17,6 +17,7 @@
|
|||
|
||||
#include "wrenpp/def_configuration.hpp"
|
||||
#include "wrenpp/vm_fun.hpp"
|
||||
#include "wrenpp/callback_manager.hpp"
|
||||
#include <string_view>
|
||||
#include <algorithm>
|
||||
#include <ctime>
|
||||
|
@ -107,24 +108,6 @@ System.print("You have %(cale.appointment_count()) appointment(s)")
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
wren::foreign_method_t foreign_method_fn(
|
||||
wren::VM* vm,
|
||||
std::string_view module,
|
||||
std::string_view class_name,
|
||||
bool is_static,
|
||||
std::string_view signature
|
||||
) {
|
||||
if (module == "calendar" and class_name == "Calendar") {
|
||||
if (is_static and signature == "today()")
|
||||
return &Calendar::today;
|
||||
else if (not is_static and signature == "add_appointment(_)")
|
||||
return wren::make_method_bindable<&Calendar::add_appointment>();
|
||||
else if (not is_static and signature == "appointment_count()")
|
||||
return wren::make_method_bindable<&Calendar::appointment_count>();
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
wren::foreign_class_t foreign_class_fn(
|
||||
wren::VM* vm,
|
||||
std::string_view module,
|
||||
|
@ -145,6 +128,10 @@ int main() {
|
|||
|
||||
MyConf conf;
|
||||
wren::VM vm(&conf, nullptr);
|
||||
vm.callback_manager().add_callback(true, "calendar", "Calendar", "today()", &Calendar::today)
|
||||
.add_callback(false, "calendar", "Calendar", "add_appointment(_)", wren::make_method_bindable<&Calendar::add_appointment>())
|
||||
.add_callback(false, "calendar", "Calendar", "appointment_count()", wren::make_method_bindable<&Calendar::appointment_count>());
|
||||
|
||||
vm.interpret("main", g_test_script);
|
||||
|
||||
Calendar* const cale = std::get<0>(wren::variables<Calendar>(vm, MN{"main", "cale"}));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue