Add overload for Handle

This commit is contained in:
King_DuckZ 2020-04-30 23:18:41 +02:00
parent 97514085cb
commit 4843ddd95e

View file

@ -33,6 +33,9 @@ namespace wren {
template <typename R, typename... Args>
R call (VM& vm, const ModuleAndName& object, const Handle& method, const Args&... args);
template <typename R, std::size_t N, typename... Args>
R call (VM& vm, const Handle& object, const char (&method)[N], const Args&... args);
template <typename R, std::size_t N, typename... Args>
R call (VM& vm, const ModuleAndName& object, const char (&method)[N], const Args&... args);
@ -165,7 +168,7 @@ namespace wren {
}
template <typename R, std::size_t N, typename... Args>
inline R call (VM& vm, const ModuleAndName& object, const char (&method)[N], const Args&... args) {
inline R call (VM& vm, const Handle& object, const char (&method)[N], const Args&... args) {
const constexpr char dummy_name_buff[N] = {0};
const constexpr auto params = dhandy::bt::string<N, char>(dummy_name_buff) +
dhandy::bt::make_string("(") +
@ -177,4 +180,12 @@ namespace wren {
std::copy(params.data() + N - 1, params.data() + params.size() + 1, cat_buff + N - 1);
return call<R, Args...>(vm, object, vm.make_call_handle(cat_buff), args...);
}
template <typename R, std::size_t N, typename... Args>
inline R call (VM& vm, const ModuleAndName& object, const char (&method)[N], const Args&... args) {
vm.ensure_slots(sizeof...(args) + 1);
variable(vm, object, 0);
Handle obj_handle = vm.slot_handle(0);
return call<R, N, Args...>(vm, obj_handle, method, args...);
}
} //namespace wren