简体   繁体   中英

Blockly: type check of child blocks during code generation

I am trying to generate code from blocks that can have any input type to JavaScript. But to do so I need to know what type these blocks are during generation time.

Most blocks already have a type internally for the type check

"output": ["Integer","Number"],

or

this.setOutput(true, 'String');

but I can't find a function to access the 'output' field with.

Ideally I want to access the type in the generator function like this:

var return_type = block.getChildren()[0].functionToAccessOutputWith;

There is the '.type' field but that one gives the name of the block type not the return value defined with output.

It seems like a very common problem but I can't find anything online.

Just trace through the source code by following the function calls of Block.setOutput() . It's not that hard. Eventually you will reach a line in Blockly.Connection that says this.check_ = check;

So what you are looking for is basically block.outputConnection.check_ . But this is not a function and the _ indicates that it is supposed to be a private property. For convenience I'd write a getter function into Block.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM