diff options
| author | Gubolin <gubolin@fantasymail.de> | 2015-03-24 18:29:54 +0100 |
|---|---|---|
| committer | Gubolin <gubolin@fantasymail.de> | 2015-03-24 18:29:54 +0100 |
| commit | bdd780e0030507626c947f85880a9eaa36e24194 (patch) | |
| tree | 070a36fee08b43b5e231b2a1e8e5fe28314a7cb8 /threads.js | |
| parent | c8de6a00e38e52bfc4b9b3a095cbcad1861687de (diff) | |
| parent | 457224dd620eea4f20f24ebc62391363333cd00f (diff) | |
| download | snap-bdd780e0030507626c947f85880a9eaa36e24194.tar.gz snap-bdd780e0030507626c947f85880a9eaa36e24194.zip | |
merge branch OOP
Diffstat (limited to 'threads.js')
| -rw-r--r-- | threads.js | 78 |
1 files changed, 55 insertions, 23 deletions
@@ -83,7 +83,7 @@ ArgLabelMorph, localize, XML_Element, hex_sha512*/ // Global stuff //////////////////////////////////////////////////////// -modules.threads = '2015-February-28'; +modules.threads = '2015-March-23'; var ThreadManager; var Process; @@ -1184,7 +1184,7 @@ Process.prototype.doSetVar = function (varName, value) { name = name.expression.blockSpec; } } - varFrame.setVar(name, value); + varFrame.setVar(name, value, this.blockReceiver()); }; Process.prototype.doChangeVar = function (varName, value) { @@ -1196,7 +1196,7 @@ Process.prototype.doChangeVar = function (varName, value) { name = name.expression.blockSpec; } } - varFrame.changeVar(name, value); + varFrame.changeVar(name, value, this.blockReceiver()); }; Process.prototype.reportGetVar = function () { @@ -1241,7 +1241,7 @@ Process.prototype.doShowVar = function (varName) { } // if no watcher exists, create a new one isGlobal = contains( - this.homeContext.receiver.variables.parentFrame.names(), + this.homeContext.receiver.globalVariables().names(), varName ); if (isGlobal || target.owner) { @@ -1370,6 +1370,23 @@ Process.prototype.reportPeerId = function () { return stage.peerId; }; +// Process sprite inheritance primitives + +Process.prototype.doDeleteAttr = function (attrName) { + // currently only variables are deletable + var name = attrName, + rcvr = this.blockReceiver(); + + if (name instanceof Context) { + if (name.expression.selector === 'reportGetVar') { + name = name.expression.blockSpec; + } + } + if (contains(rcvr.inheritedVariableNames(true), name)) { + rcvr.deleteVariable(name); + } +}; + // Process lists primitives Process.prototype.reportNewList = function (elements) { @@ -3624,35 +3641,50 @@ VariableFrame.prototype.silentFind = function (name) { return null; }; -VariableFrame.prototype.setVar = function (name, value) { -/* - change the specified variable if it exists - else throw an error, because variables need to be - declared explicitly (e.g. through a "script variables" block), - before they can be accessed. -*/ +VariableFrame.prototype.setVar = function (name, value, sender) { + // change the specified variable if it exists + // else throw an error, because variables need to be + // declared explicitly (e.g. through a "script variables" block), + // before they can be accessed. + // if the found frame is inherited by the sender sprite + // shadow it (create an explicit one for the sender) + // before setting the value ("create-on-write") + var frame = this.find(name); if (frame) { - frame.vars[name].value = value; + if (sender instanceof SpriteMorph && + (frame.owner instanceof SpriteMorph) && + (sender !== frame.owner)) { + sender.shadowVar(name, value); + } else { + frame.vars[name].value = value; + } } }; -VariableFrame.prototype.changeVar = function (name, delta) { -/* - change the specified variable if it exists - else throw an error, because variables need to be - declared explicitly (e.g. through a "script variables" block, - before they can be accessed. -*/ +VariableFrame.prototype.changeVar = function (name, delta, sender) { + // change the specified variable if it exists + // else throw an error, because variables need to be + // declared explicitly (e.g. through a "script variables" block, + // before they can be accessed. + // if the found frame is inherited by the sender sprite + // shadow it (create an explicit one for the sender) + // before changing the value ("create-on-write") + var frame = this.find(name), - value; + value, + newValue; if (frame) { value = parseFloat(frame.vars[name].value); - if (isNaN(value)) { - frame.vars[name].value = delta; + newValue = isNaN(value) ? delta : value + parseFloat(delta); + if (sender instanceof SpriteMorph && + (frame.owner instanceof SpriteMorph) && + (sender !== frame.owner)) { + sender.shadowVar(name, newValue); } else { - frame.vars[name].value = value + parseFloat(delta); + frame.vars[name].value = newValue; } + } }; |
