call() will fail earlier when object for call doesn't exist

This commit is contained in:
King_DuckZ 2022-04-22 22:04:09 +02:00
commit f749b7fb18
3 changed files with 28 additions and 5 deletions

View file

@ -266,10 +266,18 @@ namespace wren {
m_local->user_data_type = detail::type_id<std::nullptr_t>();
}
bool VM::has_user_data() const {
bool VM::has_user_data() const noexcept {
return nullptr != m_local->user_data;
}
bool VM::has_module(const char* module) const noexcept {
return wrenHasModule(m_local->wvm, module);
}
bool VM::has_variable(const char* module, const char* name) const noexcept {
return wrenHasVariable(m_local->wvm, module, name);
}
std::size_t VM::dynafunc_byte_size() const {
return m_local->dynafunc.total_memory();
}
@ -322,11 +330,23 @@ namespace wren {
return wrenGetSlotCount(m_local->wvm);
}
void VM::variable(const char* module, const char* name, int slot) {
void VM::variable(const char* module, const char* name, int slot) noexcept {
assert(slot_count() >= 1);
wrenGetVariable(m_local->wvm, module, name, slot);
}
void VM::variable_or_throw(const char* module, const char* name, int slot) {
using std::string;
using std::runtime_error;
if (not has_module(module))
throw runtime_error(string{"Module "} + module + " is unknown");
if (not has_variable(module, name))
throw runtime_error(string{"Variable "} + module + "::" + name + " not found");
variable(module, name, slot);
}
void VM::set_slot_handle (const Handle& handle, int slot) {
wrenSetSlotHandle(m_local->wvm, slot, handle);
}

View file

@ -73,7 +73,7 @@ namespace wren {
}
void variable(VM& vm, const ModuleAndName& mod_and_name, int slot) {
vm.variable(std::get<0>(mod_and_name), std::get<1>(mod_and_name), slot);
vm.variable_or_throw(std::get<0>(mod_and_name), std::get<1>(mod_and_name), slot);
}
void variable (VM& vm, const Handle& handle, int slot) {