Pass string_view instead of const char* to callback functions
This commit is contained in:
parent
f84234cede
commit
6f4b0ce094
7 changed files with 63 additions and 42 deletions
|
@ -97,8 +97,8 @@ System.print("You have %(cale.appointment_count()) appointment(s)")
|
|||
|
||||
class MyConf : public wren::DefConfiguration {
|
||||
public:
|
||||
char* load_module_fn(wren::VM* vm, const char* module_name) {
|
||||
if (std::string_view{module_name} == "calendar") {
|
||||
char* load_module_fn(wren::VM* vm, std::string_view module_name) {
|
||||
if (module_name == "calendar") {
|
||||
constexpr const std::size_t buff_sz = sizeof(g_calendar_src);
|
||||
char* const buff = static_cast<char*>(MyConf::reallocate_fn(nullptr, buff_sz));
|
||||
std::copy(g_calendar_src, g_calendar_src + buff_sz / sizeof(g_calendar_src[0]), buff);
|
||||
|
@ -107,11 +107,13 @@ System.print("You have %(cale.appointment_count()) appointment(s)")
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
wren::foreign_method_t foreign_method_fn(wren::VM* vm, const char* m, const char* c, bool is_static, const char* s) {
|
||||
std::string_view module(m);
|
||||
std::string_view class_name(c);
|
||||
std::string_view signature(s);
|
||||
|
||||
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;
|
||||
|
@ -123,10 +125,11 @@ System.print("You have %(cale.appointment_count()) appointment(s)")
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
wren::foreign_class_t foreign_class_fn(wren::VM* vm, const char* m, const char* c) {
|
||||
std::string_view module(m);
|
||||
std::string_view class_name(c);
|
||||
|
||||
wren::foreign_class_t foreign_class_fn(
|
||||
wren::VM* vm,
|
||||
std::string_view module,
|
||||
std::string_view class_name
|
||||
) {
|
||||
if (module == "calendar" and class_name == "Calendar") {
|
||||
return wren::make_foreign_class<Calendar>();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue