Make code a bit shorter
This commit is contained in:
parent
30975c1405
commit
ebd455c536
1 changed files with 11 additions and 25 deletions
|
@ -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 <typename T>
|
||||
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<T>::value)
|
||||
if constexpr (detail::method_write::exists<T>::value)
|
||||
ret.write_fn = &detail::AnyFunctionWrap<T, decltype(&T::write_fn)>::template call<&T::write_fn>;
|
||||
else
|
||||
ret.write_fn = nullptr;
|
||||
|
||||
if constexpr (method_error::exists<T>::value)
|
||||
if constexpr (detail::method_error::exists<T>::value)
|
||||
ret.error_fn = &detail::AnyFunctionWrap<T, decltype(&T::error_fn)>::template call<&T::error_fn>;
|
||||
else
|
||||
ret.error_fn = nullptr;
|
||||
|
||||
if constexpr (method_reallocate::exists<T>::value and method_reallocate::is_static<T>::value)
|
||||
ret.reallocate_fn = &T::reallocate_fn;
|
||||
else
|
||||
ret.reallocate_fn = nullptr;
|
||||
static_assert(not method_reallocate::exists<T>::value or method_reallocate::is_static<T>::value, "Realloc function must be a static function");
|
||||
|
||||
if constexpr (method_resolve_module::exists<T>::value)
|
||||
if constexpr (detail::method_resolve_module::exists<T>::value)
|
||||
ret.resolve_module_fn = &detail::AnyFunctionWrap<T, decltype(&T::resolve_module_fn)>::template call<&T::resolve_module_fn>;
|
||||
else
|
||||
ret.resolve_module_fn = nullptr;
|
||||
|
||||
if constexpr (method_load_module::exists<T>::value)
|
||||
if constexpr (detail::method_load_module::exists<T>::value)
|
||||
ret.load_module_fn = &detail::AnyFunctionWrap<T, decltype(&T::load_module_fn)>::template call<&T::load_module_fn>;
|
||||
else
|
||||
ret.load_module_fn = nullptr;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue