123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188 |
- 'use strict';
- goog.provide('Blockly.Lua');
- goog.require('Blockly.Generator');
- Blockly.Lua = new Blockly.Generator('Lua');
- Blockly.Lua.addReservedWords(
-
- '_,' +
-
-
- '__inext,assert,bit,colors,colours,coroutine,disk,dofile,error,fs,' +
- 'fetfenv,getmetatable,gps,help,io,ipairs,keys,loadfile,loadstring,math,' +
- 'native,next,os,paintutils,pairs,parallel,pcall,peripheral,print,' +
- 'printError,rawequal,rawget,rawset,read,rednet,redstone,rs,select,' +
- 'setfenv,setmetatable,sleep,string,table,term,textutils,tonumber,' +
- 'tostring,turtle,type,unpack,vector,write,xpcall,_VERSION,__indext,' +
-
- 'HTTP,' +
-
- 'and,break,do,else,elseif,end,false,for,function,if,in,local,nil,not,or,' +
- 'repeat,return,then,true,until,while,' +
-
- 'add,sub,mul,div,mod,pow,unm,concat,len,eq,lt,le,index,newindex,call,' +
-
- 'assert,collectgarbage,dofile,error,_G,getmetatable,inpairs,load,' +
- 'loadfile,next,pairs,pcall,print,rawequal,rawget,rawlen,rawset,select,' +
- 'setmetatable,tonumber,tostring,type,_VERSION,xpcall,' +
-
- 'require,package,string,table,math,bit32,io,file,os,debug'
- );
- Blockly.Lua.ORDER_ATOMIC = 0;
- Blockly.Lua.ORDER_HIGH = 1;
- Blockly.Lua.ORDER_EXPONENTIATION = 2;
- Blockly.Lua.ORDER_UNARY = 3;
- Blockly.Lua.ORDER_MULTIPLICATIVE = 4;
- Blockly.Lua.ORDER_ADDITIVE = 5;
- Blockly.Lua.ORDER_CONCATENATION = 6;
- Blockly.Lua.ORDER_RELATIONAL = 7;
- Blockly.Lua.ORDER_AND = 8;
- Blockly.Lua.ORDER_OR = 9;
- Blockly.Lua.ORDER_NONE = 99;
- Blockly.Lua.init = function(workspace) {
-
- Blockly.Lua.definitions_ = Object.create(null);
-
-
- Blockly.Lua.functionNames_ = Object.create(null);
- if (!Blockly.Lua.variableDB_) {
- Blockly.Lua.variableDB_ =
- new Blockly.Names(Blockly.Lua.RESERVED_WORDS_);
- } else {
- Blockly.Lua.variableDB_.reset();
- }
- };
- Blockly.Lua.finish = function(code) {
-
- var definitions = [];
- for (var name in Blockly.Lua.definitions_) {
- definitions.push(Blockly.Lua.definitions_[name]);
- }
-
- delete Blockly.Lua.definitions_;
- delete Blockly.Lua.functionNames_;
- Blockly.Lua.variableDB_.reset();
- return definitions.join('\n\n') + '\n\n\n' + code;
- };
- Blockly.Lua.scrubNakedValue = function(line) {
- return 'local _ = ' + line + '\n';
- };
- Blockly.Lua.quote_ = function(string) {
-
- string = string.replace(/\\/g, '\\\\')
- .replace(/\n/g, '\\\n')
- .replace(/'/g, '\\\'');
- return '\'' + string + '\'';
- };
- Blockly.Lua.scrub_ = function(block, code) {
- var commentCode = '';
-
- if (!block.outputConnection || !block.outputConnection.targetConnection) {
-
- var comment = block.getCommentText();
- if (comment) {
- commentCode += Blockly.Lua.prefixLines(comment, '-- ') + '\n';
- }
-
-
- for (var x = 0; x < block.inputList.length; x++) {
- if (block.inputList[x].type == Blockly.INPUT_VALUE) {
- var childBlock = block.inputList[x].connection.targetBlock();
- if (childBlock) {
- comment = Blockly.Lua.allNestedComments(childBlock);
- if (comment) {
- commentCode += Blockly.Lua.prefixLines(comment, '-- ');
- }
- }
- }
- }
- }
- var nextBlock = block.nextConnection && block.nextConnection.targetBlock();
- var nextCode = Blockly.Lua.blockToCode(nextBlock);
- return commentCode + code + nextCode;
- };
|