Set slot in case caller didn't, or else why we get the object parameter?

This commit is contained in:
King_DuckZ 2022-04-22 01:05:11 +02:00
parent 839dbccfb1
commit b4383e9449

View file

@ -142,6 +142,9 @@ namespace wren {
variable(vm, name, slot_num);
}
//Sets arguments so wren is ready to perform a function call. It doesn't
//touch at slot 0, so eventual objects for method calls must be set
//manually
template <typename... Args, int... Indices>
inline void set_for_call (std::integer_sequence<int, Indices...>, VM& vm, const Args&... args) {
vm.ensure_slots(sizeof...(Args));
@ -248,6 +251,7 @@ namespace wren {
template <typename R, typename... Args>
inline R call (VM& vm, const Handle& object, const Handle& method, const Args&... args) {
detail::set_for_call<Args...>(std::make_integer_sequence<int, sizeof...(Args)>(), vm, args...);
vm.set_slot_handle(object, 0);
vm.call(method);
if constexpr (not std::is_same<void, R>::value) {
return get<R>(vm, 0);