Add setters.

This commit is contained in:
King_DuckZ 2020-04-28 21:24:01 +02:00
parent ee587d0b9e
commit dafce95c8f
2 changed files with 31 additions and 1 deletions

View file

@ -4,7 +4,6 @@
#include <wren.hpp>
#include <cassert>
#include <stdexcept>
#include <vector>
namespace wren {
namespace {
@ -182,6 +181,30 @@ namespace wren {
return static_cast<int>(slot<double>(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<char>& 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);
}

View file

@ -10,6 +10,7 @@
#if __cpp_concepts >= 201907
# include <concepts>
#endif
#include <vector>
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 <typename T> 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<char>& 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);