Skip to content

Commit

Permalink
fixed input names when querying a custom block definition that has no…
Browse files Browse the repository at this point in the history
… function body script
  • Loading branch information
jmoenig committed Nov 12, 2024
1 parent 02039c1 commit 8f0e904
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 16 deletions.
5 changes: 5 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
* new "input slots" menu option for custom block input slots
* **Notable Changes:**
* automatically add a dropdown menu to any custom block input slot whose definition has a slot menu event hat block for it
* **Notable Fixes:**
* fixed input names when querying a custom block definition that has no function body script

### 2024-11-12
* threads: fixed input names when querying a custom block definition that has no function body script

### 2024-11-11
* threads: expose a copy of the custom block as "caller" to input slot reaction scripts inside custom block definitions
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-11"></script>
<script src="src/threads.js?version=2024-11-11"></script>
<script src="src/threads.js?version=2024-11-12"></script>
<script src="src/objects.js?version=2024-11-10"></script>
<script src="src/scenes.js?version=2024-05-28"></script>
<script src="src/gui.js?version=2024-11-10"></script>
Expand Down
35 changes: 20 additions & 15 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-11';
modules.threads = '2024-November-12';

var ThreadManager;
var Process;
Expand Down Expand Up @@ -7972,19 +7972,24 @@ Process.prototype.reportBasicBlockAttribute = function (attribute, block) {
case 'definition':
if (expr.isCustomBlock) {
if (expr.isGlobal) {
if (expr.definition.primitive && !expr.definition.body) {
def = expr.definition;
if (def.primitive && !def.body) {
prim = SpriteMorph.prototype.blockForSelector(
'doPrimitive'
);
prim.inputs()[0].setContents(true);
prim.inputs()[1].setContents(expr.definition.primitive);
prim.inputs()[1].setContents(def.primitive);
body = prim.reify();
} else {
body = expr.definition.body || new Context();
}
} else {
body = this.blockReceiver().getMethod(expr.semanticSpec).body ||
new Context();
def = this.blockReceiver().getMethod(expr.semanticSpec);
}
if (!body) {
body = def.body;
if (!body) {
body = new Context();
def.inputNames().forEach(name => body.addInput(name));
}
}
} else {
prim = SpriteMorph.prototype.blocks[expr.selector].src;
Expand All @@ -7997,14 +8002,14 @@ Process.prototype.reportBasicBlockAttribute = function (attribute, block) {
prim.inputs()[1].setContents(expr.selector);
body = prim.reify();
}
}
if (body instanceof Context &&
(!body.expression || prim) &&
!body.inputs.length
) {
// make sure the definition has the same number of inputs as the
// block prototype (i.e. the header)
expr.inputs().forEach((inp, i) => body.addInput('#' + (i + 1)));
if (body instanceof Context &&
(!body.expression || prim) &&
!body.inputs.length
) {
// make sure the definition has the same number of inputs as the
// block prototype (i.e. the header)
expr.inputs().forEach((inp, i) => body.addInput('#' + (i + 1)));
}
}
if (body.expression && body.expression.selector === 'doReport' &&
body.expression.inputs()[0] instanceof BlockMorph) {
Expand Down

0 comments on commit 8f0e904

Please sign in to comment.