mirror of
https://github.com/google/blockly.git
synced 2026-01-06 00:20:37 +01:00
Add a block to reverse a list (#844)
This commit is contained in:
committed by
Andrew n marshall
parent
f6168e1364
commit
46316c7cea
@@ -363,3 +363,20 @@ Blockly.Lua['lists_split'] = function(block) {
|
||||
var code = functionName + '(' + input + ', ' + delimiter + ')';
|
||||
return [code, Blockly.Lua.ORDER_HIGH];
|
||||
};
|
||||
|
||||
Blockly.Lua['lists_reverse'] = function(block) {
|
||||
// Block for reversing a list.
|
||||
var list = Blockly.Lua.valueToCode(block, 'LIST',
|
||||
Blockly.Lua.ORDER_NONE) || '{}';
|
||||
var functionName = Blockly.Lua.provideFunction_(
|
||||
'list_reverse',
|
||||
['function ' + Blockly.Lua.FUNCTION_NAME_PLACEHOLDER_ + '(input)',
|
||||
' local reversed = {}',
|
||||
' for i = #input, 1, -1 do',
|
||||
' table.insert(reversed, input[i])',
|
||||
' end',
|
||||
' return reversed',
|
||||
'end']);
|
||||
var code = 'list_reverse(' + list + ')';
|
||||
return [code, Blockly.Lua.ORDER_HIGH];
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user