Correctly manage the case of string=nil if wreng_string_t is string_view
This commit is contained in:
parent
a63a8c33d8
commit
10e3c9adac
2 changed files with 19 additions and 2 deletions
|
@ -20,12 +20,28 @@
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
namespace wren {
|
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) {
|
void DefConfiguration::write_fn (VM*, wren_string_t text) {
|
||||||
std::cout << text;
|
std::cout << text;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DefConfiguration::error_fn (VM*, ErrorType type, wren_string_t module, int line, wren_string_t message) {
|
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) {
|
void* DefConfiguration::reallocate_fn (void* ptr, std::size_t size) {
|
||||||
|
|
|
@ -47,7 +47,8 @@ namespace wren {
|
||||||
auto cb = static_cast<detail::Callbacks*>(wrenGetUserData(wvm));
|
auto cb = static_cast<detail::Callbacks*>(wrenGetUserData(wvm));
|
||||||
assert(cb);
|
assert(cb);
|
||||||
assert(cb->error_fn and cb->config_obj and cb->owner);
|
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) {
|
const char* resolve_module_fn (WrenVM* wvm, const char* importer, const char* name) {
|
||||||
|
|
Loading…
Reference in a new issue