Change variables() into a free function.
This commit is contained in:
parent
b5bf777a05
commit
2122cb628d
1 changed files with 25 additions and 32 deletions
|
@ -61,15 +61,7 @@ namespace wren {
|
||||||
void interpret (const char* module_name, const char* script);
|
void interpret (const char* module_name, const char* script);
|
||||||
void interpret (const std::string& module_name, const std::string& script);
|
void interpret (const std::string& module_name, const std::string& script);
|
||||||
void release (Handle& handle) noexcept;
|
void release (Handle& handle) noexcept;
|
||||||
|
|
||||||
template <typename T> T slot (int slot_num);
|
template <typename T> T slot (int slot_num);
|
||||||
#if __cpp_concepts >= 201907
|
|
||||||
template <typename... Outs, detail::ConstCharTuple... Params>
|
|
||||||
#else
|
|
||||||
template <typename... Outs, typename... Params>
|
|
||||||
#endif
|
|
||||||
std::tuple<Outs...> variables(Params&&... modules_names);
|
|
||||||
|
|
||||||
void ensure_slots(int num_slots);
|
void ensure_slots(int num_slots);
|
||||||
void variable(const char* module, const char* name, int slot);
|
void variable(const char* module, const char* name, int slot);
|
||||||
void variable(const ModuleAndName& mod_and_name, int slot);
|
void variable(const ModuleAndName& mod_and_name, int slot);
|
||||||
|
@ -118,6 +110,29 @@ namespace wren {
|
||||||
return (*M)(args...);
|
return (*M)(args...);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#if __cpp_concepts >= 201907
|
||||||
|
template <typename... Outs, int... Indices, ConstCharTuple... Params>
|
||||||
|
#else
|
||||||
|
template <typename... Outs, int... Indices, typename... Params>
|
||||||
|
#endif
|
||||||
|
inline std::tuple<Outs...> variables_impl (
|
||||||
|
VM& vm,
|
||||||
|
std::integer_sequence<int, Indices...>,
|
||||||
|
Params&&... modules_names
|
||||||
|
) {
|
||||||
|
if constexpr (sizeof...(Outs) == 0) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
static_assert(sizeof...(Params) == sizeof...(Outs), "Expected a module/name pair per requested output");
|
||||||
|
static_assert(sizeof...(Outs) == sizeof...(Indices), "Mismatching index count");
|
||||||
|
|
||||||
|
vm.ensure_slots(sizeof...(Outs));
|
||||||
|
(vm.variable(modules_names, Indices), ...);
|
||||||
|
return std::tuple<Outs...>(vm.slot<Outs>(Indices)...);
|
||||||
|
}
|
||||||
|
}
|
||||||
} //namespace detail
|
} //namespace detail
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
|
@ -165,29 +180,7 @@ namespace wren {
|
||||||
#else
|
#else
|
||||||
template <typename... Outs, typename... Params>
|
template <typename... Outs, typename... Params>
|
||||||
#endif
|
#endif
|
||||||
std::tuple<Outs...> VM::variables(Params&&... modules_names) {
|
std::tuple<Outs...> variables(VM& vm, Params&&... modules_names) {
|
||||||
return variables_impl<Outs...>(std::make_integer_sequence<int, sizeof...(Outs)>(), std::forward<Params>(modules_names)...);
|
return detail::variables_impl<Outs...>(vm, std::make_integer_sequence<int, sizeof...(Outs)>(), std::forward<Params>(modules_names)...);
|
||||||
}
|
|
||||||
|
|
||||||
#if __cpp_concepts >= 201907
|
|
||||||
template <typename... Outs, int... Indices, detail::ConstCharTuple... Params>
|
|
||||||
#else
|
|
||||||
template <typename... Outs, int... Indices, typename... Params>
|
|
||||||
#endif
|
|
||||||
inline std::tuple<Outs...> VM::variables_impl (
|
|
||||||
std::integer_sequence<int, Indices...>,
|
|
||||||
Params&&... modules_names
|
|
||||||
) {
|
|
||||||
if constexpr (sizeof...(Outs) == 0) {
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
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(modules_names, Indices), ...);
|
|
||||||
return std::tuple<Outs...>(this->slot<Outs>(Indices)...);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} //namespace wren
|
} //namespace wren
|
||||||
|
|
Loading…
Add table
Reference in a new issue