From ebd455c5364ced43d5db46baa584e282fab97be1 Mon Sep 17 00:00:00 2001 From: King_DuckZ Date: Sun, 26 Apr 2020 10:56:28 +0200 Subject: [PATCH] Make code a bit shorter --- src/wren/vm.hpp | 36 +++++++++++------------------------- 1 file changed, 11 insertions(+), 25 deletions(-) diff --git a/src/wren/vm.hpp b/src/wren/vm.hpp index 4394175..d46c59e 100644 --- a/src/wren/vm.hpp +++ b/src/wren/vm.hpp @@ -14,14 +14,14 @@ namespace wren { namespace detail { struct Callbacks { - void (*write_fn)(Configuration&, VM*, const char*); - void (*error_fn)(Configuration&, VM*, ErrorType, const char*, int, const char*); - void* (*reallocate_fn)(void*, std::size_t); - const char* (*resolve_module_fn)(Configuration&, VM*, const char*, const char*); - char* (*load_module_fn)(Configuration&, VM*, const char*); + void (*write_fn)(Configuration&, VM*, const char*) {nullptr}; + void (*error_fn)(Configuration&, VM*, ErrorType, const char*, int, const char*) {nullptr}; + void* (*reallocate_fn)(void*, std::size_t) {nullptr}; + const char* (*resolve_module_fn)(Configuration&, VM*, const char*, const char*) {nullptr}; + char* (*load_module_fn)(Configuration&, VM*, const char*) {nullptr}; - Configuration* config_obj; - VM* vm; + Configuration* config_obj {nullptr}; + VM* vm {nullptr}; }; } //namespace detail @@ -72,41 +72,27 @@ namespace wren { template inline detail::Callbacks VM::to_callbacks (T& conf) { - using detail::method_write; - using detail::method_error; using detail::method_reallocate; - using detail::method_resolve_module; - using detail::method_load_module; detail::Callbacks ret; ret.config_obj = &conf; ret.vm = this; - if constexpr (method_write::exists::value) + if constexpr (detail::method_write::exists::value) ret.write_fn = &detail::AnyFunctionWrap::template call<&T::write_fn>; - else - ret.write_fn = nullptr; - if constexpr (method_error::exists::value) + if constexpr (detail::method_error::exists::value) ret.error_fn = &detail::AnyFunctionWrap::template call<&T::error_fn>; - else - ret.error_fn = nullptr; if constexpr (method_reallocate::exists::value and method_reallocate::is_static::value) ret.reallocate_fn = &T::reallocate_fn; - else - ret.reallocate_fn = nullptr; static_assert(not method_reallocate::exists::value or method_reallocate::is_static::value, "Realloc function must be a static function"); - if constexpr (method_resolve_module::exists::value) + if constexpr (detail::method_resolve_module::exists::value) ret.resolve_module_fn = &detail::AnyFunctionWrap::template call<&T::resolve_module_fn>; - else - ret.resolve_module_fn = nullptr; - if constexpr (method_load_module::exists::value) + if constexpr (detail::method_load_module::exists::value) ret.load_module_fn = &detail::AnyFunctionWrap::template call<&T::load_module_fn>; - else - ret.load_module_fn = nullptr; return ret; }