Correctly manage the case of string=nil if wreng_string_t is string_view

This commit is contained in:
King_DuckZ 2022-04-29 02:09:12 +02:00
parent a63a8c33d8
commit 10e3c9adac
2 changed files with 19 additions and 2 deletions

View file

@ -20,12 +20,28 @@
#include <algorithm>
namespace wren {
namespace {
template <typename T>
bool empty(T* message) {
return not (message and *message);
}
} //unnamed namespace
void DefConfiguration::write_fn (VM*, wren_string_t text) {
std::cout << text;
}
void DefConfiguration::error_fn (VM*, ErrorType type, wren_string_t module, int line, wren_string_t message) {
std::cerr << "Wren error: " << message << " in " << module << ':' << line << '\n';
using std::empty;
std::cerr << "Wren error: " << message;
if (!empty(module)) {
std::cerr << " in " << module;
if (line > -1) {
std::cerr << ':' << line;
}
}
std::cerr << '\n';
}
void* DefConfiguration::reallocate_fn (void* ptr, std::size_t size) {

View file

@ -47,7 +47,8 @@ namespace wren {
auto cb = static_cast<detail::Callbacks*>(wrenGetUserData(wvm));
assert(cb);
assert(cb->error_fn and cb->config_obj and cb->owner);
cb->error_fn(*cb->config_obj, cb->owner, to_error_type(type), module, line, message);
const char* const sane_module = (module ? module : "");
cb->error_fn(*cb->config_obj, cb->owner, to_error_type(type), sane_module, line, message);
}
const char* resolve_module_fn (WrenVM* wvm, const char* importer, const char* name) {