mirror of
https://github.com/google/blockly.git
synced 2026-01-04 23:50:12 +01:00
* feat: add getVariableName and getProcedureName to CodeGenerator * feat: make nameDB_ public * feat: update block code generators to use new APIs * chore: fix build * chore: remove unused imports
31 lines
719 B
JavaScript
31 lines
719 B
JavaScript
/**
|
|
* @license
|
|
* Copyright 2012 Google LLC
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
/**
|
|
* @fileoverview Generating Python for variable blocks.
|
|
*/
|
|
|
|
// Former goog.module ID: Blockly.Python.variables
|
|
|
|
import {Order} from './python_generator.js';
|
|
|
|
|
|
export function variables_get(block, generator) {
|
|
// Variable getter.
|
|
const code =
|
|
generator.getVariableName(block.getFieldValue('VAR'));
|
|
return [code, Order.ATOMIC];
|
|
};
|
|
|
|
export function variables_set(block, generator) {
|
|
// Variable setter.
|
|
const argument0 =
|
|
generator.valueToCode(block, 'VALUE', Order.NONE) || '0';
|
|
const varName =
|
|
generator.getVariableName(block.getFieldValue('VAR'));
|
|
return varName + ' = ' + argument0 + '\n';
|
|
};
|