From 2d77f50491fb2bb789ffbc1e417846a0fa7728c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jens=20M=C3=B6nig?= Date: Sat, 9 Nov 2024 23:07:50 +0100 Subject: [PATCH] enhanced "set slot ... to ..." command to also handle variadic inputs, setting them to a list of values --- HISTORY.md | 3 +++ snap.html | 2 +- src/threads.js | 17 +++++++++++++++-- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index d571ceeb3..5189fefeb 100755 --- a/HISTORY.md +++ b/HISTORY.md @@ -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 diff --git a/snap.html b/snap.html index 9e8729ac5..26ba8ee9c 100755 --- a/snap.html +++ b/snap.html @@ -17,7 +17,7 @@ - + diff --git a/src/threads.js b/src/threads.js index 98d201bef..b233d3fbd 100644 --- a/src/threads.js +++ b/src/threads.js @@ -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; @@ -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; } @@ -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); + } + }); } } };