Skip to content

Commit

Permalink
enhanced "set slot ... to ..." command to also handle variadic inputs…
Browse files Browse the repository at this point in the history
…, setting them to a list of values
  • Loading branch information
jmoenig committed Nov 9, 2024
1 parent a158c27 commit 2d77f50
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
3 changes: 3 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## in development:

### 2024-11-09
* threads: enhanced "set slot ... to ..." command to also handle variadic inputs, setting them to a list of values

## 10.2.0:
* **New Features:**
1. Block instance scripting
Expand Down
2 changes: 1 addition & 1 deletion snap.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<script src="src/symbols.js?version=2024-09-13"></script>
<script src="src/widgets.js?version=2024-07-24"></script>
<script src="src/blocks.js?version=2024-11-08"></script>
<script src="src/threads.js?version=2024-11-07"></script>
<script src="src/threads.js?version=2024-11-09"></script>
<script src="src/objects.js?version=2024-11-07"></script>
<script src="src/scenes.js?version=2024-05-28"></script>
<script src="src/gui.js?version=2024-11-08"></script>
Expand Down
17 changes: 15 additions & 2 deletions src/threads.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ StagePickerMorph, CustomBlockDefinition, CommentMorph, BooleanSlotMorph*/

/*jshint esversion: 11, bitwise: false, evil: true*/

modules.threads = '2024-November-07';
modules.threads = '2024-November-09';

var ThreadManager;
var Process;
Expand Down Expand Up @@ -1734,7 +1734,7 @@ Process.prototype.reportData = function (trgt) {

Process.prototype.doSetSlot = function(name, value) {
var sym = Symbol.for('block'),
frame, block, slot;
frame, block, slot, subslots;
if (!name) {return; }
frame = this.context.variables.silentFind(sym);
if (!frame) {return; }
Expand All @@ -1745,6 +1745,19 @@ Process.prototype.doSetSlot = function(name, value) {
slot.setContents(value.toString());
} else if (slot instanceof BooleanSlotMorph) {
slot.setContents(value);
} else if (slot instanceof MultiArgMorph) {
if (!(value instanceof List)) {
value = new List([value]);
}
slot.expandTo(value.length());
subslots = slot.inputs();
value.itemsArray().forEach((item, i) => {
if (subslots[i] instanceof InputSlotMorph) {
subslots[i].setContents(item.toString());
} else if (subslots[i] instanceof BooleanSlotMorph) {
subslots[i].setContents(item);
}
});
}
}
};
Expand Down

0 comments on commit 2d77f50

Please sign in to comment.