Skip to content

Commit

Permalink
set multidimensional array
Browse files Browse the repository at this point in the history
  • Loading branch information
dfabulich committed Jul 19, 2015
1 parent 7cbbd36 commit ce4893b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
6 changes: 6 additions & 0 deletions tests/scenetest.js
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,12 @@ test("setArray", function() {
scene.execute();
doh.is(2, scene.temps.foo_1, "scene.temps.foo_1");
})
test("setMultidimensionalArray", function() {
var scene = new Scene();
scene.loadLines("*temp foo \"foo\"\n*temp foo_1_1 0\n*set foo[1][1] 2");
scene.execute();
doh.is(2, scene.temps.foo_1_1, "scene.temps.foo_1_1");
})
test("errorSetRefNoExpression", function() {
var scene = new Scene();
scene.loadLines("*temp foo 0\n*temp bar 0\n*set foo \"bar\"\n*setref foo");
Expand Down
16 changes: 7 additions & 9 deletions web/scene.js
Original file line number Diff line number Diff line change
Expand Up @@ -3108,18 +3108,16 @@ Scene.prototype.evaluateReference = function evaluateReference(stack, options) {
return name;
} else {
if (stack[0].name !== "VAR") throw new Error(this.lineMsg() + "Invalid expression; expected name, found " + stack[0].name + " at char " + stack[0].pos);
if (stack.length > 1 && stack[1].name === "OPEN_SQUARE") {
var closingBracket = findClosingBracket(stack, "SQUARE", 2);
name = String(stack[0].value);
stack.shift();
while(stack.length && stack[0].name == "OPEN_SQUARE") {
var closingBracket = findClosingBracket(stack, "SQUARE", 1);
if (closingBracket == -1) throw new Error(this.lineMsg()+"Invalid expression, no closing array bracket at char " + stack[1].pos);
var index = this.evaluateExpr(stack.slice(2, closingBracket));
name = String(stack[0].value) + "_" + index;
var index = this.evaluateExpr(stack.slice(1, closingBracket));
name += "_" + index;
stack.splice(0, closingBracket+1);
return normalizeCase(name);
} else {
name = stack[0].value;
stack.shift();
return normalizeCase(name);
}
return normalizeCase(name);
}
};

Expand Down

0 comments on commit ce4893b

Please sign in to comment.