tuple.js 646 B

123456789101112131415161718192021
  1. 'use strict';
  2. goog.provide('Blockly.Python.tuple');
  3. goog.require('Blockly.Python');
  4. Blockly.Python['tuple_create'] = function(block) {
  5. // Create a list with any number of elements of any type.
  6. var elements = new Array(block.itemCount_);
  7. for (var i = 0; i < block.itemCount_; i++) {
  8. elements[i] = (Blockly.Python.valueToCode(block, 'ADD' + i,
  9. Blockly.Python.ORDER_NONE) || '___' );
  10. }
  11. var code = elements.join(', ');
  12. if (block.itemCount_ == 1) {
  13. code = '(' + code + ',)';
  14. } else {
  15. code = '(' + code + ')';
  16. }
  17. return [code, Blockly.Python.ORDER_ATOMIC];
  18. }