summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjmoenig <jens@moenig.org>2014-07-25 14:35:36 +0200
committerjmoenig <jens@moenig.org>2014-07-25 14:35:36 +0200
commit3aae7c3ce478c3d5ba5cb716a67bf117d0a48a84 (patch)
treea31b7e799bf8eb7b60fbf46b689856899ab62778
parent54fec68d787f385f87683df5011bbcec8f0c3f77 (diff)
downloadsnap-3aae7c3ce478c3d5ba5cb716a67bf117d0a48a84.tar.gz
snap-3aae7c3ce478c3d5ba5cb716a67bf117d0a48a84.zip
new “JavaScript function” primitive
Go figure…
-rwxr-xr-xhistory.txt4
-rw-r--r--objects.js11
-rw-r--r--threads.js12
3 files changed, 25 insertions, 2 deletions
diff --git a/history.txt b/history.txt
index 9f21f79..f233284 100755
--- a/history.txt
+++ b/history.txt
@@ -2228,3 +2228,7 @@ ______
* Objects: fixed “lost sprites bug” - ensure duplicated sprites keep wearing their current costume through save and re-load
* GUI, Objects: improve unique sprite- and costume names
* Threads: Display “empty” Contexts (e.g. continuations) as empty rings
+
+140725
+------
+* Objects, Threads: new “JavaScript function” primitive. Go figure…
diff --git a/objects.js b/objects.js
index 2b04eb4..f9908ef 100644
--- a/objects.js
+++ b/objects.js
@@ -125,7 +125,7 @@ PrototypeHatBlockMorph*/
// Global stuff ////////////////////////////////////////////////////////
-modules.objects = '2014-July-24';
+modules.objects = '2014-July-25';
var SpriteMorph;
var StageMorph;
@@ -1024,6 +1024,11 @@ SpriteMorph.prototype.initBlocks = function () {
spec: 'split %s by %delim',
defaults: [localize('hello') + ' ' + localize('world'), " "]
},
+ reportJSFunction: { // experimental
+ type: 'reporter',
+ category: 'operators',
+ spec: 'JavaScript function ( %mult%s ) { %code }'
+ },
reportTypeOf: { // only in dev mode for debugging
dev: true,
type: 'reporter',
@@ -1919,6 +1924,8 @@ SpriteMorph.prototype.blockTemplates = function (category) {
blocks.push('-');
blocks.push(block('reportIsA'));
blocks.push(block('reportIsIdentical'));
+ blocks.push('-');
+ blocks.push(block('reportJSFunction'));
// for debugging: ///////////////
@@ -5000,6 +5007,8 @@ StageMorph.prototype.blockTemplates = function (category) {
blocks.push('-');
blocks.push(block('reportIsA'));
blocks.push(block('reportIsIdentical'));
+ blocks.push('-');
+ blocks.push(block('reportJSFunction'));
// for debugging: ///////////////
diff --git a/threads.js b/threads.js
index 06beebc..d72d36a 100644
--- a/threads.js
+++ b/threads.js
@@ -83,7 +83,7 @@ ArgLabelMorph, localize, XML_Element, hex_sha512*/
// Global stuff ////////////////////////////////////////////////////////
-modules.threads = '2014-July-24';
+modules.threads = '2014-July-25';
var ThreadManager;
var Process;
@@ -741,6 +741,13 @@ Process.prototype.reifyPredicate = function (topBlock, parameterNames) {
return this.reify(topBlock, parameterNames);
};
+Process.prototype.reportJSFunction = function (parmNames, body) {
+ return Function.apply(
+ Object.create(Function.prototype),
+ parmNames.asArray().concat([body])
+ );
+};
+
Process.prototype.doRun = function (context, args, isCustomBlock) {
return this.evaluate(context, args, true, isCustomBlock);
};
@@ -751,6 +758,9 @@ Process.prototype.evaluate = function (
isCommand
) {
if (!context) {return null; }
+ if (context instanceof Function) {
+ return context.apply(this.homeContext.receiver, args.asArray());
+ }
if (context.isContinuation) {
return this.runContinuation(context, args);
}