scripting language now has support for list and map literals: " [a,b,c] "

git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@422 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
twanvl
2007-06-14 14:25:53 +00:00
parent 6e55175f51
commit 40e55e8151
7 changed files with 73 additions and 11 deletions
+22
View File
@@ -101,6 +101,11 @@ ScriptValueP Context::eval(const Script& script, bool useScope) {
}
break;
}
// Make an object
case I_MAKE_OBJECT: {
makeObject(i.data);
break;
}
// Function call
case I_CALL: {
@@ -324,3 +329,20 @@ void instrTernary(TernaryInstructionType i, ScriptValueP& a, const ScriptValueP&
break;
}
}
// ----------------------------------------------------------------------------- : Simple instructions : object
void Context::makeObject(size_t n) {
intrusive_ptr<ScriptCustomCollection> ret(new ScriptCustomCollection());
size_t begin = stack.size() - 2 * n;
for (size_t i = 0 ; i < n ; ++i) {
const ScriptValueP& key = stack[begin + 2 * i];
const ScriptValueP& val = stack[begin + 2 * i + 1];
ret->value.push_back(val);
if (key != script_nil) { // valid key
ret->key_value[key->toString()] = val;
}
}
stack.resize(begin);
stack.push_back(ret);
}