update an existing global definition matching DEFINE's label

snap8
Jens Mönig 2022-06-24 15:06:24 +02:00
rodzic 7e2d331fcb
commit 0f9f17ef51
2 zmienionych plików z 25 dodań i 1 usunięć

Wyświetl plik

@ -56,6 +56,7 @@
* threads: made block attribute "type" case-insensitive for textual mnemonics
* threads: allow variadic slot type declaration using ellipses after type numbers
* threads: allow case-insensitive text for custom block scope specification
* threads: update an existing global definition matching DEFINE's label
### 2022-06-23
* objects, threads: turned DEFINE into a command block with an upvar, experimental

Wyświetl plik

@ -5990,7 +5990,7 @@ Process.prototype.doDefineBlock = function (upvar, label, context) {
vars = this.context.outerContext.variables,
type = this.reportTypeOf(context),
count = 1,
spec, def;
matches, spec, def;
this.assertType(label, 'text');
if (label === '') {return ''; }
@ -6002,6 +6002,29 @@ Process.prototype.doDefineBlock = function (upvar, label, context) {
this.compileBlockReferences(context, upvar);
}
// identify global custom block matching the specified label
matches = ide.stage.globalBlocks.filter(def =>
def.abstractBlockSpec() === label
);
if (matches.length > 1) {
throw new Error(
'several block definitions already match this label'
);
} else if (matches.length === 1) {
// update the existing global definition with the context body
def = matches[0];
this.doSetBlockAttribute(
'definition',
def.blockInstance().reify(),
context
);
// create the reference to the new block
vars.addVar(upvar);
vars.setVar(upvar, def.blockInstance().reify());
return;
}
// make a new custom block definition
def = new CustomBlockDefinition('BYOB'); // haha!
def.type = type;