Add variables() method and supporting code.
This commit is contained in:
parent
0d0ea0a0cc
commit
67a5fab3c4
2 changed files with 103 additions and 0 deletions
|
@ -68,6 +68,17 @@ namespace wren {
|
|||
retval.finalize = funcs.finalize;
|
||||
return retval;
|
||||
}
|
||||
|
||||
template <typename T> T slot_specialized (WrenVM* vm, int slot_num);
|
||||
template <> bool slot_specialized (WrenVM* vm, int slot_num) {
|
||||
return wrenGetSlotBool(vm, slot_num);
|
||||
}
|
||||
template <> std::string slot_specialized (WrenVM* vm, int slot_num) {
|
||||
return wrenGetSlotString(vm, slot_num);
|
||||
}
|
||||
template <> double slot_specialized (WrenVM* vm, int slot_num) {
|
||||
return wrenGetSlotDouble(vm, slot_num);
|
||||
}
|
||||
} //unnamed namespace
|
||||
|
||||
struct VM::LocalData {
|
||||
|
@ -152,4 +163,27 @@ namespace wren {
|
|||
void VM::interpret (const std::string& module_name, const std::string& script) {
|
||||
return interpret(module_name.c_str(), script.c_str());
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T VM::slot (int slot_num) {
|
||||
return slot_specialized<T>(m_local->wvm, slot_num);
|
||||
}
|
||||
|
||||
template <>
|
||||
int VM::slot (int slot_num) {
|
||||
return static_cast<int>(slot<double>(slot_num));
|
||||
}
|
||||
|
||||
void VM::ensure_slots (int num_slots) {
|
||||
wrenEnsureSlots(m_local->wvm, num_slots);
|
||||
}
|
||||
|
||||
void VM::variable(const char* module, const char* name, int slot) {
|
||||
wrenGetVariable(m_local->wvm, module, name, slot);
|
||||
}
|
||||
|
||||
template bool VM::slot<bool>(int);
|
||||
template std::string VM::slot<std::string>(int);
|
||||
template double VM::slot<double>(int);
|
||||
template int VM::slot<int>(int);
|
||||
} //namespace wren
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue