From b5bf777a053dd8a109ed0ba4bb466dcda92d4aa5 Mon Sep 17 00:00:00 2001 From: King_DuckZ Date: Tue, 28 Apr 2020 15:15:53 +0200 Subject: [PATCH] Allow getting variables by handle --- src/wren/vm.cpp | 8 ++++++++ src/wren/vm.hpp | 28 ++++++++++++---------------- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/src/wren/vm.cpp b/src/wren/vm.cpp index e8bb3d5..6a4283b 100644 --- a/src/wren/vm.cpp +++ b/src/wren/vm.cpp @@ -187,6 +187,14 @@ namespace wren { wrenGetVariable(m_local->wvm, module, name, slot); } + void VM::variable(const ModuleAndName& mod_and_name, int slot) { + this->variable(std::get<0>(mod_and_name), std::get<1>(mod_and_name), slot); + } + + void VM::variable (const Handle& handle, int slot) { + wrenSetSlotHandle(m_local->wvm, slot, handle); + } + template bool VM::slot(int); template std::string VM::slot(int); template double VM::slot(int); diff --git a/src/wren/vm.hpp b/src/wren/vm.hpp index 17af447..cde1b46 100644 --- a/src/wren/vm.hpp +++ b/src/wren/vm.hpp @@ -42,7 +42,11 @@ namespace wren { }; #if __cpp_concepts >= 201907 - template concept ConstCharTuple = std::same_as, ModuleAndName>; + template + concept ConstCharTuple = requires { + std::same_as, Handle> or + std::same_as, ModuleAndName>; + }; #endif } //namespace detail @@ -65,10 +69,11 @@ namespace wren { template #endif std::tuple variables(Params&&... modules_names); - //template std::tuple variables(const Handle& handle); void ensure_slots(int num_slots); void variable(const char* module, const char* name, int slot); + void variable(const ModuleAndName& mod_and_name, int slot); + void variable(const Handle& handle, int slot); private: struct LocalData; @@ -84,7 +89,7 @@ namespace wren { #else template #endif - std::tuple get_variables_impl (std::integer_sequence, Params&&... modules_names); + std::tuple variables_impl (std::integer_sequence, Params&&... modules_names); std::unique_ptr m_local; }; @@ -161,7 +166,7 @@ namespace wren { template #endif std::tuple VM::variables(Params&&... modules_names) { - return get_variables_impl(std::make_integer_sequence(), std::forward(modules_names)...); + return variables_impl(std::make_integer_sequence(), std::forward(modules_names)...); } #if __cpp_concepts >= 201907 @@ -169,7 +174,7 @@ namespace wren { #else template #endif - inline std::tuple VM::get_variables_impl ( + inline std::tuple VM::variables_impl ( std::integer_sequence, Params&&... modules_names ) { @@ -177,21 +182,12 @@ namespace wren { return {}; } else { - using std::get; - using std::tuple; - static_assert(sizeof...(Params) == sizeof...(Outs), "Expected a module/name pair per requested output"); static_assert(sizeof...(Outs) == sizeof...(Indices), "Mismatching index count"); ensure_slots(sizeof...(Outs)); - (this->variable(get<0>(modules_names), get<1>(modules_names), Indices), ...); - return tuple(this->slot(Indices)...); + (this->variable(modules_names, Indices), ...); + return std::tuple(this->slot(Indices)...); } } - - //template - //inline std::tuple VM::variables(const Handle& handle) { - // if constexpr (sizeof...(Args) == 0) - // return {}; - //} } //namespace wren