Allow getting variables by handle
This commit is contained in:
parent
59140c6c4b
commit
b5bf777a05
2 changed files with 20 additions and 16 deletions
|
@ -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<bool>(int);
|
||||
template std::string VM::slot<std::string>(int);
|
||||
template double VM::slot<double>(int);
|
||||
|
|
|
@ -42,7 +42,11 @@ namespace wren {
|
|||
};
|
||||
|
||||
#if __cpp_concepts >= 201907
|
||||
template <typename T> concept ConstCharTuple = std::same_as<std::remove_cv_t<T>, ModuleAndName>;
|
||||
template <typename T>
|
||||
concept ConstCharTuple = requires {
|
||||
std::same_as<std::remove_cv_t<T>, Handle> or
|
||||
std::same_as<std::remove_cv_t<T>, ModuleAndName>;
|
||||
};
|
||||
#endif
|
||||
} //namespace detail
|
||||
|
||||
|
@ -65,10 +69,11 @@ namespace wren {
|
|||
template <typename... Outs, typename... Params>
|
||||
#endif
|
||||
std::tuple<Outs...> variables(Params&&... modules_names);
|
||||
//template <typename... Args> std::tuple<Args...> 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 <typename... Outs, int... Indices, typename... Params>
|
||||
#endif
|
||||
std::tuple<Outs...> get_variables_impl (std::integer_sequence<int, Indices...>, Params&&... modules_names);
|
||||
std::tuple<Outs...> variables_impl (std::integer_sequence<int, Indices...>, Params&&... modules_names);
|
||||
|
||||
std::unique_ptr<LocalData> m_local;
|
||||
};
|
||||
|
@ -161,7 +166,7 @@ namespace wren {
|
|||
template <typename... Outs, typename... Params>
|
||||
#endif
|
||||
std::tuple<Outs...> VM::variables(Params&&... modules_names) {
|
||||
return get_variables_impl<Outs...>(std::make_integer_sequence<int, sizeof...(Outs)>(), std::forward<Params>(modules_names)...);
|
||||
return variables_impl<Outs...>(std::make_integer_sequence<int, sizeof...(Outs)>(), std::forward<Params>(modules_names)...);
|
||||
}
|
||||
|
||||
#if __cpp_concepts >= 201907
|
||||
|
@ -169,7 +174,7 @@ namespace wren {
|
|||
#else
|
||||
template <typename... Outs, int... Indices, typename... Params>
|
||||
#endif
|
||||
inline std::tuple<Outs...> VM::get_variables_impl (
|
||||
inline std::tuple<Outs...> VM::variables_impl (
|
||||
std::integer_sequence<int, Indices...>,
|
||||
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<Outs...>(this->slot<Outs>(Indices)...);
|
||||
(this->variable(modules_names, Indices), ...);
|
||||
return std::tuple<Outs...>(this->slot<Outs>(Indices)...);
|
||||
}
|
||||
}
|
||||
|
||||
//template <typename... Args>
|
||||
//inline std::tuple<Args...> VM::variables(const Handle& handle) {
|
||||
// if constexpr (sizeof...(Args) == 0)
|
||||
// return {};
|
||||
//}
|
||||
} //namespace wren
|
||||
|
|
Loading…
Reference in a new issue