summaryrefslogtreecommitdiff
path: root/threads.js
diff options
context:
space:
mode:
authorjmoenig <jens@moenig.org>2014-12-04 15:45:18 +0100
committerjmoenig <jens@moenig.org>2014-12-04 15:45:18 +0100
commitad1fe34d1ed900e1e4fd75e5c5666f6ab28b9c80 (patch)
tree07a26fe13d14f44bc2cff96e493db77b1a026cce /threads.js
parent17b6ae839b5c15c942440f38fc07bfcc45bc0811 (diff)
downloadsnap-byow-ad1fe34d1ed900e1e4fd75e5c5666f6ab28b9c80.tar.gz
snap-byow-ad1fe34d1ed900e1e4fd75e5c5666f6ab28b9c80.zip
Experimental “ForEach” primitive (hidden in dev mode)
Diffstat (limited to 'threads.js')
-rw-r--r--threads.js22
1 files changed, 21 insertions, 1 deletions
diff --git a/threads.js b/threads.js
index 9f9a221..c21375e 100644
--- a/threads.js
+++ b/threads.js
@@ -83,7 +83,7 @@ ArgLabelMorph, localize, XML_Element, hex_sha512*/
// Global stuff ////////////////////////////////////////////////////////
-modules.threads = '2014-December-03';
+modules.threads = '2014-December-04';
var ThreadManager;
var Process;
@@ -1679,6 +1679,26 @@ Process.prototype.reportMap = function (reporter, list) {
}
};
+Process.prototype.doForEach = function (upvar, list, script) {
+ // perform a script for each element of a list, assigning the
+ // current iteration's element to a variable with the name
+ // specified in the "upvar" parameter, so it can be referenced
+ // within the script. Uses the context's - unused - fourth
+ // element as temporary storage for the current list index
+
+ if (isNil(this.context.inputs[3])) {this.context.inputs[3] = 1; }
+ var index = this.context.inputs[3];
+ this.context.outerContext.variables.addVar(upvar);
+ this.context.outerContext.variables.setVar(
+ upvar,
+ list.at(index)
+ );
+ if (index > list.length()) {return; }
+ this.context.inputs[3] += 1;
+ this.pushContext();
+ this.evaluate(script, new List(), true);
+};
+
// Process interpolated primitives
Process.prototype.doWait = function (secs) {