diff --git a/src/wren/vm.cpp b/src/wren/vm.cpp index 706b569..64ab275 100644 --- a/src/wren/vm.cpp +++ b/src/wren/vm.cpp @@ -4,7 +4,6 @@ #include #include #include -#include namespace wren { namespace { @@ -182,6 +181,30 @@ namespace wren { return static_cast(slot(slot_num)); } + void VM::set (int slot_num, const std::string& value) { + wrenSetSlotString(m_local->wvm, slot_num, value.c_str()); + } + + void VM::set (int slot_num, const char* value) { + wrenSetSlotString(m_local->wvm, slot_num, value); + } + + void VM::set (int slot_num, double value) { + wrenSetSlotDouble(m_local->wvm, slot_num, value); + } + + void VM::set (int slot_num, bool value) { + wrenSetSlotBool(m_local->wvm, slot_num, value); + } + + void VM::set (int slot_num, const std::vector& value) { + wrenSetSlotBytes(m_local->wvm, slot_num, value.data(), value.size()); + } + + void VM::set (int slot_num, std::nullptr_t) { + wrenSetSlotNull(m_local->wvm, slot_num); + } + void VM::ensure_slots (int num_slots) { wrenEnsureSlots(m_local->wvm, num_slots); } diff --git a/src/wren/vm.hpp b/src/wren/vm.hpp index 52f7863..758afe8 100644 --- a/src/wren/vm.hpp +++ b/src/wren/vm.hpp @@ -10,6 +10,7 @@ #if __cpp_concepts >= 201907 # include #endif +#include namespace wren { class Configuration; @@ -62,6 +63,12 @@ namespace wren { void interpret (const std::string& module_name, const std::string& script); void release (Handle& handle) noexcept; template T slot (int slot_num); + void set (int slot_num, const std::string& value); + void set (int slot_num, const char* value); + void set (int slot_num, double value); + void set (int slot_num, bool value); + void set (int slot_num, const std::vector& value); + void set (int slot_num, std::nullptr_t); void ensure_slots(int num_slots); int slot_count(); void variable(const char* module, const char* name, int slot);