From 616381516bb023ffd8ed5ea9fdfacca41d9f1378 Mon Sep 17 00:00:00 2001 From: King_DuckZ Date: Wed, 25 May 2022 11:56:13 +0200 Subject: [PATCH] New helper function for abort_fiber + message --- include/wrenpp/detail/construct_foreign_class.hpp | 10 +++++----- include/wrenpp/vm_fun.hpp | 4 ++-- src/vm_fun.cpp | 5 +++++ 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/include/wrenpp/detail/construct_foreign_class.hpp b/include/wrenpp/detail/construct_foreign_class.hpp index e82a3c8..54b9e76 100644 --- a/include/wrenpp/detail/construct_foreign_class.hpp +++ b/include/wrenpp/detail/construct_foreign_class.hpp @@ -143,14 +143,14 @@ namespace wren { const auto result = detail::ForeignClassHelper::construct(vm, vm.slot_count() - 1, mem); if (not result.success) { - set(vm, 1, std::string{"No registered c++ constructor "} + + abort_fiber_with_error(vm, 1, + std::string{"No registered c++ constructor "} + #if defined(WRENPP_WITH_NAME_GUESSING) - "for class " + guess_class_name() + " " + + "for class " + guess_class_name() + " " + #endif - "takes " + std::to_string(result.parameter_count) + - " parameter" + (result.parameter_count == 1 ? "" : "s") + "takes " + std::to_string(result.parameter_count) + + " parameter" + (result.parameter_count == 1 ? "" : "s") ); - vm.abort_fiber(1); } }; ret.finalize = [](void* mem) { diff --git a/include/wrenpp/vm_fun.hpp b/include/wrenpp/vm_fun.hpp index e783019..b5030f9 100644 --- a/include/wrenpp/vm_fun.hpp +++ b/include/wrenpp/vm_fun.hpp @@ -58,6 +58,7 @@ namespace wren { void variable(VM& vm, const Handle& handle, int slot); void variable_ensure_slot(VM& vm, ModuleAndName mod_and_name, int slot); void variable_ensure_slot(VM& vm, const Handle& handle, int slot); + void abort_fiber_with_error (VM& vm, int slot, std::string_view message); namespace detail { template @@ -225,8 +226,7 @@ namespace wren { return obj; } catch (const std::runtime_error& err) { - set(vm, 1, err.what()); - vm.abort_fiber(1); + abort_fiber_with_error(vm, 1, err.what()); return nullptr; } } diff --git a/src/vm_fun.cpp b/src/vm_fun.cpp index bd76fc2..8efbd83 100644 --- a/src/vm_fun.cpp +++ b/src/vm_fun.cpp @@ -89,4 +89,9 @@ namespace wren { vm.ensure_slots(1); variable(vm, handle, slot); } + + void abort_fiber_with_error (VM& vm, int slot, std::string_view message) { + set(vm, slot, message); + vm.abort_fiber(slot); + } } //namespace wren