// Do not edit this file; automatically generated. /* eslint-disable */ ;(function(root, factory) { if (typeof define === 'function' && define.amd) { // AMD define(["./blockly_compressed.js"], factory); } else if (typeof exports === 'object') { // Node.js module.exports = factory(require("./blockly_compressed.js")); } else { // Browser root.Blockly.Lua = factory(root.Blockly); } }(this, function(Blockly) { const $=Blockly.internal_; var module$contents$Blockly$Lua_Lua=new $.module$exports$Blockly$Generator.Generator("Lua");module$contents$Blockly$Lua_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"); module$contents$Blockly$Lua_Lua.ORDER_ATOMIC=0;module$contents$Blockly$Lua_Lua.ORDER_HIGH=1;module$contents$Blockly$Lua_Lua.ORDER_EXPONENTIATION=2;module$contents$Blockly$Lua_Lua.ORDER_UNARY=3;module$contents$Blockly$Lua_Lua.ORDER_MULTIPLICATIVE=4;module$contents$Blockly$Lua_Lua.ORDER_ADDITIVE=5;module$contents$Blockly$Lua_Lua.ORDER_CONCATENATION=6;module$contents$Blockly$Lua_Lua.ORDER_RELATIONAL=7;module$contents$Blockly$Lua_Lua.ORDER_AND=8;module$contents$Blockly$Lua_Lua.ORDER_OR=9; module$contents$Blockly$Lua_Lua.ORDER_NONE=99;module$contents$Blockly$Lua_Lua.isInitialized=!1;module$contents$Blockly$Lua_Lua.init=function(a){Object.getPrototypeOf(this).init.call(this);this.nameDB_?this.nameDB_.reset():this.nameDB_=new $.module$exports$Blockly$Names.Names(this.RESERVED_WORDS_);this.nameDB_.setVariableMap(a.getVariableMap());this.nameDB_.populateVariables(a);this.nameDB_.populateProcedures(a);this.isInitialized=!0}; module$contents$Blockly$Lua_Lua.finish=function(a){var b=(0,$.module$exports$Blockly$utils$object.values)(this.definitions_);a=Object.getPrototypeOf(this).finish.call(this,a);this.isInitialized=!1;this.nameDB_.reset();return b.join("\n\n")+"\n\n\n"+a};module$contents$Blockly$Lua_Lua.scrubNakedValue=function(a){return"local _ = "+a+"\n"};module$contents$Blockly$Lua_Lua.quote_=function(a){a=a.replace(/\\/g,"\\\\").replace(/\n/g,"\\\n").replace(/'/g,"\\'");return"'"+a+"'"}; module$contents$Blockly$Lua_Lua.multiline_quote_=function(a){return a.split(/\n/g).map(this.quote_).join(" .. '\\n' ..\n")}; module$contents$Blockly$Lua_Lua.scrub_=function(a,b,c){var d="";if(!a.outputConnection||!a.outputConnection.targetConnection){var e=a.getCommentText();e&&(e=(0,$.module$exports$Blockly$utils$string.wrap)(e,this.COMMENT_WRAP-3),d+=this.prefixLines(e,"-- ")+"\n");for(var f=0;fa?$.Blockly.Lua.ORDER_UNARY:$.Blockly.Lua.ORDER_ATOMIC]}; $.Blockly.Lua.math_arithmetic=function(a){var b={ADD:[" + ",$.Blockly.Lua.ORDER_ADDITIVE],MINUS:[" - ",$.Blockly.Lua.ORDER_ADDITIVE],MULTIPLY:[" * ",$.Blockly.Lua.ORDER_MULTIPLICATIVE],DIVIDE:[" / ",$.Blockly.Lua.ORDER_MULTIPLICATIVE],POWER:[" ^ ",$.Blockly.Lua.ORDER_EXPONENTIATION]}[a.getFieldValue("OP")],c=b[0];b=b[1];var d=$.Blockly.Lua.valueToCode(a,"A",b)||"0";a=$.Blockly.Lua.valueToCode(a,"B",b)||"0";return[d+c+a,b]}; $.Blockly.Lua.math_single=function(a){var b=a.getFieldValue("OP");if("NEG"===b)return a=$.Blockly.Lua.valueToCode(a,"NUM",$.Blockly.Lua.ORDER_UNARY)||"0",["-"+a,$.Blockly.Lua.ORDER_UNARY];if("POW10"===b)return a=$.Blockly.Lua.valueToCode(a,"NUM",$.Blockly.Lua.ORDER_EXPONENTIATION)||"0",["10 ^ "+a,$.Blockly.Lua.ORDER_EXPONENTIATION];a="ROUND"===b?$.Blockly.Lua.valueToCode(a,"NUM",$.Blockly.Lua.ORDER_ADDITIVE)||"0":$.Blockly.Lua.valueToCode(a,"NUM",$.Blockly.Lua.ORDER_NONE)||"0";switch(b){case "ABS":b= "math.abs("+a+")";break;case "ROOT":b="math.sqrt("+a+")";break;case "LN":b="math.log("+a+")";break;case "LOG10":b="math.log("+a+", 10)";break;case "EXP":b="math.exp("+a+")";break;case "ROUND":b="math.floor("+a+" + .5)";break;case "ROUNDUP":b="math.ceil("+a+")";break;case "ROUNDDOWN":b="math.floor("+a+")";break;case "SIN":b="math.sin(math.rad("+a+"))";break;case "COS":b="math.cos(math.rad("+a+"))";break;case "TAN":b="math.tan(math.rad("+a+"))";break;case "ASIN":b="math.deg(math.asin("+a+"))";break; case "ACOS":b="math.deg(math.acos("+a+"))";break;case "ATAN":b="math.deg(math.atan("+a+"))";break;default:throw Error("Unknown math operator: "+b);}return[b,$.Blockly.Lua.ORDER_HIGH]}; $.Blockly.Lua.math_constant=function(a){return{PI:["math.pi",$.Blockly.Lua.ORDER_HIGH],E:["math.exp(1)",$.Blockly.Lua.ORDER_HIGH],GOLDEN_RATIO:["(1 + math.sqrt(5)) / 2",$.Blockly.Lua.ORDER_MULTIPLICATIVE],SQRT2:["math.sqrt(2)",$.Blockly.Lua.ORDER_HIGH],SQRT1_2:["math.sqrt(1 / 2)",$.Blockly.Lua.ORDER_HIGH],INFINITY:["math.huge",$.Blockly.Lua.ORDER_HIGH]}[a.getFieldValue("CONSTANT")]}; $.Blockly.Lua.math_number_property=function(a){var b=$.Blockly.Lua.valueToCode(a,"NUMBER_TO_CHECK",$.Blockly.Lua.ORDER_MULTIPLICATIVE)||"0",c=a.getFieldValue("PROPERTY");if("PRIME"===c)return[$.Blockly.Lua.provideFunction_("math_isPrime",["function "+$.Blockly.Lua.FUNCTION_NAME_PLACEHOLDER_+"(n)"," -- https://en.wikipedia.org/wiki/Primality_test#Naive_methods"," if n == 2 or n == 3 then"," return true"," end"," -- False if n is NaN, negative, is 1, or not whole."," -- And false if n is divisible by 2 or 3.", " if not(n > 1) or n % 1 ~= 0 or n % 2 == 0 or n % 3 == 0 then"," return false"," end"," -- Check all the numbers of form 6k +/- 1, up to sqrt(n)."," for x = 6, math.sqrt(n) + 1.5, 6 do"," if n % (x - 1) == 0 or n % (x + 1) == 0 then"," return false"," end"," end"," return true","end"])+"("+b+")",$.Blockly.Lua.ORDER_HIGH];switch(c){case "EVEN":var d=b+" % 2 == 0";break;case "ODD":d=b+" % 2 == 1";break;case "WHOLE":d=b+" % 1 == 0";break;case "POSITIVE":d=b+" > 0";break;case "NEGATIVE":d= b+" < 0";break;case "DIVISIBLE_BY":a=$.Blockly.Lua.valueToCode(a,"DIVISOR",$.Blockly.Lua.ORDER_MULTIPLICATIVE);if(!a||"0"===a)return["nil",$.Blockly.Lua.ORDER_ATOMIC];d=b+" % "+a+" == 0"}return[d,$.Blockly.Lua.ORDER_RELATIONAL]};$.Blockly.Lua.math_change=function(a){var b=$.Blockly.Lua.valueToCode(a,"DELTA",$.Blockly.Lua.ORDER_ADDITIVE)||"0";a=$.Blockly.Lua.nameDB_.getName(a.getFieldValue("VAR"),$.module$exports$Blockly$Names.NameType.VARIABLE);return a+" = "+a+" + "+b+"\n"}; $.Blockly.Lua.math_round=$.Blockly.Lua.math_single;$.Blockly.Lua.math_trig=$.Blockly.Lua.math_single; $.Blockly.Lua.math_on_list=function(a){function b(){return $.Blockly.Lua.provideFunction_("math_sum",["function "+$.Blockly.Lua.FUNCTION_NAME_PLACEHOLDER_+"(t)"," local result = 0"," for _, v in ipairs(t) do"," result = result + v"," end"," return result","end"])}var c=a.getFieldValue("OP");a=$.Blockly.Lua.valueToCode(a,"LIST",$.Blockly.Lua.ORDER_NONE)||"{}";switch(c){case "SUM":c=b();break;case "MIN":c=$.Blockly.Lua.provideFunction_("math_min",["function "+$.Blockly.Lua.FUNCTION_NAME_PLACEHOLDER_+ "(t)"," if #t == 0 then"," return 0"," end"," local result = math.huge"," for _, v in ipairs(t) do"," if v < result then"," result = v"," end"," end"," return result","end"]);break;case "AVERAGE":c=$.Blockly.Lua.provideFunction_("math_average",["function "+$.Blockly.Lua.FUNCTION_NAME_PLACEHOLDER_+"(t)"," if #t == 0 then"," return 0"," end"," return "+b()+"(t) / #t","end"]);break;case "MAX":c=$.Blockly.Lua.provideFunction_("math_max",["function "+$.Blockly.Lua.FUNCTION_NAME_PLACEHOLDER_+ "(t)"," if #t == 0 then"," return 0"," end"," local result = -math.huge"," for _, v in ipairs(t) do"," if v > result then"," result = v"," end"," end"," return result","end"]);break;case "MEDIAN":c=$.Blockly.Lua.provideFunction_("math_median",["function "+$.Blockly.Lua.FUNCTION_NAME_PLACEHOLDER_+"(t)"," -- Source: http://lua-users.org/wiki/SimpleStats"," if #t == 0 then"," return 0"," end"," local temp={}"," for _, v in ipairs(t) do",' if type(v) == "number" then'," table.insert(temp, v)", " end"," end"," table.sort(temp)"," if #temp % 2 == 0 then"," return (temp[#temp/2] + temp[(#temp/2)+1]) / 2"," else"," return temp[math.ceil(#temp/2)]"," end","end"]);break;case "MODE":c=$.Blockly.Lua.provideFunction_("math_modes",["function "+$.Blockly.Lua.FUNCTION_NAME_PLACEHOLDER_+"(t)"," -- Source: http://lua-users.org/wiki/SimpleStats"," local counts={}"," for _, v in ipairs(t) do"," if counts[v] == nil then"," counts[v] = 1"," else"," counts[v] = counts[v] + 1", " end"," end"," local biggestCount = 0"," for _, v in pairs(counts) do"," if v > biggestCount then"," biggestCount = v"," end"," end"," local temp={}"," for k, v in pairs(counts) do"," if v == biggestCount then"," table.insert(temp, k)"," end"," end"," return temp","end"]);break;case "STD_DEV":c=$.Blockly.Lua.provideFunction_("math_standard_deviation",["function "+$.Blockly.Lua.FUNCTION_NAME_PLACEHOLDER_+"(t)"," local m"," local vm"," local total = 0"," local count = 0", " local result"," m = #t == 0 and 0 or "+b()+"(t) / #t"," for _, v in ipairs(t) do"," if type(v) == 'number' then"," vm = v - m"," total = total + (vm * vm)"," count = count + 1"," end"," end"," result = math.sqrt(total / (count-1))"," return result","end"]);break;case "RANDOM":c=$.Blockly.Lua.provideFunction_("math_random_list",["function "+$.Blockly.Lua.FUNCTION_NAME_PLACEHOLDER_+"(t)"," if #t == 0 then"," return nil"," end"," return t[math.random(#t)]","end"]); break;default:throw Error("Unknown operator: "+c);}return[c+"("+a+")",$.Blockly.Lua.ORDER_HIGH]};$.Blockly.Lua.math_modulo=function(a){var b=$.Blockly.Lua.valueToCode(a,"DIVIDEND",$.Blockly.Lua.ORDER_MULTIPLICATIVE)||"0";a=$.Blockly.Lua.valueToCode(a,"DIVISOR",$.Blockly.Lua.ORDER_MULTIPLICATIVE)||"0";return[b+" % "+a,$.Blockly.Lua.ORDER_MULTIPLICATIVE]}; $.Blockly.Lua.math_constrain=function(a){var b=$.Blockly.Lua.valueToCode(a,"VALUE",$.Blockly.Lua.ORDER_NONE)||"0",c=$.Blockly.Lua.valueToCode(a,"LOW",$.Blockly.Lua.ORDER_NONE)||"-math.huge";a=$.Blockly.Lua.valueToCode(a,"HIGH",$.Blockly.Lua.ORDER_NONE)||"math.huge";return["math.min(math.max("+b+", "+c+"), "+a+")",$.Blockly.Lua.ORDER_HIGH]}; $.Blockly.Lua.math_random_int=function(a){var b=$.Blockly.Lua.valueToCode(a,"FROM",$.Blockly.Lua.ORDER_NONE)||"0";a=$.Blockly.Lua.valueToCode(a,"TO",$.Blockly.Lua.ORDER_NONE)||"0";return["math.random("+b+", "+a+")",$.Blockly.Lua.ORDER_HIGH]};$.Blockly.Lua.math_random_float=function(a){return["math.random()",$.Blockly.Lua.ORDER_HIGH]}; $.Blockly.Lua.math_atan2=function(a){var b=$.Blockly.Lua.valueToCode(a,"X",$.Blockly.Lua.ORDER_NONE)||"0";return["math.deg(math.atan2("+($.Blockly.Lua.valueToCode(a,"Y",$.Blockly.Lua.ORDER_NONE)||"0")+", "+b+"))",$.Blockly.Lua.ORDER_HIGH]};var module$exports$Blockly$Lua$loops={},module$contents$Blockly$Lua$loops_CONTINUE_STATEMENT="goto continue\n",module$contents$Blockly$Lua$loops_addContinueLabel=function(a){return-1!==a.indexOf(module$contents$Blockly$Lua$loops_CONTINUE_STATEMENT)?a+$.Blockly.Lua.INDENT+"::continue::\n":a}; $.Blockly.Lua.controls_repeat_ext=function(a){var b=a.getField("TIMES")?String(Number(a.getFieldValue("TIMES"))):$.Blockly.Lua.valueToCode(a,"TIMES",$.Blockly.Lua.ORDER_NONE)||"0";b=(0,$.module$exports$Blockly$utils$string.isNumber)(b)?parseInt(b,10):"math.floor("+b+")";var c=$.Blockly.Lua.statementToCode(a,"DO");c=$.Blockly.Lua.addLoopTrap(c,a);c=module$contents$Blockly$Lua$loops_addContinueLabel(c);return"for "+$.Blockly.Lua.nameDB_.getDistinctName("count",$.module$exports$Blockly$Names.NameType.VARIABLE)+ " = 1, "+b+" do\n"+c+"end\n"};$.Blockly.Lua.controls_repeat=$.Blockly.Lua.controls_repeat_ext;$.Blockly.Lua.controls_whileUntil=function(a){var b="UNTIL"===a.getFieldValue("MODE"),c=$.Blockly.Lua.valueToCode(a,"BOOL",b?$.Blockly.Lua.ORDER_UNARY:$.Blockly.Lua.ORDER_NONE)||"false",d=$.Blockly.Lua.statementToCode(a,"DO");d=$.Blockly.Lua.addLoopTrap(d,a);d=module$contents$Blockly$Lua$loops_addContinueLabel(d);b&&(c="not "+c);return"while "+c+" do\n"+d+"end\n"}; $.Blockly.Lua.controls_for=function(a){var b=$.Blockly.Lua.nameDB_.getName(a.getFieldValue("VAR"),$.module$exports$Blockly$Names.NameType.VARIABLE),c=$.Blockly.Lua.valueToCode(a,"FROM",$.Blockly.Lua.ORDER_NONE)||"0",d=$.Blockly.Lua.valueToCode(a,"TO",$.Blockly.Lua.ORDER_NONE)||"0",e=$.Blockly.Lua.valueToCode(a,"BY",$.Blockly.Lua.ORDER_NONE)||"1",f=$.Blockly.Lua.statementToCode(a,"DO");f=$.Blockly.Lua.addLoopTrap(f,a);f=module$contents$Blockly$Lua$loops_addContinueLabel(f);a="";if((0,$.module$exports$Blockly$utils$string.isNumber)(c)&& (0,$.module$exports$Blockly$utils$string.isNumber)(d)&&(0,$.module$exports$Blockly$utils$string.isNumber)(e))var g=(Number(c)<=Number(d)?"":"-")+Math.abs(Number(e));else a="",g=$.Blockly.Lua.nameDB_.getDistinctName(b+"_inc",$.module$exports$Blockly$Names.NameType.VARIABLE),a+=g+" = ",a=(0,$.module$exports$Blockly$utils$string.isNumber)(e)?a+(Math.abs(e)+"\n"):a+("math.abs("+e+")\n"),a=a+("if ("+c+") > ("+d+") then\n")+($.Blockly.Lua.INDENT+g+" = -"+g+"\n"),a+="end\n";return a+("for "+b+" = "+c+", "+ d+", "+g)+(" do\n"+f+"end\n")};$.Blockly.Lua.controls_forEach=function(a){var b=$.Blockly.Lua.nameDB_.getName(a.getFieldValue("VAR"),$.module$exports$Blockly$Names.NameType.VARIABLE),c=$.Blockly.Lua.valueToCode(a,"LIST",$.Blockly.Lua.ORDER_NONE)||"{}",d=$.Blockly.Lua.statementToCode(a,"DO");d=$.Blockly.Lua.addLoopTrap(d,a);d=module$contents$Blockly$Lua$loops_addContinueLabel(d);return"for _, "+b+" in ipairs("+c+") do \n"+d+"end\n"}; $.Blockly.Lua.controls_flow_statements=function(a){var b="";$.Blockly.Lua.STATEMENT_PREFIX&&(b+=$.Blockly.Lua.injectId($.Blockly.Lua.STATEMENT_PREFIX,a));$.Blockly.Lua.STATEMENT_SUFFIX&&(b+=$.Blockly.Lua.injectId($.Blockly.Lua.STATEMENT_SUFFIX,a));if($.Blockly.Lua.STATEMENT_PREFIX){var c=a.getSurroundLoop();c&&!c.suppressPrefixSuffix&&(b+=$.Blockly.Lua.injectId($.Blockly.Lua.STATEMENT_PREFIX,c))}switch(a.getFieldValue("FLOW")){case "BREAK":return b+"break\n";case "CONTINUE":return b+module$contents$Blockly$Lua$loops_CONTINUE_STATEMENT}throw Error("Unknown flow statement."); };var module$exports$Blockly$Lua$logic={}; $.Blockly.Lua.controls_if=function(a){var b=0,c="";$.Blockly.Lua.STATEMENT_PREFIX&&(c+=$.Blockly.Lua.injectId($.Blockly.Lua.STATEMENT_PREFIX,a));do{var d=$.Blockly.Lua.valueToCode(a,"IF"+b,$.Blockly.Lua.ORDER_NONE)||"false",e=$.Blockly.Lua.statementToCode(a,"DO"+b);$.Blockly.Lua.STATEMENT_SUFFIX&&(e=$.Blockly.Lua.prefixLines($.Blockly.Lua.injectId($.Blockly.Lua.STATEMENT_SUFFIX,a),$.Blockly.Lua.INDENT)+e);c+=(0",GTE:">="}[a.getFieldValue("OP")],c=$.Blockly.Lua.valueToCode(a,"A",$.Blockly.Lua.ORDER_RELATIONAL)||"0";a=$.Blockly.Lua.valueToCode(a,"B",$.Blockly.Lua.ORDER_RELATIONAL)||"0";return[c+" "+b+" "+a,$.Blockly.Lua.ORDER_RELATIONAL]}; $.Blockly.Lua.logic_operation=function(a){var b="AND"===a.getFieldValue("OP")?"and":"or",c="and"===b?$.Blockly.Lua.ORDER_AND:$.Blockly.Lua.ORDER_OR,d=$.Blockly.Lua.valueToCode(a,"A",c);a=$.Blockly.Lua.valueToCode(a,"B",c);if(d||a){var e="and"===b?"true":"false";d||(d=e);a||(a=e)}else a=d="false";return[d+" "+b+" "+a,c]};$.Blockly.Lua.logic_negate=function(a){return["not "+($.Blockly.Lua.valueToCode(a,"BOOL",$.Blockly.Lua.ORDER_UNARY)||"true"),$.Blockly.Lua.ORDER_UNARY]}; $.Blockly.Lua.logic_boolean=function(a){return["TRUE"===a.getFieldValue("BOOL")?"true":"false",$.Blockly.Lua.ORDER_ATOMIC]};$.Blockly.Lua.logic_null=function(a){return["nil",$.Blockly.Lua.ORDER_ATOMIC]};$.Blockly.Lua.logic_ternary=function(a){var b=$.Blockly.Lua.valueToCode(a,"IF",$.Blockly.Lua.ORDER_AND)||"false",c=$.Blockly.Lua.valueToCode(a,"THEN",$.Blockly.Lua.ORDER_AND)||"nil";a=$.Blockly.Lua.valueToCode(a,"ELSE",$.Blockly.Lua.ORDER_OR)||"nil";return[b+" and "+c+" or "+a,$.Blockly.Lua.ORDER_OR]};var module$exports$Blockly$Lua$lists={};$.Blockly.Lua.lists_create_empty=function(a){return["{}",$.Blockly.Lua.ORDER_HIGH]};$.Blockly.Lua.lists_create_with=function(a){for(var b=Array(a.itemCount_),c=0;c