How to create the same block generate two different code to diferrent programming languages

124 views
Skip to first unread message

Josue da Silva Gomes Junior

unread,
May 28, 2016, 10:29:23 PM5/28/16
to Blockly

hello everyone would like to create this block in green and generate code for these two languages in the tabs on the image "OpenCL" and "Kernel".

To create this page, I have edited the code demo page of blockly, I created the blocks in the block factory and put the information "language code" in blocks_compressed.js file and "stub generator" in javascript_compressed and python_compressed file, but I edited the name the file "javascript_compressed" to "opencl_compressed" and "python_compressed" to "kernel_compressed".

I put this code in the end of the file opencl_compressed.js
Blockly.JavaScript['operacaocommatrizes'] = function(block) {
    var statements_matriza = Blockly.JavaScript.statementToCode(block, 'MatrizA');
    var dropdown_name = block.getFieldValue('NAME');
    var statements_matrizb = Blockly.JavaScript.statementToCode(block, 'MatrizB');
    var code = 'opencl';
    return code;
}

and this code in the end of the file kernel_compressed.js

Blockly.JavaScript['operacaocommatrizes'] = function(block) {
    var statements_matriza = Blockly.JavaScript.statementToCode(block, 'MatrizA');
    var dropdown_name = block.getFieldValue('NAME');
    var statements_matrizb = Blockly.JavaScript.statementToCode(block, 'MatrizB');
    var code = 'kernel';
    return code;
}

but does not work. the page only generates the first one code for both tabs  "python_compressed" and "kernel_compressed"

Neil Fraser

unread,
May 29, 2016, 12:18:01 AM5/29/16
to blo...@googlegroups.com
One really should not be editing the compressed files.  Even if successful, it makes you code impossible to upgrade as improvements are made to Blockly.  Instead, create a separate file that contains your own blocks and generators, and add a <script> tag in your HTML to include it.  That way Blockly can be upgraded without destroying your code.

--
You received this message because you are subscribed to the Google Groups "Blockly" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blockly+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

Josue da Silva Gomes Junior

unread,
May 29, 2016, 12:48:12 AM5/29/16
to blo...@googlegroups.com
Thanks Neil Fraser, I'll fix it, and already understood the procedures to do the same block to generate the two languages

--
You received this message because you are subscribed to a topic in the Google Groups "Blockly" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/blockly/kSjv-Z4h-p4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to blockly+u...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Ciência da Computação (lic)
UFPB - CCAE
Reply all
Reply to author
Forward
0 new messages