Files
blockly/generators/lua/variables.js
Neil Fraser 2f2252f588 Rename variableDB_ to nameDB_
There is significant confusion in names and comments with regards to variables and procedures.  `Blockly.Generator.prototype.variableDB_` is a Blockly.Names database, not a variable map.  This rename introduces a getter and setter so deprecated references still work.  This commit also fixes some comments which are either outright wrong or misleading regarding variable and procedure names.
2021-05-27 21:30:26 -07:00

33 lines
837 B
JavaScript

/**
* @license
* Copyright 2016 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @fileoverview Generating Lua for variable blocks.
* @author rodrigoq@google.com (Rodrigo Queiro)
*/
'use strict';
goog.provide('Blockly.Lua.variables');
goog.require('Blockly.Lua');
Blockly.Lua['variables_get'] = function(block) {
// Variable getter.
var code = Blockly.Lua.nameDB_.getName(block.getFieldValue('VAR'),
Blockly.VARIABLE_CATEGORY_NAME);
return [code, Blockly.Lua.ORDER_ATOMIC];
};
Blockly.Lua['variables_set'] = function(block) {
// Variable setter.
var argument0 = Blockly.Lua.valueToCode(block, 'VALUE',
Blockly.Lua.ORDER_NONE) || '0';
var varName = Blockly.Lua.nameDB_.getName(
block.getFieldValue('VAR'), Blockly.VARIABLE_CATEGORY_NAME);
return varName + ' = ' + argument0 + '\n';
};