blockly
Version:
Blockly is a library for building visual programming editors.
338 lines (334 loc) • 25.9 kB
JavaScript
// 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 { // Script
root.lua = factory(root.Blockly);
root.Blockly.Lua = root.lua.luaGenerator;
}
}(this, function(__parent__) {
var $=__parent__.__namespace__;
var ss=function(a,b,c){return b==="FIRST"?"1":b==="FROM_END"?"#"+a+" + 1 - "+c:b==="LAST"?"#"+a:b==="RANDOM"?"math.random(#"+a+")":c},ts=function(a,b){var c=0,d="";b.STATEMENT_PREFIX&&(d+=b.injectId(b.STATEMENT_PREFIX,a));do{let e=b.valueToCode(a,"IF"+c,Y.NONE)||"false",f=b.statementToCode(a,"DO"+c);b.STATEMENT_SUFFIX&&(f=b.prefixLines(b.injectId(b.STATEMENT_SUFFIX,a),b.INDENT)+f);d+=(c>0?"else":"")+"if "+e+" then\n"+f;c++}while(a.getInput("IF"+c));if(a.getInput("ELSE")||b.STATEMENT_SUFFIX)c=a.getInput("ELSE")?
b.statementToCode(a,"ELSE"):"",b.STATEMENT_SUFFIX&&(c=b.prefixLines(b.injectId(b.STATEMENT_SUFFIX,a),b.INDENT)+c),d+="else\n"+c;return d+"end\n"},us=function(a,b){return a.includes("goto continue\n")?a+b+"::continue::\n":a},vs=function(a,b){var c=a.getField("TIMES")?String(Number(a.getFieldValue("TIMES"))):b.valueToCode(a,"TIMES",Y.NONE)||"0";c=$.zf(c)?parseInt(c,10):"math.floor("+c+")";var d=b.statementToCode(a,"DO");d=b.addLoopTrap(d,a);d=us(d,b.INDENT);return"for "+b.nameDB_.getDistinctName("count",
$.P.VARIABLE)+" = 1, "+c+" do\n"+d+"end\n"},ws=function(a,b){var c=a.getFieldValue("OP");if(c==="NEG")return a=b.valueToCode(a,"NUM",Y.UNARY)||"0",["-"+a,Y.UNARY];if(c==="POW10")return a=b.valueToCode(a,"NUM",Y.EXPONENTIATION)||"0",["10 ^ "+a,Y.EXPONENTIATION];a=c==="ROUND"?b.valueToCode(a,"NUM",Y.ADDITIVE)||"0":b.valueToCode(a,"NUM",Y.NONE)||"0";switch(c){case "ABS":c="math.abs("+a+")";break;case "ROOT":c="math.sqrt("+a+")";break;case "LN":c="math.log("+a+")";break;case "LOG10":c="math.log("+a+", 10)";
break;case "EXP":c="math.exp("+a+")";break;case "ROUND":c="math.floor("+a+" + .5)";break;case "ROUNDUP":c="math.ceil("+a+")";break;case "ROUNDDOWN":c="math.floor("+a+")";break;case "SIN":c="math.sin(math.rad("+a+"))";break;case "COS":c="math.cos(math.rad("+a+"))";break;case "TAN":c="math.tan(math.rad("+a+"))";break;case "ASIN":c="math.deg(math.asin("+a+"))";break;case "ACOS":c="math.deg(math.acos("+a+"))";break;case "ATAN":c="math.deg(math.atan("+a+"))";break;default:throw Error("Unknown math operator: "+
c);}return[c,Y.HIGH]},xs=function(a,b){var c=b.getProcedureName(a.getFieldValue("NAME")),d="";b.STATEMENT_PREFIX&&(d+=b.injectId(b.STATEMENT_PREFIX,a));b.STATEMENT_SUFFIX&&(d+=b.injectId(b.STATEMENT_SUFFIX,a));d&&(d=b.prefixLines(d,b.INDENT));var e="";b.INFINITE_LOOP_TRAP&&(e=b.prefixLines(b.injectId(b.INFINITE_LOOP_TRAP,a),b.INDENT));var f="";a.getInput("STACK")&&(f=b.statementToCode(a,"STACK"));var g="";a.getInput("RETURN")&&(g=b.valueToCode(a,"RETURN",Y.NONE)||"");var h="";f&&g&&(h=d);g?g=b.INDENT+
"return "+g+"\n":f||(f="");var m=[],z=a.getVarModels();for(let E=0;E<z.length;E++)m[E]=b.getVariableName(z[E].getId());d="function "+c+"("+m.join(", ")+")\n"+d+e+f+h+g+"end\n";d=b.scrub_(a,d);b.definitions_["%"+c]=d;return null},zs=function(a,b){var c=a.getField("TEXT")?b.quote_(a.getFieldValue("TEXT")):b.valueToCode(a,"TEXT",Y.NONE)||"''";b=b.provideFunction_("text_prompt",`
function ${b.FUNCTION_NAME_PLACEHOLDER_}(msg)
io.write(msg)
io.flush()
return io.read()
end
`)+"("+c+")";a.getFieldValue("TYPE")==="NUMBER"&&(b="tonumber("+b+", 10)");return[b,Y.HIGH]},As=function(a,b){return[b.getVariableName(a.getFieldValue("VAR")),Y.ATOMIC]},Bs=function(a,b){var c=b.valueToCode(a,"VALUE",Y.NONE)||"0";return b.getVariableName(a.getFieldValue("VAR"))+" = "+c+"\n"},Y,Cs=Y||(Y={});Cs[Cs.ATOMIC=0]="ATOMIC";Cs[Cs.HIGH=1]="HIGH";Cs[Cs.EXPONENTIATION=2]="EXPONENTIATION";Cs[Cs.UNARY=3]="UNARY";Cs[Cs.MULTIPLICATIVE=4]="MULTIPLICATIVE";Cs[Cs.ADDITIVE=5]="ADDITIVE";
Cs[Cs.CONCATENATION=6]="CONCATENATION";Cs[Cs.RELATIONAL=7]="RELATIONAL";Cs[Cs.AND=8]="AND";Cs[Cs.OR=9]="OR";Cs[Cs.NONE=99]="NONE";
var Ds=class extends $.dq{constructor(a="Lua"){super(a);this.isInitialized=!1;for(let b in Y)a=Y[b],typeof a!=="string"&&(this["ORDER_"+b]=a);this.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")}init(a){super.init(a);this.nameDB_?
this.nameDB_.reset():this.nameDB_=new $.kj(this.RESERVED_WORDS_);this.nameDB_.setVariableMap(a.getVariableMap());this.nameDB_.populateVariables(a);this.nameDB_.populateProcedures(a);this.isInitialized=!0}finish(a){var b=Object.values(this.definitions_);a=super.finish(a);this.isInitialized=!1;this.nameDB_.reset();return b.join("\n\n")+"\n\n\n"+a}scrubNakedValue(a){return"local _ = "+a+"\n"}quote_(a){a=a.replace(/\\/g,"\\\\").replace(/\n/g,"\\\n").replace(/'/g,"\\'");return"'"+a+"'"}multiline_quote_(a){return a.split(/\n/g).map(this.quote_).join(" .. '\\n' ..\n")}scrub_(a,
b,c=!1){var d="";if(!a.outputConnection||!a.outputConnection.targetConnection){var e=a.getCommentText();e&&(e=$.yf(e,this.COMMENT_WRAP-3),d+=this.prefixLines(e,"-- ")+"\n");for(let f=0;f<a.inputList.length;f++)a.inputList[f].type===$.je.VALUE&&(e=a.inputList[f].connection.targetBlock())&&(e=this.allNestedComments(e))&&(d+=this.prefixLines(e,"-- "))}a=a.nextConnection&&a.nextConnection.targetBlock();c=c?"":this.blockToCode(a);return d+b+c}};var Es={};Es.controls_if=ts;Es.controls_ifelse=ts;Es.logic_boolean=function(a){return[a.getFieldValue("BOOL")==="TRUE"?"true":"false",Y.ATOMIC]};Es.logic_compare=function(a,b){var c={EQ:"==",NEQ:"~=",LT:"<",LTE:"<=",GT:">",GTE:">="}[a.getFieldValue("OP")],d=b.valueToCode(a,"A",Y.RELATIONAL)||"0";a=b.valueToCode(a,"B",Y.RELATIONAL)||"0";return[d+" "+c+" "+a,Y.RELATIONAL]};Es.logic_negate=function(a,b){return["not "+(b.valueToCode(a,"BOOL",Y.UNARY)||"true"),Y.UNARY]};
Es.logic_null=function(){return["nil",Y.ATOMIC]};Es.logic_operation=function(a,b){var c=a.getFieldValue("OP")==="AND"?"and":"or",d=c==="and"?Y.AND:Y.OR,e=b.valueToCode(a,"A",d);a=b.valueToCode(a,"B",d);e||a?(b=c==="and"?"true":"false",e||(e=b),a||(a=b)):a=e="false";return[e+" "+c+" "+a,d]};Es.logic_ternary=function(a,b){var c=b.valueToCode(a,"IF",Y.AND)||"false",d=b.valueToCode(a,"THEN",Y.AND)||"nil";a=b.valueToCode(a,"ELSE",Y.OR)||"nil";return[c+" and "+d+" or "+a,Y.OR]};var Fs={controls_flow_statements:function(a,b){var c="";b.STATEMENT_PREFIX&&(c+=b.injectId(b.STATEMENT_PREFIX,a));b.STATEMENT_SUFFIX&&(c+=b.injectId(b.STATEMENT_SUFFIX,a));if(b.STATEMENT_PREFIX){let d=a.getSurroundLoop();d&&!d.suppressPrefixSuffix&&(c+=b.injectId(b.STATEMENT_PREFIX,d))}switch(a.getFieldValue("FLOW")){case "BREAK":return c+"break\n";case "CONTINUE":return c+"goto continue\n"}throw Error("Unknown flow statement.");},controls_for:function(a,b){var c=b.getVariableName(a.getFieldValue("VAR")),
d=b.valueToCode(a,"FROM",Y.NONE)||"0",e=b.valueToCode(a,"TO",Y.NONE)||"0",f=b.valueToCode(a,"BY",Y.NONE)||"1",g=b.statementToCode(a,"DO");g=b.addLoopTrap(g,a);g=us(g,b.INDENT);a="";if($.zf(d)&&$.zf(e)&&$.zf(f))var h=(Number(d)<=Number(e)?"":"-")+Math.abs(Number(f));else a="",h=b.nameDB_.getDistinctName(c+"_inc",$.P.VARIABLE),a+=h+" = ",a=$.zf(f)?a+(Math.abs(f)+"\n"):a+("math.abs("+f+")\n"),a=a+("if ("+d+") > ("+e+") then\n")+(b.INDENT+h+" = -"+h+"\n"),a+="end\n";return a+("for "+c+" = "+d+", "+e+
", "+h)+(" do\n"+g+"end\n")},controls_forEach:function(a,b){var c=b.getVariableName(a.getFieldValue("VAR")),d=b.valueToCode(a,"LIST",Y.NONE)||"{}",e=b.statementToCode(a,"DO");e=b.addLoopTrap(e,a);e=us(e,b.INDENT);return"for _, "+c+" in ipairs("+d+") do \n"+e+"end\n"}};Fs.controls_repeat=vs;Fs.controls_repeat_ext=vs;
Fs.controls_whileUntil=function(a,b){var c=a.getFieldValue("MODE")==="UNTIL",d=b.valueToCode(a,"BOOL",c?Y.UNARY:Y.NONE)||"false",e=b.statementToCode(a,"DO");e=b.addLoopTrap(e,a);e=us(e,b.INDENT);c&&(d="not "+d);return"while "+d+" do\n"+e+"end\n"};var Gs={math_arithmetic:function(a,b){var c={ADD:[" + ",Y.ADDITIVE],MINUS:[" - ",Y.ADDITIVE],MULTIPLY:[" * ",Y.MULTIPLICATIVE],DIVIDE:[" / ",Y.MULTIPLICATIVE],POWER:[" ^ ",Y.EXPONENTIATION]}[a.getFieldValue("OP")],d=c[0];c=c[1];var e=b.valueToCode(a,"A",c)||"0";a=b.valueToCode(a,"B",c)||"0";return[e+d+a,c]},math_atan2:function(a,b){var c=b.valueToCode(a,"X",Y.NONE)||"0";return["math.deg(math.atan2("+(b.valueToCode(a,"Y",Y.NONE)||"0")+", "+c+"))",Y.HIGH]},math_change:function(a,b){var c=b.valueToCode(a,
"DELTA",Y.ADDITIVE)||"0";a=b.getVariableName(a.getFieldValue("VAR"));return a+" = "+a+" + "+c+"\n"},math_constant:function(a){return{PI:["math.pi",Y.HIGH],E:["math.exp(1)",Y.HIGH],GOLDEN_RATIO:["(1 + math.sqrt(5)) / 2",Y.MULTIPLICATIVE],SQRT2:["math.sqrt(2)",Y.HIGH],SQRT1_2:["math.sqrt(1 / 2)",Y.HIGH],INFINITY:["math.huge",Y.HIGH]}[a.getFieldValue("CONSTANT")]},math_constrain:function(a,b){var c=b.valueToCode(a,"VALUE",Y.NONE)||"0",d=b.valueToCode(a,"LOW",Y.NONE)||"-math.huge";a=b.valueToCode(a,"HIGH",
Y.NONE)||"math.huge";return["math.min(math.max("+c+", "+d+"), "+a+")",Y.HIGH]},math_modulo:function(a,b){var c=b.valueToCode(a,"DIVIDEND",Y.MULTIPLICATIVE)||"0";a=b.valueToCode(a,"DIVISOR",Y.MULTIPLICATIVE)||"0";return[c+" % "+a,Y.MULTIPLICATIVE]},math_number:function(a){a=Number(a.getFieldValue("NUM"));return[String(a),a<0?Y.UNARY:Y.ATOMIC]},math_number_property:function(a,b){var c={EVEN:[" % 2 == 0",Y.MULTIPLICATIVE,Y.RELATIONAL],ODD:[" % 2 == 1",Y.MULTIPLICATIVE,Y.RELATIONAL],WHOLE:[" % 1 == 0",
Y.MULTIPLICATIVE,Y.RELATIONAL],POSITIVE:[" > 0",Y.RELATIONAL,Y.RELATIONAL],NEGATIVE:[" < 0",Y.RELATIONAL,Y.RELATIONAL],DIVISIBLE_BY:[null,Y.MULTIPLICATIVE,Y.RELATIONAL],PRIME:[null,Y.NONE,Y.HIGH]},d=a.getFieldValue("PROPERTY"),[e,f,g]=c[d];c=b.valueToCode(a,"NUMBER_TO_CHECK",f)||"0";if(d==="PRIME")a=b.provideFunction_("math_isPrime",`
function ${b.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
`)+"("+c+")";else if(d==="DIVISIBLE_BY"){a=b.valueToCode(a,"DIVISOR",Y.MULTIPLICATIVE)||"0";if(a==="0")return["nil",Y.ATOMIC];a=c+" % "+a+" == 0"}else a=c+e;return[a,g]},math_on_list:function(a,b){function c(){return b.provideFunction_("math_sum",`
function ${b.FUNCTION_NAME_PLACEHOLDER_}(t)
local result = 0
for _, v in ipairs(t) do
result = result + v
end
return result
end
`)}var d=a.getFieldValue("OP");a=b.valueToCode(a,"LIST",Y.NONE)||"{}";switch(d){case "SUM":d=c();break;case "MIN":d=b.provideFunction_("math_min",`
function ${b.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":d=b.provideFunction_("math_average",`
function ${b.FUNCTION_NAME_PLACEHOLDER_}(t)
if #t == 0 then
return 0
end
return ${c()}(t) / #t
end
`);break;case "MAX":d=b.provideFunction_("math_max",`
function ${b.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":d=b.provideFunction_("math_median",`
function ${b.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":d=b.provideFunction_("math_modes",`
function ${b.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":d=b.provideFunction_("math_standard_deviation",`
function ${b.FUNCTION_NAME_PLACEHOLDER_}(t)
local m
local vm
local total = 0
local count = 0
local result
m = #t == 0 and 0 or ${c()}(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":d=b.provideFunction_("math_random_list",`
function ${b.FUNCTION_NAME_PLACEHOLDER_}(t)
if #t == 0 then
return nil
end
return t[math.random(#t)]
end
`);break;default:throw Error("Unknown operator: "+d);}return[d+"("+a+")",Y.HIGH]},math_random_float:function(){return["math.random()",Y.HIGH]},math_random_int:function(a,b){var c=b.valueToCode(a,"FROM",Y.NONE)||"0";a=b.valueToCode(a,"TO",Y.NONE)||"0";return["math.random("+c+", "+a+")",Y.HIGH]}};Gs.math_round=ws;Gs.math_single=ws;Gs.math_trig=ws;var Hs={procedures_callnoreturn:function(a,b){return b.forBlock.procedures_callreturn(a,b)[0]+"\n"},procedures_callreturn:function(a,b){var c=b.getProcedureName(a.getFieldValue("NAME")),d=[],e=a.getVarModels();for(let f=0;f<e.length;f++)d[f]=b.valueToCode(a,"ARG"+f,Y.NONE)||"nil";return[c+"("+d.join(", ")+")",Y.HIGH]}};Hs.procedures_defnoreturn=xs;Hs.procedures_defreturn=xs;
Hs.procedures_ifreturn=function(a,b){var c="if "+(b.valueToCode(a,"CONDITION",Y.NONE)||"false")+" then\n";b.STATEMENT_SUFFIX&&(c+=b.prefixLines(b.injectId(b.STATEMENT_SUFFIX,a),b.INDENT));a.hasReturnValue_?(a=b.valueToCode(a,"VALUE",Y.NONE)||"nil",c+=b.INDENT+"return "+a+"\n"):c+=b.INDENT+"return\n";return c+"end\n"};var Is={text:function(a,b){return[b.quote_(a.getFieldValue("TEXT")),Y.ATOMIC]},text_append:function(a,b){var c=b.getVariableName(a.getFieldValue("VAR"));a=b.valueToCode(a,"TEXT",Y.CONCATENATION)||"''";return c+" = "+c+" .. "+a+"\n"},text_changeCase:function(a,b){var c=a.getFieldValue("CASE");a=b.valueToCode(a,"TEXT",Y.NONE)||"''";var d;c==="UPPERCASE"?d="string.upper":c==="LOWERCASE"?d="string.lower":c==="TITLECASE"&&(d=b.provideFunction_("text_titlecase",`
function ${b.FUNCTION_NAME_PLACEHOLDER_}(str)
local buf = {}
local inWord = false
for i = 1, #str do
local c = string.sub(str, i, i)
if inWord then
table.insert(buf, string.lower(c))
if string.find(c, "%s") then
inWord = false
end
else
table.insert(buf, string.upper(c))
inWord = true
end
end
return table.concat(buf)
end
`));return[d+"("+a+")",Y.HIGH]},text_charAt:function(a,b){var c=a.getFieldValue("WHERE")||"FROM_START",d=b.valueToCode(a,"VALUE",Y.NONE)||"''";if(c==="RANDOM")b=b.provideFunction_("text_random_letter",`
function ${b.FUNCTION_NAME_PLACEHOLDER_}(str)
local index = math.random(string.len(str))
return string.sub(str, index, index)
end
`)+"("+d+")";else{if(c==="FIRST")c="1";else if(c==="LAST")c="-1";else if(a=b.valueToCode(a,"AT",c==="FROM_END"?Y.UNARY:Y.NONE)||"1",c==="FROM_START")c=a;else if(c==="FROM_END")c="-"+a;else throw Error("Unhandled option (text_charAt).");b=c.match(/^-?\w*$/)?"string.sub("+d+", "+c+", "+c+")":b.provideFunction_("text_char_at",`
function ${b.FUNCTION_NAME_PLACEHOLDER_}(str, index)
return string.sub(str, index, index)
end
`)+"("+d+", "+c+")"}return[b,Y.HIGH]},text_count:function(a,b){var c=b.valueToCode(a,"TEXT",Y.NONE)||"''";a=b.valueToCode(a,"SUB",Y.NONE)||"''";return[b.provideFunction_("text_count",`
function ${b.FUNCTION_NAME_PLACEHOLDER_}(haystack, needle)
if #needle == 0 then
return #haystack + 1
end
local i = 1
local count = 0
while true do
i = string.find(haystack, needle, i, true)
if i == nil then
break
end
count = count + 1
i = i + #needle
end
return count
end
`)+"("+c+", "+a+")",Y.HIGH]},text_getSubstring:function(a,b){var c=b.valueToCode(a,"STRING",Y.NONE)||"''",d=a.getFieldValue("WHERE1"),e=b.valueToCode(a,"AT1",d==="FROM_END"?Y.UNARY:Y.NONE)||"1";if(d==="FIRST")d=1;else if(d==="FROM_START")d=e;else if(d==="FROM_END")d="-"+e;else throw Error("Unhandled option (text_getSubstring)");e=a.getFieldValue("WHERE2");a=b.valueToCode(a,"AT2",e==="FROM_END"?Y.UNARY:Y.NONE)||"1";if(e==="LAST")a=-1;else if(e!=="FROM_START")if(e==="FROM_END")a="-"+a;else throw Error("Unhandled option (text_getSubstring)");
return["string.sub("+c+", "+d+", "+a+")",Y.HIGH]},text_indexOf:function(a,b){var c=b.valueToCode(a,"FIND",Y.NONE)||"''",d=b.valueToCode(a,"VALUE",Y.NONE)||"''";return[(a.getFieldValue("END")==="FIRST"?b.provideFunction_("firstIndexOf",`
function ${b.FUNCTION_NAME_PLACEHOLDER_}(str, substr)
local i = string.find(str, substr, 1, true)
if i == nil then
return 0
end
return i
end
`):b.provideFunction_("lastIndexOf",`
function ${b.FUNCTION_NAME_PLACEHOLDER_}(str, substr)
local i = string.find(string.reverse(str), string.reverse(substr), 1, true)
if i then
return #str + 2 - i - #substr
end
return 0
end
`))+"("+d+", "+c+")",Y.HIGH]},text_isEmpty:function(a,b){return["#"+(b.valueToCode(a,"VALUE",Y.UNARY)||"''")+" == 0",Y.RELATIONAL]},text_join:function(a,b){if(a.itemCount_===0)return["''",Y.ATOMIC];if(a.itemCount_===1)return["tostring("+(b.valueToCode(a,"ADD0",Y.NONE)||"''")+")",Y.HIGH];if(a.itemCount_===2){var c=b.valueToCode(a,"ADD0",Y.CONCATENATION)||"''";a=b.valueToCode(a,"ADD1",Y.CONCATENATION)||"''";return[c+" .. "+a,Y.CONCATENATION]}c=[];for(let d=0;d<a.itemCount_;d++)c[d]=b.valueToCode(a,
"ADD"+d,Y.NONE)||"''";return["table.concat({"+c.join(", ")+"})",Y.HIGH]},text_length:function(a,b){return["#"+(b.valueToCode(a,"VALUE",Y.UNARY)||"''"),Y.UNARY]},text_print:function(a,b){return"print("+(b.valueToCode(a,"TEXT",Y.NONE)||"''")+")\n"}};Is.text_prompt=zs;Is.text_prompt_ext=zs;Is.text_replace=function(a,b){var c=b.valueToCode(a,"TEXT",Y.NONE)||"''",d=b.valueToCode(a,"FROM",Y.NONE)||"''";a=b.valueToCode(a,"TO",Y.NONE)||"''";return[b.provideFunction_("text_replace",`
function ${b.FUNCTION_NAME_PLACEHOLDER_}(haystack, needle, replacement)
local buf = {}
local i = 1
while i <= #haystack do
if string.sub(haystack, i, i + #needle - 1) == needle then
for j = 1, #replacement do
table.insert(buf, string.sub(replacement, j, j))
end
i = i + #needle
else
table.insert(buf, string.sub(haystack, i, i))
i = i + 1
end
end
return table.concat(buf)
end
`)+"("+c+", "+d+", "+a+")",Y.HIGH]};Is.text_reverse=function(a,b){return["string.reverse("+(b.valueToCode(a,"TEXT",Y.NONE)||"''")+")",Y.HIGH]};Is.text_trim=function(a,b){var c={LEFT:"^%s*(,-)",RIGHT:"(.-)%s*$",BOTH:"^%s*(.-)%s*$"}[a.getFieldValue("MODE")];return["string.gsub("+(b.valueToCode(a,"TEXT",Y.NONE)||"''")+', "'+c+'", "%1")',Y.HIGH]};var Js={};Js.variables_get=As;Js.variables_set=Bs;var Ks={};Ks.variables_get_dynamic=As;Ks.variables_set_dynamic=Bs;var Ls=new Ds,Ms=Object.assign({},{lists_create_empty:function(){return["{}",Y.HIGH]},lists_create_with:function(a,b){var c=Array(a.itemCount_);for(let d=0;d<a.itemCount_;d++)c[d]=b.valueToCode(a,"ADD"+d,Y.NONE)||"nil";return["{"+c.join(", ")+"}",Y.HIGH]},lists_getIndex:function(a,b){var c=a.getFieldValue("MODE")||"GET",d=a.getFieldValue("WHERE")||"FROM_START",e=b.valueToCode(a,"VALUE",Y.HIGH)||"({})";if(d!=="LAST"&&d!=="FROM_END"&&d!=="RANDOM"||e.match(/^\w+$/)){b=b.valueToCode(a,"AT",c==="GET"&&
d==="FROM_END"?Y.ADDITIVE:Y.NONE)||"1";b=ss(e,d,b);if(c==="GET")return[e+"["+b+"]",Y.HIGH];d="table.remove("+e+", "+b+")";return c==="GET_REMOVE"?[d,Y.HIGH]:d+"\n"}if(c==="REMOVE")return c=b.valueToCode(a,"AT",d==="FROM_END"?Y.ADDITIVE:Y.NONE)||"1",b=b.nameDB_.getDistinctName("tmp_list",$.P.VARIABLE),c=ss(b,d,c),b+" = "+e+"\ntable.remove("+b+", "+c+")\n";a=b.valueToCode(a,"AT",Y.NONE)||"1";return[(c==="GET"?b.provideFunction_("list_get_"+d.toLowerCase(),["function "+b.FUNCTION_NAME_PLACEHOLDER_+"(t"+
(d==="FROM_END"||d==="FROM_START"?", at)":")")," return t["+ss("t",d,"at")+"]","end"]):b.provideFunction_("list_remove_"+d.toLowerCase(),["function "+b.FUNCTION_NAME_PLACEHOLDER_+"(t"+(d==="FROM_END"||d==="FROM_START"?", at)":")")," return table.remove(t, "+ss("t",d,"at")+")","end"]))+"("+e+(d==="FROM_END"||d==="FROM_START"?", "+a:"")+")",Y.HIGH]},lists_getSublist:function(a,b){var c=b.valueToCode(a,"LIST",Y.NONE)||"{}",d=a.getFieldValue("WHERE1"),e=a.getFieldValue("WHERE2"),f=b.valueToCode(a,"AT1",
Y.NONE)||"1";a=b.valueToCode(a,"AT2",Y.NONE)||"1";var g=d==="FROM_END"||d==="FROM_START"?", at1":"",h=e==="FROM_END"||e==="FROM_START"?", at2":"";return[b.provideFunction_("list_sublist_"+d.toLowerCase()+"_"+e.toLowerCase(),`
function ${b.FUNCTION_NAME_PLACEHOLDER_}(source${g}${h})
local t = {}
local start = ${ss("source",d,"at1")}
local finish = ${ss("source",e,"at2")}
for i = start, finish do
table.insert(t, source[i])
end
return t
end
`)+"("+c+(d==="FROM_END"||d==="FROM_START"?", "+f:"")+(e==="FROM_END"||e==="FROM_START"?", "+a:"")+")",Y.HIGH]},lists_indexOf:function(a,b){var c=b.valueToCode(a,"FIND",Y.NONE)||"''",d=b.valueToCode(a,"VALUE",Y.NONE)||"{}";return[(a.getFieldValue("END")==="FIRST"?b.provideFunction_("first_index",`
function ${b.FUNCTION_NAME_PLACEHOLDER_}(t, elem)
for k, v in ipairs(t) do
if v == elem then
return k
end
end
return 0
end
`):b.provideFunction_("last_index",`
function ${b.FUNCTION_NAME_PLACEHOLDER_}(t, elem)
for i = #t, 1, -1 do
if t[i] == elem then
return i
end
end
return 0
end
`))+"("+d+", "+c+")",Y.HIGH]},lists_isEmpty:function(a,b){return["#"+(b.valueToCode(a,"VALUE",Y.UNARY)||"{}")+" == 0",Y.RELATIONAL]},lists_length:function(a,b){return["#"+(b.valueToCode(a,"VALUE",Y.UNARY)||"{}"),Y.UNARY]},lists_repeat:function(a,b){var c=b.provideFunction_("create_list_repeated",`
function ${b.FUNCTION_NAME_PLACEHOLDER_}(item, count)
local t = {}
for i = 1, count do
table.insert(t, item)
end
return t
end
`),d=b.valueToCode(a,"ITEM",Y.NONE)||"nil";a=b.valueToCode(a,"NUM",Y.NONE)||"0";return[c+"("+d+", "+a+")",Y.HIGH]},lists_reverse:function(a,b){a=b.valueToCode(a,"LIST",Y.NONE)||"{}";return[b.provideFunction_("list_reverse",`
function ${b.FUNCTION_NAME_PLACEHOLDER_}(input)
local reversed = {}
for i = #input, 1, -1 do
table.insert(reversed, input[i])
end
return reversed
end
`)+"("+a+")",Y.HIGH]},lists_setIndex:function(a,b){var c=b.valueToCode(a,"LIST",Y.HIGH)||"{}",d=a.getFieldValue("MODE")||"SET",e=a.getFieldValue("WHERE")||"FROM_START",f=b.valueToCode(a,"AT",Y.ADDITIVE)||"1";a=b.valueToCode(a,"TO",Y.NONE)||"Nil";var g="";e!=="LAST"&&e!=="FROM_END"&&e!=="RANDOM"||c.match(/^\w+$/)||(b=b.nameDB_.getDistinctName("tmp_list",$.P.VARIABLE),g=b+" = "+c+"\n",c=b);g=d==="SET"?g+(c+"["+ss(c,e,f)+"] = "+a):g+("table.insert("+c+", "+(ss(c,e,f)+(e==="LAST"?" + 1":""))+", "+a+")");
return g+"\n"},lists_sort:function(a,b){var c=b.valueToCode(a,"LIST",Y.NONE)||"{}",d=a.getFieldValue("DIRECTION")==="1"?1:-1;a=a.getFieldValue("TYPE");return[b.provideFunction_("list_sort",`
function ${b.FUNCTION_NAME_PLACEHOLDER_}(list, typev, direction)
local t = {}
for n,v in pairs(list) do table.insert(t, v) end
local compareFuncs = {
NUMERIC = function(a, b)
return (tonumber(tostring(a)) or 0)
< (tonumber(tostring(b)) or 0) end,
TEXT = function(a, b)
return tostring(a) < tostring(b) end,
IGNORE_CASE = function(a, b)
return string.lower(tostring(a)) < string.lower(tostring(b)) end
}
local compareTemp = compareFuncs[typev]
local compare = compareTemp
if direction == -1
then compare = function(a, b) return compareTemp(b, a) end
end
table.sort(t, compare)
return t
end
`)+"("+c+',"'+a+'", '+d+")",Y.HIGH]},lists_split:function(a,b){var c=b.valueToCode(a,"INPUT",Y.NONE),d=b.valueToCode(a,"DELIM",Y.NONE)||"''";a=a.getFieldValue("MODE");if(a==="SPLIT")c||(c="''"),b=b.provideFunction_("list_string_split",`
function ${b.FUNCTION_NAME_PLACEHOLDER_}(input, delim)
local t = {}
local pos = 1
while true do
next_delim = string.find(input, delim, pos)
if next_delim == nil then
table.insert(t, string.sub(input, pos))
break
else
table.insert(t, string.sub(input, pos, next_delim-1))
pos = next_delim + #delim
end
end
return t
end
`);else if(a==="JOIN")c||(c="{}"),b="table.concat";else throw Error("Unknown mode: "+a);return[b+"("+c+", "+d+")",Y.HIGH]}},Es,Fs,Gs,Hs,Is,Js,Ks);for(let a in Ms)Ls.forBlock[a]=Ms[a];var Ns={};Ns.LuaGenerator=Ds;Ns.Order=Y;Ns.luaGenerator=Ls;$.__chunk_lua=Ns;
$.__chunk_lua.__namespace__=$;
return $.__chunk_lua;
}));
//# sourceMappingURL=lua_compressed.js.map