Advertisement
MAG_Gen

C SuS SuS (CSSC 3.5-beta) Package Installer - Code preprocessor for Lua (5.1) language.

Oct 7th, 2023 (edited)
220
-1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 112.95 KB | Software | 0 1
  1. --LOCAL PART
  2. local lzss_api,cssc_api,env_pack,cssc_prog_code,startup,Fg,Bg,tArgs,scnd_clr,path1,path2,st_path,env_path,comp,install,main,x,y,max_x,max_y,version,description,license,make_gui,PrimeUI,animate_color,savePal,loadPal,rainbowPrintEffect,lzss_sep,lzss_hash=
  3. {},{["LZSS"]="",["LZSS-SEP"]="",["Original"]="",["Minified"]=""},{["LZSS"]="",["LZSS-SEP"]="",["Original"]="",["Minified"]=""},"","",term.getTextColor(),term.getBackgroundColor(),{...}
  4. ------------------------------------------------------------------------------------
  5. --CODE PART
  6. startup_small=[=[local S,C,d=settings,"cssc.enable","CSSC_PATH"S.define(C,{default=true,type="boolean"})if S.get(C)then
  7. shell.run(d.."cssc_api.lua")cssc.addPath(d.."modules/",1)end]=]
  8. cssc_prog_code      =[===========[if#{...}<1 then print"Usage: cssc <prog>"return end
  9. local p,E,a,t,f,e,r=shell.resolveProgram(...),error,{...},table.remove
  10. p=p or E("Program `"..a[1].."` not found!")
  11. f,e=fs.open(p,"r")
  12. e=e and E(e)
  13. r=f.readAll():gsub("^#!cssc\n","",1)
  14. r=r:find"^[^<]"and"<A,err>"..r or r
  15. r,e=cssc.load(r,"@"..p,nil,_ENV)
  16. f.close()
  17. e=e and E(e)
  18. t(a,1)
  19. arg[0]=t(arg,1)
  20. return r(unpack(a))]===========] -- 11
  21. startup             =[=[local S,s,c,a,p,m,C,d=settings,shell,require"cc.shell.completion","cssc_api.lua","cssc.lua","modules/","cssc.enable","CSSC_PATH"S.define(C,{default=true,type="boolean"})if S.get(C)then
  22. s.run(d..a)cssc.addPath(d..m,1)s.setAlias("cssc",d..p)s.setCompletionFunction(d..p,c.build({c.programWithArgs,2,many=true}))end]=]
  23. cssc_api["Original"]=[=============[ -- C SuS SuS Programming language compiler 3.5 - alpha
  24.  
  25. --CODE START
  26. --this section contain all lua keywords for specific features
  27. K={}
  28. Ks="if function for while repeat elseif else do then end until local return in break "
  29. Kb={}
  30. Ks:gsub("(%S+)( )", function (x,s)K[#K+1]=s..x..s Kb[x]=#K end )
  31. NL=load  --native CraftOS load function
  32. --initialize lambda function feature
  33. local l= function (C,o) --DO NOT PLACE LAMBDA AT THE START OF FILE!!! You will got ")" instead of "function(*args*)"
  34.     local i,a,e,p=#C.R,1
  35.     e=C.R[i]
  36.     p=e:find"^%)%s*" and "" or "("
  37.     while i>0 and (#p>0 and (a and (e:match"[%w_]+" or "..."==e) or ","==e) or #p<1 and  not e:find"^%(%s*")do --comma or word or ( if ) located
  38.         i,a=i-1,not a
  39.         e=C.R[i] end
  40.     table.insert(C.R,#p<1 and i or i+1,K[2]..p)-- K[2] - function keyword K[13] - return
  41.     C.R[#C.R+1]=(#p>0 and ")" or "")..(o:sub(1,1)=="-" and K[13] or "") --WARNING!!! Thanks for your attention! =)
  42.     if C.L then --core exist
  43.         C.pv=2 -- Lua5.3 operators compatability patch (and for some future things)
  44.         C.C.L("function",1)
  45.     end
  46. end
  47.  
  48. --FEATURES TABLE
  49. F={
  50. --initialise main features::
  51.  
  52. -- keywords and "if else then" shortcut section
  53. E={ ["/|"]=K[1],--if
  54.     ["?"]=K[9],--then
  55.     [":|"]=K[6],--elseif
  56.     ["\\|"]=K[7]},--else
  57. K={ ["@"]=K[12],--local
  58.     ["$"]=K[13],--return
  59.     ["||"]=" or ",--or
  60.     ["&&"]=" and ",--and
  61.     ["!"]=" not ",--not
  62.     [";"]=K[10]},--end
  63.  
  64. --lambda section
  65. F={ ["->"]=l,
  66.     ["=>"]=l}
  67.  
  68.  
  69. }
  70.  
  71. -- C SuS SuS Compiller (CSSC)
  72. -- Base function for all cores and modules
  73. L= function (x,name,mode,env)
  74.     if type(x)=="string" then -- x might be a function or a string
  75.         local c=x:match"^<.->" or x:match"^#!.-\n?<.->" -- locate control string
  76.         if c then --control string exists!
  77.        
  78.             --INITIALISE LOCALS
  79.             local po,R,O,C,s,t,a,b,l,e="",{""},{['"']= function () return  end ,["\0"]= function (C) local r=C.R r[#r]=r[#r].." "..(table.remove(C.c,1) or "") end ,['..']='..',['...']='...'} -- " - for strings \0 - for comments
  80.             x=x:sub(#c+1) --remove control string to start parsing
  81.             C={O=O,C= function () end ,R=R,F={},c={},l=1,pv=1} -- initialise control tablet for special functions call
  82.                  --S -> the core module (empty by default)
  83.             --INITIALIZE COMPILLER
  84.             for K,V in c:gmatch"([%w_]+)%(?([%w_. ]*)"do--load flags that used in control string: K - feature name V - feature argument
  85.                 if F[K] then -- feature exist
  86.                     for k,v in pairs(F[K])do O[k]=v end
  87.                     l=F[K][1] and F[K][1](C,V,x,name,mode,env)-- [1] index is used to store special compiller directives
  88.                     if l then  return l end --PRELOAD CHECK
  89.                 end                                          -- if special has argumet V ex: "<pre(V)>" then F["pre"][1](ctrl_table,"V")
  90.             end
  91.             O[1]=nil -- remove trash from current_operators table (all specials in S table now)
  92.            
  93.             --COMPILE -- o: operator, w: word
  94.             l=#x+1
  95.             for o,w,i in x:gmatch"([%s!#-&(-/:-@\\-^{-~`]*%[?=*[%['\"]?%s*)([%w_]*[^%w%p%[-`{-~\\-_%s]*[^\n%S]*)()"do
  96.                                         -- see that pattern? Now try to spell it in one breath! =P
  97.                 --LINE COUNTER          -- in this pattern the word (w) will never be "^%s*$"!
  98.                 o:gsub("\n", function ()C.l=C.l+1 end )
  99.                 --STRING MODE: string or comment located and must be captured
  100.                 if s then
  101.                     a,b,e=o:find(#s<2 and "(\\*[\n"..s.."])%s*" or "(%]=*%])%s*") --locate posible end of string (depends on string type)
  102.                     if a and (#s<2 and (s=="\n" or #e%2>0) or #s==#e) or i==l then -- end of something found, check is it our string end or not
  103.                         b=b or i
  104.                         t=t..o:sub(0,b) --finish string
  105.                         if c then c=C.c
  106.                         else
  107.                             t=C.C(nil,t,i)or t --CORE module
  108.                             c=R
  109.                         end
  110.                         c[#c+1]=t -- insert object
  111.                         o=po..o:sub(b+1) --form new operators sequence
  112.                         s,t=nil --disable string mode
  113.                     else
  114.                         t=t..o..w --continue string
  115.                     end
  116.                 end
  117.                
  118.                 --DEFAULT MODE: main compiler part
  119.                 if  not s then
  120.                     --STRING LOCATOR
  121.                     o=o:gsub("-%-%s-\n","\n")--remove all empty comments (they may corrupt a lot of things!)
  122.                     c=o:match"-%-%[?=*%[?" --if start found: init str_mode
  123.                     s=o:match"%[=*%["or o:match"['\"]"
  124.                     if c or s then
  125.                         a=o:find(c or s,1,1)
  126.                         s=c and (c:sub(3)==s and s or "\n") or s --(string/long_string/long_comment) or small_comment
  127.                         t,w=o:sub(a)..w,"" -- save temp string and errase word
  128.                         o=o:sub(0,a-1)..(c and "\0" or '"') -- correct opeartor seq add control character
  129.                         po=c and (o or "") or "" -- set previous operator
  130.                     end
  131.                     --IF NOT COMMENT
  132.                     if not c or i==l then
  133.                         --OPERATOR PARCE: Default parcer and custom functions launcher
  134.                         while #o>0 do
  135.                             a=o:match"^%s*" --this code was made to decrase the length of result table and allow spacing in operators capture section
  136.                             R[#R]=R[#R]..a
  137.                             o=o:sub(#a+1)
  138.                             for i=3,1,-1 do --WARNING! Max operator length: 3    
  139.                                 a=o:sub(1,i)  -- a variable here used to store enabled_operators[posible operator]
  140.                                 b=O[a] or i<2 and a
  141.                                 if b and #o>0 then --if O[posible_operator] -> C SuS SuS enabled operator (or something else) found and must be parced
  142.                                     b=C.C(a,b,i) or b -- CORE module call
  143.                                     if 7>#type(b) then --type<7 -> string; >7 - function | these can't be any othere values
  144.                                         R[#R+1]=b --string located
  145.                                         o=o:sub(i+1)
  146.                                     else
  147.                                         b={b(C,o,w,i)} --if there is a special replacement function
  148.                                         o,w=b[1] or o:sub(i+1),b[2] or w
  149.                                     end
  150.                                     break -- operator found! break out...
  151.                                 end
  152.                             end
  153.                         end
  154.                         --WORD
  155.                         if #w>0 then
  156.                             w=C.C(nil,w,i) or w --CORE module call
  157.                             R[#R+1]=w
  158.                         end
  159.                     end
  160.                 end
  161.             end
  162.            
  163.             --FINISH COMPILE
  164.             for k,v in pairs(C.F)do
  165.                 local a,n,m,e=v(x,name,mode,env)--launch all finalizer function
  166.                 if C.rt then  return a,n end -- if finaliser return something then return it vithout calling native load
  167.                 x=a or x
  168.                 name=n or name
  169.                 mode=m or mode
  170.                 env=e or env
  171.             end
  172.             x=table.concat(R)
  173.             if mode=="c" then  return R end
  174.         end
  175.     end
  176.     return NL(x,name,mode,env)
  177. end
  178.  
  179. --COMPILLER CORES AND MODULES:load other features of compiler using compiler ITSELF
  180. a,b=L([=[<K,E,F>
  181.  
  182. F.K[';']=C,o,w=> -- any ";" that stand near ";,)]" or "\n" will be replaced by " end " for ex ";;" equal to " end  end "
  183.     @a,p=o:match"(;*) *([%S\n]?)%s*"
  184.     /|#p>0&&p~="("||#a>1?
  185.         for i=1,#a do
  186.         C.R[#C.R+1]=K[10]
  187.         /|C.L?C.C.L("end");--K[10]="end"
  188.                   end
  189.     \|C.R[#C.R+1]=";";
  190.     $o:sub(#a+1);
  191.    
  192. --OBJ: object separator function
  193. OBJ=o=>$type(o)=='string'&&o:match"%S+"||"";
  194.  
  195. do--CSSC Environmet table (CC:T-f)
  196. @o=setmetatable({},{__index=os})
  197. clone=value,arg=>
  198.     @D,v,a=debug,value,arg||{}
  199.     @t=type(v)
  200.     /|t=="function"?
  201.         @I=D.getinfo(v)
  202.         @f=NL(t.dump(v),I.source,nil,a.env||getfenv(v))
  203.         for i=1,I.nups do
  204.             /|a.ref?D.upvaluejoin(f,i,v,i)
  205.             \|@n,d=D.getupvalue(v,i)D.setupvalue(f,i,d);
  206.                       end $f
  207.     :|t=="table"?
  208.         t={}for k,v in pairs(v)do t[k]=v end
  209.         $setmetatable(t,a.meta||getmetatable(v));;
  210. @m={__index=_G}
  211. env={os=o,
  212.      clone=clone,
  213.      load=L,
  214.      loadfile=clone(loadfile,{env=setmetatable({load=L},m)}),
  215.      include=name,force=>
  216.          @e=getfenv(2)
  217.          @r=e.require
  218.          /|!r?error("Unable to include '"..name.."', _ENV has no require function!",2);
  219.          @f,t=pcall(r,name)
  220.          /|!f?error(t,2);
  221.          for k,v in pairs(t)do
  222.              e[k]=!force&&e[k]||v
  223.                            end $t;}
  224.  
  225. @e={env=setmetatable({loadfile=env.loadfile},m)}
  226. o.run=clone(os.run,e)
  227. o.loadAPI=clone(os.loadAPI,e)
  228. end
  229.  
  230. --Error detector
  231. err=C,s=>C.err=C.err||"SuS["..C.l.."]:"..s;
  232. F.err={C=>
  233.     C.F.err==>
  234.         /|C.err?C.rt=1$ nil,C.err;;;}
  235.  
  236. --Preload feature
  237. F.pre={C,V,x,n,m,e=>
  238.     /|!cssc.preload?cssc.preload={};
  239.     @P=cssc.preload
  240.     /|P[V]?$NL(P[V],n,m,e);
  241.     C.F.pre==>P[V]=table.concat(C.R);;}
  242.  
  243. --Debug feature (old debug will be removed in final version)
  244. F.dbg={C,V=>-- V - argument
  245.     @v=V
  246.     C.F.dbg=x,n,m=>
  247.         /|v=="P"?require"cc.pretty".pretty_print(C.R)
  248.         :|v=="p"?print(table.concat(C.R));
  249.         /|m=="c"?C.rt=1$C.R
  250.         :|m=="s"?C.rt=1$table.concat(C.R);;;}
  251.  
  252. --0b0000000 and 0o0000.000 number format support (avaliable exponenta: E+-x)
  253. F.b={C=>--return function that will be inserted in special extensions table
  254.     F.c[1](C)
  255.     C.C.W.b=o,w=>
  256.         @a,b,c,r,t=w:match"^0([bo])(%d*)([eE]?.*)" --RUSH EEEEEEEEEEEEE for exponenta
  257.         /|C.b&&C.R[#C.R]=="."?t,b,c=C.b,w:match"(%d+)([eE]?.*)"--b located! posible floating point!
  258.         \|C.b=nil;
  259.         /|b?--number exist
  260.           t,r=t||(a>"b"&&"8"||"2"),0--You are a good person if you read this (^_^)
  261.           for i,k in b:gmatch"()(.)"do
  262.              /|k>=t?err(C,"This is not a valid number: 0"..a..b..c);--if number is weird
  263.              r=r+k*t^(#b-i)-- t: number base system, r - result, i - current position in number string
  264.                                    end
  265.           r=C.b&&tostring(r/t^#b):sub(3)||r--this is a floating point! recalculate required!
  266.           C.b=!C.b&&#c<1&&t||nil--floating point support
  267.           $r..c;;;}
  268.  
  269.  
  270. --This function works as #include directive in C++
  271. --include"module" inserts all module values to _ENV (_ENV must have 'require' inside it!)
  272. do
  273. -- Add path
  274. @N=fs.combine
  275. adp=str,full=>cssc.path=full and cssc.path..N(str,"?;")..N(str,"?.lua;")..N(str,"?/init.lua;")or cssc.path..str..";";
  276. --ATP: Attempt to perform
  277. ATP=C,wt,on=>err(C,"Attempt to perform '"..wt.."' on '"..on.."'!");
  278.  
  279. --C SuS SuS LANGUAGE CORE
  280. F.c={C=>
  281.     /|C.CR?$;
  282.     C.CR=1--mark & skip
  283.     C.L={{st=1,t="main"},o={},c={}}--leveling table [o -> on lvl open, c -> on lvl close]
  284.     @l=C.L
  285.     @r=C.R
  286.     --add uncatched operators
  287.     for k in("=~<>"):gfind"."do k=k..'='C.O[k]=k end
  288.     --EVENT invocator
  289.     @f=T,o,w,i=>for k,v in pairs(T)do w=v(o,w,i)or w end $w;
  290.     --table print f
  291.     @pt=t=>@r=""for k in pairs(t)do r=r..k.."' or '"end$r:sub(1,-7);
  292.     --CORE table
  293.     C.C={W={},O={},A={},K={},o={['and']=1,['or']=1,['not']=1}, -- o for operators
  294.     --LEVELING controller
  295.         l={["for"]="do",["while"]="do",["repeat"]="until",["if"]="then",["then"]={["else"]=1,["elseif"]=1,["end"]=1},["elseif"]="then",["else"]="end",["do"]="end",["function"]="end",["{"]="}",["("]=")",["["]="]"},--level ends table (then has no end because it can has multiple ones)
  296.         L=o,v=>/|v?l[#l+1]=f(l.o,o,{t=o})     -- level+
  297.                \|@e=C.C.l[l[#l].t]            -- level-
  298.                  @t=#type(e)==5
  299.                  /|!t&&e&&e~=o||t&&!e[o]?err(C,"Expected '"..(te&&pt(e)||e).."' after '"..l[#l].t.."' but got '"..o.."'!");--level error detection
  300.                  /|#l<2?err(C,"Unexpected '"..o.."'!");
  301.                  @cl=l[#l]
  302.                  l[#l]=#l<2&&l[#l]||nil
  303.                  f(l.c,o,cl);;}-- level-
  304.     @c=C.C
  305.     C.F[1]=x,n,m,e=>
  306.         /|#l>1?err(C,"Unclosed construction! Missing '"..(c.l[l[#l].t]||"end").."'!"..#l);
  307.         @p=e&&e.package --CC:T require
  308.         /|p?p.path=p.path..cssc.path--if package.path exist then add additional path
  309.             setfenv(p.loaders[2],setmetatable({loadfile=env.loadfile},{_index=_G}))
  310.             for k,v in pairs(env)do e[k]=rawget(e,k)||v end;;
  311.    
  312.     --CORE function
  313.     setmetatable(C.C,{__call=S,o,w,i=>
  314.         /|o=='"'||o=='\0'?$;--skip string markers and comments
  315.         C.pv=C.cv -- set previous value
  316.         C.cv=nil
  317.         /|#type(w)==6?
  318.             @ow=OBJ(w)
  319.             @k=Kb[ow]--get keyword id if keyword
  320.             /|k?C.cv=1--KEYWORD
  321.                 --keywords leveling part
  322.                 /|k>5&&k<12?c.L(ow);--end  level
  323.                 /|k<10?c.L(ow,1);   --open level
  324.                 w=f(c.K,o,w,i)||w
  325.             :|c.o[ow]?C.cv=2 w=f(c.O,o,w,i)||w;;--OPERATOR (and or not)
  326.         /|!C.cv?
  327.             /|!o?C.cv=w:find"^['\"%[]"&&6||3 w=f(c.W,o,w,i)||w                       --KEYWORD(1)  WORD(3)         STRING(6)
  328.             \|C.cv=o:find"^[%[%({]"&&4||o:find"^[%]%)}]"&&5||2
  329.               /|C.cv==4?c.L(o,1); --breaket+
  330.               /|C.cv==5?c.L(o);   --breaket-
  331.               w=f(c.O,o,w,i)||w;;                                                    --OPERATOR(2) BREAKET_OPEN(4) BREAKET_CLOSE(5)
  332.         w=f(c.A,o,w,i)||w--ALL
  333.         $w;})
  334.    
  335.     --START SEARCHER
  336.     --@lb=->OBJ(r[#r]):find"^ ?[%]%)}\"']";
  337.     l.o[#l.o+1]=o,t=>--on level open
  338.         @s=#r+1
  339.         /|C.pv&&C.pv<3?l[#l].st=s;--previous level
  340.         t.st=s+1;--next level table
  341.     c.W.st=o,w=>
  342.         @p=OBJ(r[#r])
  343.         /|p:find"[.:]"&&#p<2?$;--default start searcher allowed operators
  344.         /|C.cv==6&&C.pv>2?$;--current word is string and previous word was an operator or keyword
  345.         l[#l].st=#r+1;
  346.     ;}
  347. end
  348.  
  349. --UE:Unexpected value
  350. UE=C,o=>err(C,"Unexpected '"..o.."'!");
  351. -- Default function arguments feature
  352. F.D={C=>
  353.     F.c[1](C)
  354.     @l=C.L
  355.     @r=C.R
  356.     l.o[#l.o+1]=o,t=>
  357.         /|t.t=="function"?t.ada=1;-- allow_default_args for nex level
  358.         /|l[#l].ada?
  359.             l[#l].ada=nil
  360.             /|t.t=="("?t.da={};;;
  361.     l.c[#l.c+1]=o,t=>--on level close
  362.         l[#l].ada=nil
  363.         /|t.da&&#t.da>0&&t.t=="("? -- da - default_args
  364.             r[#r+1]=")"
  365.             t.da[#t.da].nd=t.da[#t.da].nd||#r-1 --set last index if not exist
  366.             --remove default statements and finalise default args
  367.             for i=#t.da,1,-1 do
  368.             --print(r[t.da[i].st],t.da[i].nd,#r,t.t)
  369.                 @ob=r[t.da[i].st-1]
  370.                 r[#r+1]="if "..ob.."==nil then "..ob.."="--insert start
  371.                 for j=t.da[i].st,t.da[i].nd do r[#r+1]=r[j]end--insert obj
  372.                 r[#r+1]=" end "--insert end
  373.                 for j=t.da[i].nd,t.da[i].st,-1 do table.remove(r,j)end--remove default arg
  374.                             end
  375.             t.da=nil
  376.             C.C.A.da=o,w=>C.C.A.da=nil$()->;;;;--this part is required to switch of the ')' insertion (because we already inserted one)
  377.     C.C.O.da=o,w=> --catch coma and ';'
  378.         @d=l[#l].da
  379.         /|d&&o==';'?UE(C,';');
  380.         /|d&&#d>0&&o==','?
  381.             d[#d].nd=d[#d].nd||#r;;
  382.     C.O[":="]=C,o,w=>
  383.         /|!l[#l].da?UE(C,':=')--emit an error
  384.         \|@d=l[#l].da
  385.           d[#d+1]={st=#r+1};;
  386.     ;}
  387.  
  388. --Prohibited area check
  389. PAch=t->t:find"[{(%[]"||t=="if"||t=="elseif"||t=="for"||t=="while";
  390.  
  391. -- Nil forgiving operators feature
  392. do
  393. @c,d=setmetatable--nil returning object | nilF feature: nil forgiving operators | d -> default c-> colon
  394. d=c({},{__call=->nil;,__index=->nil;})
  395. c=c({},{__index=->()->nil;;})
  396.  
  397. N=(o,i)=>-- o -> object, i -> index
  398.     /|o==nil?$i&&c||d;--> obj not exist (false and other variables are allowed)
  399.     /|i?$o[i]&&o||c;--> obj and index exist -> colon mode
  400.     $o;-- obj exist but not index
  401.  
  402. F.N={C=>
  403.     F.c[1](C)
  404.     C.C.O.N=o=>/|F.N[o]?C.cv=C.pv;;;}--mark F.N operators as start searcher allowed (core-invisible)
  405. for v,k in('.:"({'):gfind"()(.)"do
  406.     F.N['?'..k]=C,o,w=>
  407.         @r=C.R
  408.         /|#r<2||C.pv<3?ATP(C,k,r[#r]);--previous value was a keyword or operator
  409.         /|o:sub(3):find"[^\0%s]"?ATP(C,OBJ(o:sub(3)),k);
  410.         table.insert(C.R,C.L[#C.L].st," cssc.nilF(")--first part
  411.         r[#r+1]=v==2&&",'"..w.."')"||')'
  412.         /|v==1?--no error and index detected
  413.             C.ci=#r--index of ?
  414.             C.pc=#r+2-- index of word
  415.             C.C.A.str=o=>
  416.                 /|C.pc<=#r? print(C.cv,w,r[#r],r[#r-1],r[#r-2],#r,o)
  417.                     /|C.cv>4||C.cv>3&&!o:find'^[)%]}]'?
  418.                         table.insert(r,C.ci,",'"..w.."'");
  419.                     C.C.A.str=nil;;;
  420.         $o:sub(2);
  421.                                end
  422. end
  423.  
  424. -- X= operators feature.
  425. --WARNING! They don't support multiple asignemnt (a,b X= *code*) - is prohibited!
  426.  
  427. --Add initialiser function to F.K feature to enable support of &&= and ||=
  428. F.K[1]=C=>C.EQ={"&&","||",unpack(C.EQ||{})};
  429. -- ?= function
  430. @qeq=b,a=> --b - base, a - adition
  431. /|a==nil?$b
  432. \|$a;;
  433. F.C={C=>
  434.     F.c[1](C)--load start searcher
  435.     --EQ - table with operators that support *op*= behaviour
  436.     C.EQ={"+","-","*","%","/","..","^","?",unpack(C.EQ||{})}
  437.     @l=C.L
  438.     @r=C.R
  439.     C.C.A.br=o,w=>
  440.         /|l[#l].br&&(C.pv==3||C.pv>4)&&(C.cv==1||C.cv==3||(o==','||o==';'))? --breaket request located and end of block located
  441.             l[#l].br=nil
  442.             r[#r+1]=")";;
  443.     l.c[#l.c+1]=o,t=>/|t.br?r[#r+1]=")";; -- on level end
  444.     C.F.c==>/|l[#l].br?r[#r+1]=")";;
  445.     --operator main parce function
  446.     @op=C,o,w=>
  447.         @lt=l[#l].t
  448.         /|PAch(lt)?err(C,"Attempt to use X= operator in prohibited area! '"..lt.." *var* X= *val* "..C.C.l[lt].."'");
  449.         /|OBJ(r[l[#l].st-1]||"")==","?err(C,"Comma detected! X= operators has no multiple assignments support!");
  450.         /|#r<2||C.pv<3?ATP(C,k,r[#r]);
  451.         o=o:match"(.-)="--for this we need only the first part of operator
  452.         r[#r+1]="="..(o=="?"&&"cssc.q_eq("||"")--insert equality or ?=
  453.         l[#l].m={bor=#r+1} --Lua5.3 feature support
  454.         for i=l[#l].st,#r-1 do r[#r+1]=r[i]end --copy variable from the start of an object
  455.         @t=#type(C.O[o])
  456.         /|o=="?"?r[#r+1]=","
  457.         :|t==6?r[#r+1]=C.O[o]--string
  458.         :|t==3?r[#r+1]=o--operator
  459.         \|C.O[o](C,o,w);--function
  460.         --print(C,o,w)
  461.         /|o~="?"?r[#r+1]="("; --add opening breaket
  462.         l[#l].br=1  --request closing breaet for this level
  463.         l[#l].m={bor=#r+1}; --Lua5.3 feature support
  464.     -- main function initialiser        
  465.     for i=1,#C.EQ do C.O[C.EQ[i].."=" ]=op end;--END OF F.C
  466. }
  467.  
  468. --IS keyword simular to typeof()
  469. @tof=o->(getmetatable(o)||{}).__type||type(o);
  470. @is=setmetatable({},{__concat=v,a=>$setmetatable({a},--is inited
  471.         {__concat=v,a=> --a args v value
  472.         /|type(a[1])=="table"?a=a[1];
  473.         for i=1,#a do
  474.             /|tof(v)==a[i]?$true;
  475.                   end
  476.         $false;});})
  477. _G.typeof=tof--include typeof into global environment
  478. F.IS={C=>
  479.     F.c[1](C)
  480.     C.C.o['is']=1
  481.     @l=C.L
  482.     C.C.O[1]=o,w=>
  483.         w=OBJ(w)
  484.         /|w=='is'?
  485.             /|#C.R<2||C.pv<3?ATP(C,'is',C.R[#C.R]);
  486.             $" ..cssc.is.. ";;;}
  487.  
  488. --Lua5.3 operators feature! Bitwise and idiv operators support!
  489. do
  490. @B={}
  491. for k,v in pairs(bit32)do B[k]=v end
  492. B.idiv=a,b->math.floor(a/b);
  493. B.shl=B.lshift
  494. B.shr=B.rshift
  495. @bt={shl='<<',shr='>>',bxor='~',bor='|',band='&',idiv='//'}
  496. @kp={}('and or , = ; > < >= <= ~= == '):gsub("%S+",(x)=>kp[x]=1;) -- all operators that has lower priority than bitise operators
  497. @f=t,m->"Attempt to perform "..t.." bitwise operation on a "..m.." value";
  498. M={bnot=setmetatable({},{
  499.     __pow=a,b=>
  500.         @m=(getmetatable(b)||{}).bnot
  501.         /|m?$m(b);
  502.         m=type(b)
  503.         /|m~='number'?error(f('bitwise',m),3);
  504.         $B.bnot(b);})}
  505.  
  506. for k,v in pairs(bt)do
  507.     @n='__'..k--name of metamethod
  508.     @t='number'--number value type
  509.     @e=v=='//'&&'idiv'||'bitwise'
  510.     @f=a,b=>--base calculation function
  511.         @m=(getmetatable(a[1])||{})[n]||(getmetatable(b)||{})[n]
  512.         /|m?$m(a,b);--metamethod located! Calculation override!
  513.         m=type(a[1])
  514.         m=m==t&&type(b)||m
  515.         /|m~=t?error(f(e,m),3);
  516.         $B[k](a[1],b);
  517.     M[k]=v=='//'&&{__div=f}||{__concat=f}
  518.                    end
  519. F.M={C=>
  520.     C.EQ={">>","<<","&","|",unpack(C.EQ||{})}--additional equality
  521.     F.c[1](C)--enable core
  522.     @l=C.L
  523.     @r=C.R
  524.     l[#l].m={bor=1}
  525.     --on level open
  526.     l.o[#l.o+1]=o,t=>
  527.         /|o=="function"&&C.pv==2?l[#l].m.sk=1; -- curent value is function keyword and previous value was an operator -> mark function end on skip
  528.         t.m={bor=#r+2};
  529.     --function to correct priority of sequence (set on O and on W)
  530.     C.C.A.pc=o,w=>
  531.         @i=#r+2
  532.         @b=C.cv<2&&!l[#l].m.sk||o&&kp[o]--current value is equal to keyword or operator and has lower priority than bitwises
  533.         l[#l].m.sk=nil--reset end skip
  534.         /|b?l[#l].m={bor=i};--reset the starter table
  535.         /|b||o&&(" .. + -"):find(' '..o..' ',1,1)?l[#l].m.idiv=i;;--start of sequence and reset!
  536.     for k,v in pairs(bt)do
  537.         C.O[v]=C,o,w=>
  538.             @p=OBJ(r[#r])-- grep the value, skip the comments
  539.             /|v=='~'&&--posible unary operator
  540.                 ((p:find"[^%)}%]'\"%P]"&&!p:find"%[=*%[")||--there is no breaket or string before op or string
  541.                 Kb[p]||kp[p])?-- there is no keyword before op
  542.                     r[#r+1]="cssc.mt.bnot^" $;--bnot located. Insert and return...
  543.             table.insert(r,l[#l].m[k]||l[#l].m.bor||l[#l].st,"setmetatable({")
  544.             r[#r+1]="},cssc.mt."..k..(v=='//'&&')/'||')..')
  545.             @i=#r+1
  546.             @l=l[#l]
  547.             /|v=='|'?l.m.bxor=i;
  548.             /|v:find'[|~]'?l.m.band=i;
  549.             /|v:find'[|~&]'?l.m.shl,l.m.shr,l.m.idiv=i,i,i;-- Full support of bitwizes!111 Finaly!
  550.             /|v:find"([><])%1"?l.m.idiv=i;;-- Full support of idiv
  551.                        end;}
  552. end
  553.  
  554. --DEFAULT: ALL INCLUSIVE (E feature disabled!)
  555. F.A={C=>
  556.  F.M[1](C) -- Lua5.3 opts
  557.  F.K[1](C) -- Keyword shortcuts
  558.  F.IS[1](C)-- IS keyword
  559.  F.N[1](C) -- nil forgiving operators
  560.  F.C[1](C) -- X= operators
  561.  F.D[1](C) -- default function arguments
  562.  F.b[1](C) -- octal and binary number formats
  563.  C.O['..']=' ..' --fix number concatenation bug
  564.  for K,V in pairs{F.K,F.F}do
  565.      for k,v in pairs(V)do
  566.          C.O[k]=v
  567.      end
  568.  end
  569.  ;}
  570.  
  571. _G.cssc={features=F,load=L,nilF=N,mt=M,version="3.5-beta",creator="M.A.G.Gen.",_CSSC=env,_ENV=_ENV,path=";",addPath=adp,is=is,q_eq=qeq,env=env}
  572. ]=],"SuS",nil,_ENV)--]=]
  573. b=b and error(b)
  574. a=a and a(...)
  575. ]=============] -- 13
  576. cssc_api["Minified"]=[==============[
  577. K={}
  578. Ks="if function for while repeat elseif else do then end until local return in break "
  579. Kb={}
  580. Ks:gsub("(%S+)( )", function (x,s)K[#K+1]=s..x..s Kb[x]=#K end )
  581. NL=load
  582. a,b=NL(([=[
  583. local l=C,o)
  584. local i,a,e,p=#R,1
  585. e=R[i]
  586. p=e"^%)%s*""" "("
  587. while i>0(#p>0(a(e:[%w_]+" "."e) ","e) #p<1 not e"^%(%s*")do
  588. i,a=i-1,not a
  589. e=R[i] end
  590. .insert(R,#p<1i i+1,K[2]p)
  591. R[#R+1]=(#p>0")" "")(o1,1)"-"K[13] "")
  592. if L
  593. pv=2
  594. L("function",1)
  595. end
  596. end
  597. F={
  598. E={ ["/|"]=K[1],
  599. ["?"]=K[9],
  600. [":|"]=K[6],
  601. ["\\|"]=K[7]},
  602. K={ ["@"]=K[12],
  603. ["$"]=K[13],
  604. ["||"]=" ",
  605. ["&&"]="",
  606. ["!"]=" not ",
  607. [";"]=K[10]},
  608. F={ ["->"]=l,
  609. ["=>"]=l}
  610. }
  611. L=x,name,mode,env)
  612. if x)"string"
  613. local c=x:^<.->" x:^#!.-\n?<.->"
  614. if c
  615. local po,R,O,C,s,t,a,b,l,e="",{""},{['"']=),["\0"]=C) local r=R r[#r]=r[#r]" "(.remove(c,1) ""),['']='',['.']='.'}
  616. x=x#c+1)
  617. C={O=O,C=),R=R,F={},c={},l=1,pv=1}
  618. fK,V in c:g([%w_]+)%(?([%w_. ]*)" if F[K]
  619. fF[K])do O[k]=v end
  620. l=F[K][1]F[K][1](C,V,x,name,mode,env)
  621. if ll
  622. 
  623. end
  624. O[1]=
  625. l=#x+1
  626. f,i in x:g([%s!#-&(-/:-@\\-^{-~`]*%[?=*[%['\"]?%s*)([%w_]*[^%w%p%[-`{-~\\-_%s]*[^\n%S]*)()"
  627. o:gsub("\n",)l=l+1)
  628. if s then
  629. a,b,e=o(#s<2"(\\*[\n"s"])%s*" "(%]=*%])%s*")
  630. if a(#s<2(s"\n" #e%2>0) #s#e) il
  631. b=b i
  632. t=to0,b)
  633. if cc=c
  634. 
  635. t=C(,t,i)t
  636. c=R
  637. end
  638. c[#c+1]=t
  639. o=poob+1)
  640. s,t=
  641. 
  642. t=tow
  643. end
  644. end
  645. if not s then
  646. o=o:gsub("-%-%s-\n","\n")
  647. c=o:-%-%[?=*%[?"
  648. s=o:%[=*%["o:['\"]"
  649. if c s then
  650. a=o(c s,1,1)
  651. s=c(c3)ss "\n") s
  652. t,w=oa)w,""
  653. o=o0,a-1)(c"\0" '"')
  654. po=c(o "") ""
  655. end
  656. if not c il then
  657. while #o>0  a=o:^%s*"
  658. R[#R]=R[#R]a
  659. o=o#a+1)
  660. fi=3,1,-1 do
  661. a=o1,i)
  662. b=O[a] i<2a
  663. if b#o>0
  664. b=C(a,b,i) b
  665. if 7>#b)
  666. R[#R+1]=b
  667. o=oi+1)
  668. 
  669. b={b(C,,i)}
  670. =b[1] oi+1),b[2] w
  671. end
  672. break
  673. end
  674. end
  675. end
  676. if #w>0 then
  677. w=C(,w,i) w
  678. R[#R+1]=w
  679. end
  680. end
  681. 
  682. end
  683. fF) local a,n,m,e=v(x,name,mode,env)
  684. if rta,n
  685. x=a x
  686. name=n name
  687. mode=m mode
  688. env=e env
  689. end
  690. x=.concat(R)
  691. if mode"c"R
  692. end
  693. end
  694. NL(x,name,mode,env)
  695. end
  696. F.K[';']=C,)
  697. local a,p=o:(;*) *([%S\n]?)%s*"
  698. if #p>0p~="(" #a>1
  699. fi=1,#a  R[#R+1]=K[10]
  700. if LL("end")
  701. end
  702.  R[#R+1]=";"
  703. o#a+1)
  704. OBJ=o)o)'string'o:%S+" ""
  705. do o=s({},{__index=os})
  706. clone=value,arg)
  707. local D,v,a=debug,value,arg {}
  708. local t=v)
  709. if t"function"
  710. local I=D.getinfo(v)
  711. local f=NL(t.dump(v),I.source,,a.env getfenv(v))
  712. fi=1,I.nups  if a.refD.upvaluejoin(f,i,v,i)
  713.  local n,d=D.getupvalue(v,i)D.setupvalue(f,i,d)
  714. f
  715. if t""
  716. t={}fv)do t[k]=v
  717. s(t,a.meta g(v))m={__index=_G}
  718. env={os=o,
  719. clone=clone,
  720. load=L,
  721. loadfile=clone(loadfile,{env=s({load=L},m)}),
  722. include=name,force)
  723. local e=getfenv(2)
  724. local r=e.require
  725. if not rerror("Unable to include '"name"', _ENV has no require function!",2)
  726. local f,t=pcall(r,name)
  727. if not ferror(t,2)
  728. ft) e[k]= not forcee[k] v
  729. t}
  730. e={env=s({loadfile=env.loadfile},m)}
  731. o.run=clone(os.run,e)
  732. o.loadAPI=clone(os.loadAPI,e)
  733. end
  734. err=C,s)err=err "SuS["l"]:"s
  735. F.err={C)
  736. F.err=)
  737. if errrt=1 ,err}
  738. F.pre={C,V,x,n,m,e)
  739. if not cssc.preloadcssc.preload={}
  740. local P=cssc.preload
  741. if P[V]NL(P[V],n,m,e)
  742. F.pre=)P[V]=.concat(R)}
  743. F.dbg={C,V)
  744. local v=V
  745. F.dbg=x,n,m)
  746. if v"P"require"cc.pretty".pretty_print(R)
  747. if v"p"print(.concat(R))
  748. if m"c"rt=1R
  749. if m"s"rt=1.concat(R)}
  750. F.b={C)
  751. F.c
  752. W.b=)
  753. local a,b,c,r,t=w:^0([bo])(%d*)([eE]?.*)"
  754. if bR[#R]"."t,b,c=b,w:(%d+)([eE]?.*)"
  755.  b=
  756. if b
  757. t,r=t (a>"b""8" "2"),0
  758. fi,k in b:g()(.)" if k>=terr(C,"This is not a valid number: 0"abc)
  759. r=r+k*t^(#b-i)
  760. end
  761. r=btostring(r/t^#b)3) r
  762. b= not b#c<1t 
  763. rc}
  764.  N=fs.combine
  765. adp=str,full)cssc.path=fullcssc.pathN(str,"?;")N(str,"?.lua;")N(str,"?/init.lua;")cssc.pathstr";"
  766. ATP=C,wt,on)err(C,"Attempt to perform '"wt"' on '"on"'!")
  767. F.c={C)
  768. if CR
  769. CR=1
  770. L={{st=1,t="main"},o={},c={}}
  771. local l=L
  772. local r=R
  773. fk in("=~<>"):gfind"."do k=k'='O[k]=k end
  774. local f=T,,i)fT)do w=v(,i)ww
  775. local pt=t) local r=""fk in pairs(t)do r=rk"' '"endr1,-7)
  776. C={W={},O={},A={},K={},o={['and']=1,['or']=1,['not']=1},
  777. l={["for"]="do",["while"]="do",["repeat"]="until",["if"]="then",["then"]={[""]=1,["if"]=1,["end"]=1},["if"]="then",[""]="end",["do"]="end",["function"]="end",["{"]="}",["("]=")",["["]="]"},
  778. L=o,v) if vl[#l+1]=f(l.o,o,{t=o})
  779.  local e=l[t]
  780. local t=#e)5
  781. if not tee~=o t not e[o]err(C,"Expected '"(tept(e) e)"' after '"t"' but got '"o"'!")
  782. if #l<2err(C,"Unexpected '"o"'!")
  783. local cl=l[#l]
  784. l[#l]=#l<2l[#l] 
  785. f(l.c,o,cl)}
  786. local c=C
  787. F[1]=x,n,m,e)
  788. if #l>1err(C,"Unclosed construction! Missing '"(c.l[t] "end")"'!"#l)
  789. local p=ee.package
  790. if pp.path=p.pathcssc.path
  791. setfenv(p.loaders[2],s({loadfile=env.loadfile},{_index=_G}))
  792. fenv)do e[k]=rawget(e,k) vend 
  793. s(C,{__call=S,,i)
  794. if o'"' o'\0'
  795. pv=cv
  796. cv=
  797. if #w)6
  798. local ow=OBJ(w)
  799. local k=Kb[ow]
  800. if kcv=1
  801. if k>5k<12c.L(ow)
  802. if k<10c.L(ow,1)
  803. w=f(c.K,,i) w
  804. if c.o[ow]cv=2 w=f(c.O,,i) w
  805. if not cv
  806. if not ocv=w"^['\"%[]"6 3 w=f(c.W,,i) w
  807.  cv=o"^[%[%({]"4 o"^[%]%)}]"5 2
  808. if cv4c.L(o,1)
  809. if cv5c.L(o)
  810. w=f(c.O,,i) w
  811. w=f(c.A,,i) w
  812. w})
  813. l.o[#l.o+1]=o,t)
  814. local s=#r+1
  815. if pvpv<3st=s
  816. t.st=s+1
  817. c.W.st=)
  818. local p=OBJ(r[#r])
  819. if p"[.:]"#p<2
  820. if cv6pv>2
  821. st=#r+1
  822. }
  823. end
  824. UE=C,o)err(C,"Unexpected '"o"'!")
  825. F.D={C)
  826. F.c
  827. local l=L
  828. local r=R
  829. l.o[#l.o+1]=o,t)
  830. if t.t"function"t.ada=1
  831. if ada
  832. ada=
  833. if t.t"("t.da={}
  834. l.c[#l.c+1]=o,t)
  835. ada=
  836. if t.da#t.da>0t.t"("
  837. ")"
  838. t.da[#t.da].nd=t.da[#t.da].nd #r-1
  839. fi=#t.da,1,-1 
  840. local ob=r[t.da[i].st-1]
  841. "if "ob""ob"="
  842. fj=t.da[i].st,t.da[i].nd do r[j]end
  843. ""
  844. fj=t.da[i].nd,t.da[i].st,-1 do .remove(r,j)end
  845. end
  846. t.da=
  847. A.da=)A.da=)
  848. O.da=)
  849. local d=da
  850. if do';'UE(C,';')
  851. if d#d>0o','
  852. d[#d].nd=d[#d].nd #r
  853. O[":="]=C,)
  854. if not daUE(C,':=')
  855.  local d=da
  856. d[#d+1]={st=#r+1}
  857. }
  858. PAch=t)t"[{(%[]" t"if" t"if" t"for" t"while"
  859. doc,d=s
  860. d=c({},{__call=),__index=)})
  861. c=c({},{__index=))})
  862. N=o,i)
  863. if oic d
  864. if io[i]o c
  865. o
  866. F.N={C)
  867. F.c
  868. O.N=o) if F.N[o]cv=pv}
  869. fv,k in('.:"({'):gfind"()(.)" F.N['?'k]=C,)
  870. local r=R
  871. if #r<2 pv<3ATP(C,k,r[#r])
  872. if o3)"[^\0%s]"ATP(C,OBJ(o3)),k)
  873. .insert(R,L[#L].st," cssc.F(")
  874. v2",'"w"')" ')'
  875. if v1
  876. ci=#r
  877. pc=#r+2
  878. A.str=o)
  879. if pc<=#r print(cv,w,r[#r],r[#r-1],r[#r-2],#r,o)
  880. if cv>4 cv>3 not o'^[)%]}]'
  881. .insert(r,ci,",'"w"'")
  882. A.str=
  883. o2)
  884. end
  885. end
  886. F.K[1]=C)EQ={"&&","||",unpack(EQ {})}
  887. qeq=b,a) ab
  888.  a
  889. F.C={C)
  890. F.c
  891. EQ={"+","-","*","%","/","","^","?",unpack(EQ {})}
  892. local l=L
  893. local r=R
  894. A.br=)
  895. if br(pv3 pv>4)(cv1 cv3 (o',' o';'))
  896. br=
  897. ")"
  898. l.c[#l.c+1]=o,t) if t.br")"
  899. F.c=) if br")"
  900. local op=C,)
  901. local lt=t
  902. if PAch(lt)err(C,"Attempt to use X= operatin prohibited area! '"lt" *var* X= *val* "l[lt]"'")
  903. if OBJ(r[st-1] "")","err(C,"Comma detected! X= operators has no multiple assignments support!")
  904. if #r<2 pv<3ATP(C,k,r[#r])
  905. o=o:(.-)="
  906. "="(o"?""cssc.q_eq(" "")
  907. m={bor=#r+1}
  908. fi=st,#r-1 do r[i]end
  909. local t=#O[o])
  910. if o"?"","
  911. if t6O[o]
  912. if t3o
  913.  O[o](C,)
  914. if o~="?""("
  915. br=1
  916. m={bor=#r+1}
  917. fi=1,#EQ do O[EQ[i]"=" ]=opend
  918. }
  919. tof=o)(g(o) {}).__type o)is=s({},{__concat=v,a)s({a},
  920. {__concat=v,a)
  921. if a[1])""a=a[1]
  922. fi=1,#a  if tof(v)a[i]true
  923. end
  924. false})})
  925. _G.typeof=tof
  926. F.IS={C)
  927. F.c
  928. o['is']=1
  929. local l=L
  930. O[1]=)
  931. w=OBJ(w)
  932. if w'is'
  933. if #R<2 pv<3ATP(C,'is',R[#R])
  934. " cssc.is "}
  935. doB={}
  936. fbit32)do B[k]=v end
  937. B.idiv=a,b)math.floor(a/b)
  938. B.shl=B.lshift
  939. B.shr=B.rshiftbt={shl='<<',shr='>>',bxor='~',bor='|',band='&',idiv='//'}kp={}('and , = ; > < >= <= ~=  '):gsub("%S+",x)kp[x]=1) f=t,m)"Attempt to perform "t" bitwise operation on a "m" value"
  940. M={bnot=s({},{
  941. __pow=a,b)
  942. local m=(g(b) {}).bnot
  943. if mm(b)
  944. m=b)
  945. if m~='number'error(f('bitwise',m),3)
  946. B.bnot(b)})}
  947. fbt) local n='__'k
  948. local t='number'
  949. local e=v'//''idiv' 'bitwise'
  950. local f=a,b)
  951. local m=(g(a[1]) {})[n] (g(b) {})[n]
  952. if mm(a,b)
  953. m=a[1])
  954. m=mtb) m
  955. if m~=terror(f(e,m),3)
  956. B[k](a[1],b)
  957. M[k]=v'//'{__div=f} {__concat=f}
  958. end
  959. F.M={C)
  960. EQ={">>","<<","&","|",unpack(EQ {})}
  961. F.c
  962. local l=L
  963. local r=R
  964. m={bor=1}
  965. l.o[#l.o+1]=o,t)
  966. if o"function"pv2m.sk=1
  967. t.m={bor=#r+2}
  968. A.pc=)
  969. local i=#r+2
  970. local b=cv<2 not m.sk okp[o]
  971. m.sk=
  972. if bm={bor=i}
  973. if b o("  + -")(' 'o' ',1,1)m.idiv=i
  974. fbt) O[v]=C,)
  975. local p=OBJ(r[#r])
  976. if v'~'
  977. ((p"[^%)}%]'\"%P]" not p"%[=*%[") 
  978. Kb[p] kp[p])
  979. "cssc.mt.bnot^" 
  980. .insert(r,m[k] m.bst,"s({")
  981. "},cssc.mt."k(v'//'')/' ')')
  982. local i=#r+1
  983. local l=l[#l]
  984. if v'|'l.m.bxor=i
  985. if v'[|~]'l.m.band=i
  986. if v'[|~&]'l.m.shl,l.m.shr,l.m.idiv=i,i,i
  987. if v"([><])%1"l.m.idiv=i
  988. end }
  989. end
  990. F.A={C)
  991. F.M
  992. F.K
  993. F.IS
  994. F.N
  995. F.C
  996. F.D
  997. F.b
  998. O['']=' '
  999. fK,V in pairs{F.K,F.F} fV) O[k]=v
  1000. end
  1001. end
  1002. }
  1003. _G.cssc={features=F,load=L,F=N,mt=M,version="3.5-beta",creator="M.A.G.Gen.",_CSSC=env,_ENV=_ENV,path=";",addPath=adp,is=is,q_eq=qeq,env=env}
  1004. ]=]):gsub('.',{[""]=" function (",[""]="\
  1005. local ",[""]=" and ",[""]=" return ",[""]="or ",[""]="etmeta",[""]="table",[""]=" then ",[""]="\
  1006. if ",[""]=" end ",[""]=":find",[""]="match\"",[""]="else",[""]="[1](C)",[""]="k,v in pairs(",[""]="l[#l].",[""]=":sub(",[""]="C.",[""]="..",[""]="r[#r+1]=",[""]="==",[""]="type(",[""]="o,w",[""]="nil",[""]="do\
  1007. "}),'SuS',nil,_ENV)
  1008. b=b and error(b)
  1009. a=a and a()]==============] -- 14
  1010. env_pack["Original"]=[===============[
  1011. K={}
  1012. Ks="if function for while repeat elseif else do then end until local return in break "
  1013. Kb={}
  1014. Ks:gsub("(%S+)( )", function (x,s)K[#K+1]=s..x..s Kb[x]=#K end )
  1015. NL=load
  1016. a,b=NL(([=[
  1017. local l=C,o)
  1018. local i,a,e,p=#R,1
  1019. e=R[i]
  1020. p=e"^%)%s*""" "("
  1021. while i>0(#p>0(a(e:[%w_]+" "."e) ","e) #p<1 not e"^%(%s*")do
  1022. i,a=i-1,not a
  1023. e=R[i] end
  1024. .insert(R,#p<1i i+1,K[2]p)
  1025. R[#R+1]=(#p>0")" "")(o1,1)"-"K[13] "")
  1026. if L
  1027. pv=2
  1028. L("function",1)
  1029. end
  1030. end
  1031. F={
  1032. E={ ["/|"]=K[1],
  1033. ["?"]=K[9],
  1034. [":|"]=K[6],
  1035. ["\\|"]=K[7]},
  1036. K={ ["@"]=K[12],
  1037. ["$"]=K[13],
  1038. ["||"]=" ",
  1039. ["&&"]="",
  1040. ["!"]=" not ",
  1041. [";"]=K[10]},
  1042. F={ ["->"]=l,
  1043. ["=>"]=l}
  1044. }
  1045. L=x,name,mode,env)
  1046. if x)"string"
  1047. local c=x:^<.->" x:^#!.-\n?<.->"
  1048. if c
  1049. local po,R,O,C,s,t,a,b,l,e="",{""},{['"']=),["\0"]=C) local r=R r[#r]=r[#r]" "(.remove(c,1) ""),['']='',['.']='.'}
  1050. x=x#c+1)
  1051. C={O=O,C=),R=R,F={},c={},l=1,pv=1}
  1052. fK,V in c:g([%w_]+)%(?([%w_. ]*)" if F[K]
  1053. fF[K])do O[k]=v end
  1054. l=F[K][1]F[K][1](C,V,x,name,mode,env)
  1055. if ll
  1056. 
  1057. end
  1058. O[1]=
  1059. l=#x+1
  1060. f,i in x:g([%s!#-&(-/:-@\\-^{-~`]*%[?=*[%['\"]?%s*)([%w_]*[^%w%p%[-`{-~\\-_%s]*[^\n%S]*)()"
  1061. o:gsub("\n",)l=l+1)
  1062. if s then
  1063. a,b,e=o(#s<2"(\\*[\n"s"])%s*" "(%]=*%])%s*")
  1064. if a(#s<2(s"\n" #e%2>0) #s#e) il
  1065. b=b i
  1066. t=to0,b)
  1067. if cc=c
  1068. 
  1069. t=C(,t,i)t
  1070. c=R
  1071. end
  1072. c[#c+1]=t
  1073. o=poob+1)
  1074. s,t=
  1075. 
  1076. t=tow
  1077. end
  1078. end
  1079. if not s then
  1080. o=o:gsub("-%-%s-\n","\n")
  1081. c=o:-%-%[?=*%[?"
  1082. s=o:%[=*%["o:['\"]"
  1083. if c s then
  1084. a=o(c s,1,1)
  1085. s=c(c3)ss "\n") s
  1086. t,w=oa)w,""
  1087. o=o0,a-1)(c"\0" '"')
  1088. po=c(o "") ""
  1089. end
  1090. if not c il then
  1091. while #o>0  a=o:^%s*"
  1092. R[#R]=R[#R]a
  1093. o=o#a+1)
  1094. fi=3,1,-1 do
  1095. a=o1,i)
  1096. b=O[a] i<2a
  1097. if b#o>0
  1098. b=C(a,b,i) b
  1099. if 7>#b)
  1100. R[#R+1]=b
  1101. o=oi+1)
  1102. 
  1103. b={b(C,,i)}
  1104. =b[1] oi+1),b[2] w
  1105. end
  1106. break
  1107. end
  1108. end
  1109. end
  1110. if #w>0 then
  1111. w=C(,w,i) w
  1112. R[#R+1]=w
  1113. end
  1114. end
  1115. 
  1116. end
  1117. fF) local a,n,m,e=v(x,name,mode,env)
  1118. if rta,n
  1119. x=a x
  1120. name=n name
  1121. mode=m mode
  1122. env=e env
  1123. end
  1124. x=.concat(R)
  1125. if mode"c"R
  1126. end
  1127. end
  1128. NL(x,name,mode,env)
  1129. end
  1130. F.K[';']=C,)
  1131. local a,p=o:(;*) *([%S\n]?)%s*"
  1132. if #p>0p~="(" #a>1
  1133. fi=1,#a  R[#R+1]=K[10]
  1134. if LL("end")
  1135. end
  1136.  R[#R+1]=";"
  1137. o#a+1)
  1138. OBJ=o)o)'string'o:%S+" ""
  1139. do o=s({},{__index=os})
  1140. clone=value,arg)
  1141. local D,v,a=debug,value,arg {}
  1142. local t=v)
  1143. if t"function"
  1144. local I=D.getinfo(v)
  1145. local f=NL(t.dump(v),I.source,,a.env getfenv(v))
  1146. fi=1,I.nups  if a.refD.upvaluejoin(f,i,v,i)
  1147.  local n,d=D.getupvalue(v,i)D.setupvalue(f,i,d)
  1148. f
  1149. if t""
  1150. t={}fv)do t[k]=v
  1151. s(t,a.meta g(v))m={__index=_G}
  1152. env={os=o,
  1153. clone=clone,
  1154. load=L,
  1155. loadfile=clone(loadfile,{env=s({load=L},m)}),
  1156. include=name,force)
  1157. local e=getfenv(2)
  1158. local r=e.require
  1159. if not rerror("Unable to include '"name"', _ENV has no require function!",2)
  1160. local f,t=pcall(r,name)
  1161. if not ferror(t,2)
  1162. ft) e[k]= not forcee[k] v
  1163. t}
  1164. e={env=s({loadfile=env.loadfile},m)}
  1165. o.run=clone(os.run,e)
  1166. o.loadAPI=clone(os.loadAPI,e)
  1167. end
  1168. err=C,s)err=err "SuS["l"]:"s
  1169. F.err={C)
  1170. F.err=)
  1171. if errrt=1 ,err}
  1172. F.pre={C,V,x,n,m,e)
  1173. if not cssc.preloadcssc.preload={}
  1174. local P=cssc.preload
  1175. if P[V]NL(P[V],n,m,e)
  1176. F.pre=)P[V]=.concat(R)}
  1177. F.dbg={C,V)
  1178. local v=V
  1179. F.dbg=x,n,m)
  1180. if v"P"require"cc.pretty".pretty_print(R)
  1181. if v"p"print(.concat(R))
  1182. if m"c"rt=1R
  1183. if m"s"rt=1.concat(R)}
  1184. F.b={C)
  1185. F.c
  1186. W.b=)
  1187. local a,b,c,r,t=w:^0([bo])(%d*)([eE]?.*)"
  1188. if bR[#R]"."t,b,c=b,w:(%d+)([eE]?.*)"
  1189.  b=
  1190. if b
  1191. t,r=t (a>"b""8" "2"),0
  1192. fi,k in b:g()(.)" if k>=terr(C,"This is not a valid number: 0"abc)
  1193. r=r+k*t^(#b-i)
  1194. end
  1195. r=btostring(r/t^#b)3) r
  1196. b= not b#c<1t 
  1197. rc}
  1198.  N=fs.combine
  1199. adp=str,full)cssc.path=fullcssc.pathN(str,"?;")N(str,"?.lua;")N(str,"?/init.lua;")cssc.pathstr";"
  1200. ATP=C,wt,on)err(C,"Attempt to perform '"wt"' on '"on"'!")
  1201. F.c={C)
  1202. if CR
  1203. CR=1
  1204. L={{st=1,t="main"},o={},c={}}
  1205. local l=L
  1206. local r=R
  1207. fk in("=~<>"):gfind"."do k=k'='O[k]=k end
  1208. local f=T,,i)fT)do w=v(,i)ww
  1209. local pt=t) local r=""fk in pairs(t)do r=rk"' '"endr1,-7)
  1210. C={W={},O={},A={},K={},o={['and']=1,['or']=1,['not']=1},
  1211. l={["for"]="do",["while"]="do",["repeat"]="until",["if"]="then",["then"]={[""]=1,["if"]=1,["end"]=1},["if"]="then",[""]="end",["do"]="end",["function"]="end",["{"]="}",["("]=")",["["]="]"},
  1212. L=o,v) if vl[#l+1]=f(l.o,o,{t=o})
  1213.  local e=l[t]
  1214. local t=#e)5
  1215. if not tee~=o t not e[o]err(C,"Expected '"(tept(e) e)"' after '"t"' but got '"o"'!")
  1216. if #l<2err(C,"Unexpected '"o"'!")
  1217. local cl=l[#l]
  1218. l[#l]=#l<2l[#l] 
  1219. f(l.c,o,cl)}
  1220. local c=C
  1221. F[1]=x,n,m,e)
  1222. if #l>1err(C,"Unclosed construction! Missing '"(c.l[t] "end")"'!"#l)
  1223. local p=ee.package
  1224. if pp.path=p.pathcssc.path
  1225. setfenv(p.loaders[2],s({loadfile=env.loadfile},{_index=_G}))
  1226. fenv)do e[k]=rawget(e,k) vend 
  1227. s(C,{__call=S,,i)
  1228. if o'"' o'\0'
  1229. pv=cv
  1230. cv=
  1231. if #w)6
  1232. local ow=OBJ(w)
  1233. local k=Kb[ow]
  1234. if kcv=1
  1235. if k>5k<12c.L(ow)
  1236. if k<10c.L(ow,1)
  1237. w=f(c.K,,i) w
  1238. if c.o[ow]cv=2 w=f(c.O,,i) w
  1239. if not cv
  1240. if not ocv=w"^['\"%[]"6 3 w=f(c.W,,i) w
  1241.  cv=o"^[%[%({]"4 o"^[%]%)}]"5 2
  1242. if cv4c.L(o,1)
  1243. if cv5c.L(o)
  1244. w=f(c.O,,i) w
  1245. w=f(c.A,,i) w
  1246. w})
  1247. l.o[#l.o+1]=o,t)
  1248. local s=#r+1
  1249. if pvpv<3st=s
  1250. t.st=s+1
  1251. c.W.st=)
  1252. local p=OBJ(r[#r])
  1253. if p"[.:]"#p<2
  1254. if cv6pv>2
  1255. st=#r+1
  1256. }
  1257. end
  1258. UE=C,o)err(C,"Unexpected '"o"'!")
  1259. F.D={C)
  1260. F.c
  1261. local l=L
  1262. local r=R
  1263. l.o[#l.o+1]=o,t)
  1264. if t.t"function"t.ada=1
  1265. if ada
  1266. ada=
  1267. if t.t"("t.da={}
  1268. l.c[#l.c+1]=o,t)
  1269. ada=
  1270. if t.da#t.da>0t.t"("
  1271. ")"
  1272. t.da[#t.da].nd=t.da[#t.da].nd #r-1
  1273. fi=#t.da,1,-1 
  1274. local ob=r[t.da[i].st-1]
  1275. "if "ob""ob"="
  1276. fj=t.da[i].st,t.da[i].nd do r[j]end
  1277. ""
  1278. fj=t.da[i].nd,t.da[i].st,-1 do .remove(r,j)end
  1279. end
  1280. t.da=
  1281. A.da=)A.da=)
  1282. O.da=)
  1283. local d=da
  1284. if do';'UE(C,';')
  1285. if d#d>0o','
  1286. d[#d].nd=d[#d].nd #r
  1287. O[":="]=C,)
  1288. if not daUE(C,':=')
  1289.  local d=da
  1290. d[#d+1]={st=#r+1}
  1291. }
  1292. PAch=t)t"[{(%[]" t"if" t"if" t"for" t"while"
  1293. doc,d=s
  1294. d=c({},{__call=),__index=)})
  1295. c=c({},{__index=))})
  1296. N=o,i)
  1297. if oic d
  1298. if io[i]o c
  1299. o
  1300. F.N={C)
  1301. F.c
  1302. O.N=o) if F.N[o]cv=pv}
  1303. fv,k in('.:"({'):gfind"()(.)" F.N['?'k]=C,)
  1304. local r=R
  1305. if #r<2 pv<3ATP(C,k,r[#r])
  1306. if o3)"[^\0%s]"ATP(C,OBJ(o3)),k)
  1307. .insert(R,L[#L].st," cssc.F(")
  1308. v2",'"w"')" ')'
  1309. if v1
  1310. ci=#r
  1311. pc=#r+2
  1312. A.str=o)
  1313. if pc<=#r print(cv,w,r[#r],r[#r-1],r[#r-2],#r,o)
  1314. if cv>4 cv>3 not o'^[)%]}]'
  1315. .insert(r,ci,",'"w"'")
  1316. A.str=
  1317. o2)
  1318. end
  1319. end
  1320. F.K[1]=C)EQ={"&&","||",unpack(EQ {})}
  1321. qeq=b,a) ab
  1322.  a
  1323. F.C={C)
  1324. F.c
  1325. EQ={"+","-","*","%","/","","^","?",unpack(EQ {})}
  1326. local l=L
  1327. local r=R
  1328. A.br=)
  1329. if br(pv3 pv>4)(cv1 cv3 (o',' o';'))
  1330. br=
  1331. ")"
  1332. l.c[#l.c+1]=o,t) if t.br")"
  1333. F.c=) if br")"
  1334. local op=C,)
  1335. local lt=t
  1336. if PAch(lt)err(C,"Attempt to use X= operatin prohibited area! '"lt" *var* X= *val* "l[lt]"'")
  1337. if OBJ(r[st-1] "")","err(C,"Comma detected! X= operators has no multiple assignments support!")
  1338. if #r<2 pv<3ATP(C,k,r[#r])
  1339. o=o:(.-)="
  1340. "="(o"?""cssc.q_eq(" "")
  1341. m={bor=#r+1}
  1342. fi=st,#r-1 do r[i]end
  1343. local t=#O[o])
  1344. if o"?"","
  1345. if t6O[o]
  1346. if t3o
  1347.  O[o](C,)
  1348. if o~="?""("
  1349. br=1
  1350. m={bor=#r+1}
  1351. fi=1,#EQ do O[EQ[i]"=" ]=opend
  1352. }
  1353. tof=o)(g(o) {}).__type o)is=s({},{__concat=v,a)s({a},
  1354. {__concat=v,a)
  1355. if a[1])""a=a[1]
  1356. fi=1,#a  if tof(v)a[i]true
  1357. end
  1358. false})})
  1359. _G.typeof=tof
  1360. F.IS={C)
  1361. F.c
  1362. o['is']=1
  1363. local l=L
  1364. O[1]=)
  1365. w=OBJ(w)
  1366. if w'is'
  1367. if #R<2 pv<3ATP(C,'is',R[#R])
  1368. " cssc.is "}
  1369. doB={}
  1370. fbit32)do B[k]=v end
  1371. B.idiv=a,b)math.floor(a/b)
  1372. B.shl=B.lshift
  1373. B.shr=B.rshiftbt={shl='<<',shr='>>',bxor='~',bor='|',band='&',idiv='//'}kp={}('and , = ; > < >= <= ~=  '):gsub("%S+",x)kp[x]=1) f=t,m)"Attempt to perform "t" bitwise operation on a "m" value"
  1374. M={bnot=s({},{
  1375. __pow=a,b)
  1376. local m=(g(b) {}).bnot
  1377. if mm(b)
  1378. m=b)
  1379. if m~='number'error(f('bitwise',m),3)
  1380. B.bnot(b)})}
  1381. fbt) local n='__'k
  1382. local t='number'
  1383. local e=v'//''idiv' 'bitwise'
  1384. local f=a,b)
  1385. local m=(g(a[1]) {})[n] (g(b) {})[n]
  1386. if mm(a,b)
  1387. m=a[1])
  1388. m=mtb) m
  1389. if m~=terror(f(e,m),3)
  1390. B[k](a[1],b)
  1391. M[k]=v'//'{__div=f} {__concat=f}
  1392. end
  1393. F.M={C)
  1394. EQ={">>","<<","&","|",unpack(EQ {})}
  1395. F.c
  1396. local l=L
  1397. local r=R
  1398. m={bor=1}
  1399. l.o[#l.o+1]=o,t)
  1400. if o"function"pv2m.sk=1
  1401. t.m={bor=#r+2}
  1402. A.pc=)
  1403. local i=#r+2
  1404. local b=cv<2 not m.sk okp[o]
  1405. m.sk=
  1406. if bm={bor=i}
  1407. if b o("  + -")(' 'o' ',1,1)m.idiv=i
  1408. fbt) O[v]=C,)
  1409. local p=OBJ(r[#r])
  1410. if v'~'
  1411. ((p"[^%)}%]'\"%P]" not p"%[=*%[") 
  1412. Kb[p] kp[p])
  1413. "cssc.mt.bnot^" 
  1414. .insert(r,m[k] m.bst,"s({")
  1415. "},cssc.mt."k(v'//'')/' ')')
  1416. local i=#r+1
  1417. local l=l[#l]
  1418. if v'|'l.m.bxor=i
  1419. if v'[|~]'l.m.band=i
  1420. if v'[|~&]'l.m.shl,l.m.shr,l.m.idiv=i,i,i
  1421. if v"([><])%1"l.m.idiv=i
  1422. end }
  1423. end
  1424. F.A={C)
  1425. F.M
  1426. F.K
  1427. F.IS
  1428. F.N
  1429. F.C
  1430. F.D
  1431. F.b
  1432. O['']=' '
  1433. fK,V in pairs{F.K,F.F} fV) O[k]=v
  1434. end
  1435. end
  1436. }
  1437. _G.cssc={features=F,load=L,F=N,mt=M,version="3.5-beta",creator="M.A.G.Gen.",_CSSC=env,_ENV=_ENV,path=";",addPath=adp,is=is,q_eq=qeq,env=env}
  1438. ]=]):gsub('.',{[""]=" function (",[""]="\
  1439. local ",[""]=" and ",[""]=" return ",[""]="or ",[""]="etmeta",[""]="table",[""]=" then ",[""]="\
  1440. if ",[""]=" end ",[""]=":find",[""]="match\"",[""]="else",[""]="[1](C)",[""]="k,v in pairs(",[""]="l[#l].",[""]=":sub(",[""]="C.",[""]="..",[""]="r[#r+1]=",[""]="==",[""]="type(",[""]="o,w",[""]="nil",[""]="do\
  1441. "}),'SuS',nil,_ENV)
  1442. b=b and error(b)
  1443. a=a and a()]===============] -- 15
  1444. env_pack["Minified"]=[================[
  1445. K={}
  1446. Ks="if function for while repeat elseif else do then end until local return in break "
  1447. Kb={}
  1448. Ks:gsub("(%S+)( )", function (x,s)K[#K+1]=s..x..s Kb[x]=#K end )
  1449. NL=load
  1450. a,b=NL(([=[
  1451. local l=C,o)
  1452. local i,a,e,p=#R,1
  1453. e=R[i]
  1454. p=e"^%)%s*""" "("
  1455. while i>0(#p>0(a(e:[%w_]+" "."e) ","e) #p<1 not e"^%(%s*")do
  1456. i,a=i-1,not a
  1457. e=R[i] end
  1458. .insert(R,#p<1i i+1,K[2]p)
  1459. R[#R+1]=(#p>0")" "")(o1,1)"-"K[13] "")
  1460. if L
  1461. pv=2
  1462. L("function",1)
  1463. end
  1464. end
  1465. F={
  1466. E={ ["/|"]=K[1],
  1467. ["?"]=K[9],
  1468. [":|"]=K[6],
  1469. ["\\|"]=K[7]},
  1470. K={ ["@"]=K[12],
  1471. ["$"]=K[13],
  1472. ["||"]=" ",
  1473. ["&&"]="",
  1474. ["!"]=" not ",
  1475. [";"]=K[10]},
  1476. F={ ["->"]=l,
  1477. ["=>"]=l}
  1478. }
  1479. L=x,name,mode,env)
  1480. if x)"string"
  1481. local c=x:^<.->" x:^#!.-\n?<.->"
  1482. if c
  1483. local po,R,O,C,s,t,a,b,l,e="",{""},{['"']=),["\0"]=C) local r=R r[#r]=r[#r]" "(.remove(c,1) ""),['']='',['.']='.'}
  1484. x=x#c+1)
  1485. C={O=O,C=),R=R,F={},c={},l=1,pv=1}
  1486. fK,V in c:g([%w_]+)%(?([%w_. ]*)" if F[K]
  1487. fF[K])do O[k]=v end
  1488. l=F[K][1]F[K][1](C,V,x,name,mode,env)
  1489. if ll
  1490. 
  1491. end
  1492. O[1]=
  1493. l=#x+1
  1494. f,i in x:g([%s!#-&(-/:-@\\-^{-~`]*%[?=*[%['\"]?%s*)([%w_]*[^%w%p%[-`{-~\\-_%s]*[^\n%S]*)()"
  1495. o:gsub("\n",)l=l+1)
  1496. if s then
  1497. a,b,e=o(#s<2"(\\*[\n"s"])%s*" "(%]=*%])%s*")
  1498. if a(#s<2(s"\n" #e%2>0) #s#e) il
  1499. b=b i
  1500. t=to0,b)
  1501. if cc=c
  1502. 
  1503. t=C(,t,i)t
  1504. c=R
  1505. end
  1506. c[#c+1]=t
  1507. o=poob+1)
  1508. s,t=
  1509. 
  1510. t=tow
  1511. end
  1512. end
  1513. if not s then
  1514. o=o:gsub("-%-%s-\n","\n")
  1515. c=o:-%-%[?=*%[?"
  1516. s=o:%[=*%["o:['\"]"
  1517. if c s then
  1518. a=o(c s,1,1)
  1519. s=c(c3)ss "\n") s
  1520. t,w=oa)w,""
  1521. o=o0,a-1)(c"\0" '"')
  1522. po=c(o "") ""
  1523. end
  1524. if not c il then
  1525. while #o>0  a=o:^%s*"
  1526. R[#R]=R[#R]a
  1527. o=o#a+1)
  1528. fi=3,1,-1 do
  1529. a=o1,i)
  1530. b=O[a] i<2a
  1531. if b#o>0
  1532. b=C(a,b,i) b
  1533. if 7>#b)
  1534. R[#R+1]=b
  1535. o=oi+1)
  1536. 
  1537. b={b(C,,i)}
  1538. =b[1] oi+1),b[2] w
  1539. end
  1540. break
  1541. end
  1542. end
  1543. end
  1544. if #w>0 then
  1545. w=C(,w,i) w
  1546. R[#R+1]=w
  1547. end
  1548. end
  1549. 
  1550. end
  1551. fF) local a,n,m,e=v(x,name,mode,env)
  1552. if rta,n
  1553. x=a x
  1554. name=n name
  1555. mode=m mode
  1556. env=e env
  1557. end
  1558. x=.concat(R)
  1559. if mode"c"R
  1560. end
  1561. end
  1562. NL(x,name,mode,env)
  1563. end
  1564. F.K[';']=C,)
  1565. local a,p=o:(;*) *([%S\n]?)%s*"
  1566. if #p>0p~="(" #a>1
  1567. fi=1,#a  R[#R+1]=K[10]
  1568. if LL("end")
  1569. end
  1570.  R[#R+1]=";"
  1571. o#a+1)
  1572. OBJ=o)o)'string'o:%S+" ""
  1573. do o=s({},{__index=os})
  1574. clone=value,arg)
  1575. local D,v,a=debug,value,arg {}
  1576. local t=v)
  1577. if t"function"
  1578. local I=D.getinfo(v)
  1579. local f=NL(t.dump(v),I.source,,a.env getfenv(v))
  1580. fi=1,I.nups  if a.refD.upvaluejoin(f,i,v,i)
  1581.  local n,d=D.getupvalue(v,i)D.setupvalue(f,i,d)
  1582. f
  1583. if t""
  1584. t={}fv)do t[k]=v
  1585. s(t,a.meta g(v))m={__index=_G}
  1586. env={os=o,
  1587. clone=clone,
  1588. load=L,
  1589. loadfile=clone(loadfile,{env=s({load=L},m)}),
  1590. include=name,force)
  1591. local e=getfenv(2)
  1592. local r=e.require
  1593. if not rerror("Unable to include '"name"', _ENV has no require function!",2)
  1594. local f,t=pcall(r,name)
  1595. if not ferror(t,2)
  1596. ft) e[k]= not forcee[k] v
  1597. t}
  1598. e={env=s({loadfile=env.loadfile},m)}
  1599. o.run=clone(os.run,e)
  1600. o.loadAPI=clone(os.loadAPI,e)
  1601. end
  1602. err=C,s)err=err "SuS["l"]:"s
  1603. F.err={C)
  1604. F.err=)
  1605. if errrt=1 ,err}
  1606. F.pre={C,V,x,n,m,e)
  1607. if not cssc.preloadcssc.preload={}
  1608. local P=cssc.preload
  1609. if P[V]NL(P[V],n,m,e)
  1610. F.pre=)P[V]=.concat(R)}
  1611. F.dbg={C,V)
  1612. local v=V
  1613. F.dbg=x,n,m)
  1614. if v"P"require"cc.pretty".pretty_print(R)
  1615. if v"p"print(.concat(R))
  1616. if m"c"rt=1R
  1617. if m"s"rt=1.concat(R)}
  1618. F.b={C)
  1619. F.c
  1620. W.b=)
  1621. local a,b,c,r,t=w:^0([bo])(%d*)([eE]?.*)"
  1622. if bR[#R]"."t,b,c=b,w:(%d+)([eE]?.*)"
  1623.  b=
  1624. if b
  1625. t,r=t (a>"b""8" "2"),0
  1626. fi,k in b:g()(.)" if k>=terr(C,"This is not a valid number: 0"abc)
  1627. r=r+k*t^(#b-i)
  1628. end
  1629. r=btostring(r/t^#b)3) r
  1630. b= not b#c<1t 
  1631. rc}
  1632.  N=fs.combine
  1633. adp=str,full)cssc.path=fullcssc.pathN(str,"?;")N(str,"?.lua;")N(str,"?/init.lua;")cssc.pathstr";"
  1634. ATP=C,wt,on)err(C,"Attempt to perform '"wt"' on '"on"'!")
  1635. F.c={C)
  1636. if CR
  1637. CR=1
  1638. L={{st=1,t="main"},o={},c={}}
  1639. local l=L
  1640. local r=R
  1641. fk in("=~<>"):gfind"."do k=k'='O[k]=k end
  1642. local f=T,,i)fT)do w=v(,i)ww
  1643. local pt=t) local r=""fk in pairs(t)do r=rk"' '"endr1,-7)
  1644. C={W={},O={},A={},K={},o={['and']=1,['or']=1,['not']=1},
  1645. l={["for"]="do",["while"]="do",["repeat"]="until",["if"]="then",["then"]={[""]=1,["if"]=1,["end"]=1},["if"]="then",[""]="end",["do"]="end",["function"]="end",["{"]="}",["("]=")",["["]="]"},
  1646. L=o,v) if vl[#l+1]=f(l.o,o,{t=o})
  1647.  local e=l[t]
  1648. local t=#e)5
  1649. if not tee~=o t not e[o]err(C,"Expected '"(tept(e) e)"' after '"t"' but got '"o"'!")
  1650. if #l<2err(C,"Unexpected '"o"'!")
  1651. local cl=l[#l]
  1652. l[#l]=#l<2l[#l] 
  1653. f(l.c,o,cl)}
  1654. local c=C
  1655. F[1]=x,n,m,e)
  1656. if #l>1err(C,"Unclosed construction! Missing '"(c.l[t] "end")"'!"#l)
  1657. local p=ee.package
  1658. if pp.path=p.pathcssc.path
  1659. setfenv(p.loaders[2],s({loadfile=env.loadfile},{_index=_G}))
  1660. fenv)do e[k]=rawget(e,k) vend 
  1661. s(C,{__call=S,,i)
  1662. if o'"' o'\0'
  1663. pv=cv
  1664. cv=
  1665. if #w)6
  1666. local ow=OBJ(w)
  1667. local k=Kb[ow]
  1668. if kcv=1
  1669. if k>5k<12c.L(ow)
  1670. if k<10c.L(ow,1)
  1671. w=f(c.K,,i) w
  1672. if c.o[ow]cv=2 w=f(c.O,,i) w
  1673. if not cv
  1674. if not ocv=w"^['\"%[]"6 3 w=f(c.W,,i) w
  1675.  cv=o"^[%[%({]"4 o"^[%]%)}]"5 2
  1676. if cv4c.L(o,1)
  1677. if cv5c.L(o)
  1678. w=f(c.O,,i) w
  1679. w=f(c.A,,i) w
  1680. w})
  1681. l.o[#l.o+1]=o,t)
  1682. local s=#r+1
  1683. if pvpv<3st=s
  1684. t.st=s+1
  1685. c.W.st=)
  1686. local p=OBJ(r[#r])
  1687. if p"[.:]"#p<2
  1688. if cv6pv>2
  1689. st=#r+1
  1690. }
  1691. end
  1692. UE=C,o)err(C,"Unexpected '"o"'!")
  1693. F.D={C)
  1694. F.c
  1695. local l=L
  1696. local r=R
  1697. l.o[#l.o+1]=o,t)
  1698. if t.t"function"t.ada=1
  1699. if ada
  1700. ada=
  1701. if t.t"("t.da={}
  1702. l.c[#l.c+1]=o,t)
  1703. ada=
  1704. if t.da#t.da>0t.t"("
  1705. ")"
  1706. t.da[#t.da].nd=t.da[#t.da].nd #r-1
  1707. fi=#t.da,1,-1 
  1708. local ob=r[t.da[i].st-1]
  1709. "if "ob""ob"="
  1710. fj=t.da[i].st,t.da[i].nd do r[j]end
  1711. ""
  1712. fj=t.da[i].nd,t.da[i].st,-1 do .remove(r,j)end
  1713. end
  1714. t.da=
  1715. A.da=)A.da=)
  1716. O.da=)
  1717. local d=da
  1718. if do';'UE(C,';')
  1719. if d#d>0o','
  1720. d[#d].nd=d[#d].nd #r
  1721. O[":="]=C,)
  1722. if not daUE(C,':=')
  1723.  local d=da
  1724. d[#d+1]={st=#r+1}
  1725. }
  1726. PAch=t)t"[{(%[]" t"if" t"if" t"for" t"while"
  1727. doc,d=s
  1728. d=c({},{__call=),__index=)})
  1729. c=c({},{__index=))})
  1730. N=o,i)
  1731. if oic d
  1732. if io[i]o c
  1733. o
  1734. F.N={C)
  1735. F.c
  1736. O.N=o) if F.N[o]cv=pv}
  1737. fv,k in('.:"({'):gfind"()(.)" F.N['?'k]=C,)
  1738. local r=R
  1739. if #r<2 pv<3ATP(C,k,r[#r])
  1740. if o3)"[^\0%s]"ATP(C,OBJ(o3)),k)
  1741. .insert(R,L[#L].st," cssc.F(")
  1742. v2",'"w"')" ')'
  1743. if v1
  1744. ci=#r
  1745. pc=#r+2
  1746. A.str=o)
  1747. if pc<=#r print(cv,w,r[#r],r[#r-1],r[#r-2],#r,o)
  1748. if cv>4 cv>3 not o'^[)%]}]'
  1749. .insert(r,ci,",'"w"'")
  1750. A.str=
  1751. o2)
  1752. end
  1753. end
  1754. F.K[1]=C)EQ={"&&","||",unpack(EQ {})}
  1755. qeq=b,a) ab
  1756.  a
  1757. F.C={C)
  1758. F.c
  1759. EQ={"+","-","*","%","/","","^","?",unpack(EQ {})}
  1760. local l=L
  1761. local r=R
  1762. A.br=)
  1763. if br(pv3 pv>4)(cv1 cv3 (o',' o';'))
  1764. br=
  1765. ")"
  1766. l.c[#l.c+1]=o,t) if t.br")"
  1767. F.c=) if br")"
  1768. local op=C,)
  1769. local lt=t
  1770. if PAch(lt)err(C,"Attempt to use X= operatin prohibited area! '"lt" *var* X= *val* "l[lt]"'")
  1771. if OBJ(r[st-1] "")","err(C,"Comma detected! X= operators has no multiple assignments support!")
  1772. if #r<2 pv<3ATP(C,k,r[#r])
  1773. o=o:(.-)="
  1774. "="(o"?""cssc.q_eq(" "")
  1775. m={bor=#r+1}
  1776. fi=st,#r-1 do r[i]end
  1777. local t=#O[o])
  1778. if o"?"","
  1779. if t6O[o]
  1780. if t3o
  1781.  O[o](C,)
  1782. if o~="?""("
  1783. br=1
  1784. m={bor=#r+1}
  1785. fi=1,#EQ do O[EQ[i]"=" ]=opend
  1786. }
  1787. tof=o)(g(o) {}).__type o)is=s({},{__concat=v,a)s({a},
  1788. {__concat=v,a)
  1789. if a[1])""a=a[1]
  1790. fi=1,#a  if tof(v)a[i]true
  1791. end
  1792. false})})
  1793. _G.typeof=tof
  1794. F.IS={C)
  1795. F.c
  1796. o['is']=1
  1797. local l=L
  1798. O[1]=)
  1799. w=OBJ(w)
  1800. if w'is'
  1801. if #R<2 pv<3ATP(C,'is',R[#R])
  1802. " cssc.is "}
  1803. doB={}
  1804. fbit32)do B[k]=v end
  1805. B.idiv=a,b)math.floor(a/b)
  1806. B.shl=B.lshift
  1807. B.shr=B.rshiftbt={shl='<<',shr='>>',bxor='~',bor='|',band='&',idiv='//'}kp={}('and , = ; > < >= <= ~=  '):gsub("%S+",x)kp[x]=1) f=t,m)"Attempt to perform "t" bitwise operation on a "m" value"
  1808. M={bnot=s({},{
  1809. __pow=a,b)
  1810. local m=(g(b) {}).bnot
  1811. if mm(b)
  1812. m=b)
  1813. if m~='number'error(f('bitwise',m),3)
  1814. B.bnot(b)})}
  1815. fbt) local n='__'k
  1816. local t='number'
  1817. local e=v'//''idiv' 'bitwise'
  1818. local f=a,b)
  1819. local m=(g(a[1]) {})[n] (g(b) {})[n]
  1820. if mm(a,b)
  1821. m=a[1])
  1822. m=mtb) m
  1823. if m~=terror(f(e,m),3)
  1824. B[k](a[1],b)
  1825. M[k]=v'//'{__div=f} {__concat=f}
  1826. end
  1827. F.M={C)
  1828. EQ={">>","<<","&","|",unpack(EQ {})}
  1829. F.c
  1830. local l=L
  1831. local r=R
  1832. m={bor=1}
  1833. l.o[#l.o+1]=o,t)
  1834. if o"function"pv2m.sk=1
  1835. t.m={bor=#r+2}
  1836. A.pc=)
  1837. local i=#r+2
  1838. local b=cv<2 not m.sk okp[o]
  1839. m.sk=
  1840. if bm={bor=i}
  1841. if b o("  + -")(' 'o' ',1,1)m.idiv=i
  1842. fbt) O[v]=C,)
  1843. local p=OBJ(r[#r])
  1844. if v'~'
  1845. ((p"[^%)}%]'\"%P]" not p"%[=*%[") 
  1846. Kb[p] kp[p])
  1847. "cssc.mt.bnot^" 
  1848. .insert(r,m[k] m.bst,"s({")
  1849. "},cssc.mt."k(v'//'')/' ')')
  1850. local i=#r+1
  1851. local l=l[#l]
  1852. if v'|'l.m.bxor=i
  1853. if v'[|~]'l.m.band=i
  1854. if v'[|~&]'l.m.shl,l.m.shr,l.m.idiv=i,i,i
  1855. if v"([><])%1"l.m.idiv=i
  1856. end }
  1857. end
  1858. F.A={C)
  1859. F.M
  1860. F.K
  1861. F.IS
  1862. F.N
  1863. F.C
  1864. F.D
  1865. F.b
  1866. O['']=' '
  1867. fK,V in pairs{F.K,F.F} fV) O[k]=v
  1868. end
  1869. end
  1870. }
  1871. _G.cssc={features=F,load=L,F=N,mt=M,version="3.5-beta",creator="M.A.G.Gen.",_CSSC=env,_ENV=_ENV,path=";",addPath=adp,is=is,q_eq=qeq,env=env}
  1872. ]=]):gsub('.',{[""]=" function (",[""]="\
  1873. local ",[""]=" and ",[""]=" return ",[""]="or ",[""]="etmeta",[""]="table",[""]=" then ",[""]="\
  1874. if ",[""]=" end ",[""]=":find",[""]="match\"",[""]="else",[""]="[1](C)",[""]="k,v in pairs(",[""]="l[#l].",[""]=":sub(",[""]="C.",[""]="..",[""]="r[#r+1]=",[""]="==",[""]="type(",[""]="o,w",[""]="nil",[""]="do\
  1875. "}),'SuS',nil,_ENV)
  1876. b=b and error(b)
  1877. a=a and a()]================]-- 16
  1878. --CODE PART END
  1879.  
  1880. --LZSS START
  1881. do
  1882. local POS_BITS = 12
  1883. local LEN_BITS = 16 - POS_BITS
  1884. local POS_SIZE = bit32.lshift(1,POS_BITS)
  1885. local LEN_SIZE = bit32.lshift(1,LEN_BITS)
  1886. local LEN_MIN = 3
  1887. function lzss_api.pack(input)
  1888.     local offset, output = 1, {}
  1889.     local window = ''
  1890.  
  1891.     local function search()
  1892.         for i = LEN_SIZE + LEN_MIN - 1, LEN_MIN, -1 do
  1893.             local str = string.sub(input, offset, offset + i - 1)
  1894.             local pos = string.find(window, str, 1, true)
  1895.             if pos then
  1896.                 return pos, str
  1897.             end
  1898.         end
  1899.     end
  1900.  
  1901.     while offset <= #input do
  1902.         local flags, buffer = 0, {}
  1903.  
  1904.         for i = 0, 7 do
  1905.             if offset <= #input then
  1906.                 local pos, str = search()
  1907.                 if pos and #str >= LEN_MIN then
  1908.                     local tmp = bit32.bor(bit32.lshift(pos-1,LEN_BITS), #str - LEN_MIN)
  1909.                     buffer[#buffer + 1] = string.pack('>I2', tmp)
  1910.                 else
  1911.                     flags = bit32.bor(flags,bit32.lshift(1,i))
  1912.                     str = string.sub(input, offset, offset)
  1913.                     buffer[#buffer + 1] = str
  1914.                 end
  1915.                 window = string.sub(window .. str, -POS_SIZE)
  1916.                 offset = offset + #str
  1917.             else
  1918.                 break
  1919.             end
  1920.         end
  1921.  
  1922.         if #buffer > 0 then
  1923.             output[#output + 1] = string.char(flags)
  1924.             output[#output + 1] = table.concat(buffer)
  1925.         end
  1926.     end
  1927.  
  1928.     return table.concat(output)
  1929. end
  1930.  
  1931. function lzss_api.unpack(input)
  1932.     local offset, output = 1, {}
  1933.     local window = ''
  1934.  
  1935.     while offset <= #input do
  1936.         local flags = string.byte(input, offset)
  1937.         offset = offset + 1
  1938.  
  1939.         for i = 1, 8 do
  1940.             local str = nil
  1941.             if bit32.band(flags,1) ~= 0 then
  1942.                 if offset <= #input then
  1943.                     str = string.sub(input, offset, offset)
  1944.                     offset = offset + 1
  1945.                 end
  1946.             else
  1947.                 if offset + 1 <= #input then
  1948.                     local tmp = string.unpack('>I2', input, offset)
  1949.                     offset = offset + 2
  1950.                     local pos = bit32.rshift(tmp,LEN_BITS) + 1
  1951.                     local len = bit32.band(tmp,LEN_SIZE - 1) + LEN_MIN
  1952.                     str = string.sub(window, pos, pos + len - 1)
  1953.                 end
  1954.             end
  1955.             flags = bit32.rshift(flags,1)
  1956.             if str then
  1957.                 output[#output + 1] = str
  1958.                 window = string.sub(window .. str, -POS_SIZE)
  1959.             end
  1960.         end
  1961.     end
  1962.  
  1963.     return table.concat(output)
  1964. end
  1965.  
  1966. end
  1967.  
  1968. --LZSS-SEP START
  1969. function lzss_sep()
  1970. local extractor_base=[==[P=P:sub(SiZ,ZiS)while#P>=o do f=P:byte(o)o=o+1
  1971. for _=0,7 do s=nil
  1972. if 0<A(f,1)then
  1973. if#P>=o then s=S(P,o,o)o=o+1
  1974. end
  1975. elseif#P>=o+1 then
  1976. t=('>I2'):unpack(P,o)p=1+R(t,4)s=S(w,p,p+A(t,15)+2)o=o+2
  1977. end
  1978. f=R(f,1)if s then w=S(w..s,-4096)r=r..s end
  1979. end
  1980. end
  1981. return load(r,O,nil,_ENV)(...)--[]==]
  1982.  
  1983. --default extractor (can start from file only, but smaller)
  1984. local extractor_def =[==[local D,A,R,L,o,r,w,f,t,p,s,S,O,P=debug or{},bit32.band,bit32.rshift,shell,1,'',''S=r.sub
  1985. O=L and"@/"..L.resolveProgram(arg[0])or(D.getinfo or r.char)(1).source or""D,L=io.open(S(O,2),'rb')L=L and error(L)P=D:read"*a"D:close()]==]
  1986.  
  1987. local eq_count=0
  1988. local before=cssc_api["Minified"]
  1989. local prog=lzss.pack(before)
  1990. local extractor = extractor_def..extractor_base
  1991. -- make container for compressed code
  1992. local k=false
  1993. repeat
  1994.    if prog:find('([%[%]])'..("="):rep(eq_count)..'%1') then
  1995.        eq_count=eq_count+1
  1996.    else
  1997.        k=true
  1998.    end
  1999. until k
  2000.  
  2001. cssc_api["LZSS-SEP"]=extractor:gsub("SiZ",#extractor+2+eq_count):gsub("ZiS",("%.2d"):format(-3-eq_count))..("="):rep(eq_count).."["..prog.."]"..("="):rep(eq_count).."]"
  2002.  
  2003. end
  2004. --LZSS-SEP END
  2005.  
  2006. --LZSS-HASH
  2007. function lzss_hash()
  2008.  
  2009. cssc_api["LZSS"]="#!lzss\n"..lzss.pack(cssc_api["Minified"])
  2010.  
  2011. end
  2012. --LZSS END
  2013. ------------------------------------------------------------------------------------
  2014. function install(cssc_folder,type_api,path1,path2,st_path,env_path)--install
  2015.    local file1,file2,st_file,env_file
  2016.    
  2017.    path2=path2 or error"cssc_api path not specified!"
  2018.    file2,err=fs.open(path2,type_api:find"LZSS" and "wb" or "w")--cssc_api
  2019.    err=err and error("CSSC> API install error:\n"..err)
  2020.    file2.write(cssc_api[type_api])
  2021.    file2.close()
  2022.    fs.makeDir(fs.combine(cssc_folder,"modules"))
  2023.    
  2024.    if path1 then --optional (program)
  2025.        file1,err=fs.open(path1,"w")
  2026.        err=err and error("CSSC> Program install error:\n"..err)
  2027.        file1.write(cssc_prog_code)
  2028.        file1.close()
  2029.    end
  2030.    
  2031.    if st_path then --optional (startup)
  2032.        st_file,err=fs.open(st_path,"w")
  2033.        err=err and error("CSSC> Startup install error:\n"..err)
  2034.        st_file.write((path1 and startup or startup_small):gsub("CSSC_PATH",fs.combine(cssc_folder).."/"))
  2035.        st_file.close()
  2036.    end
  2037.    
  2038.    if env_path then --optional (env_pack)
  2039.        st_file,err=fs.open(env_path,type_api:find"LZSS" and "wb" or "w")
  2040.        err=err and error("Startup: "..err)
  2041.        env_file.write(env_pack[type_api])
  2042.        env_file.close()
  2043.    end
  2044. end
  2045. ------------------------------------------------------------------------------------
  2046. --GUI CONTROL
  2047. local skip_animations=false
  2048. local skip_desc=false
  2049. local skip_licence=false
  2050. local skip_timer=false
  2051. do
  2052.    local i=1
  2053.    while i<=#tArgs do
  2054.        if tArgs[i]=="-SA" or tArgs[i]=="--skip-animations" then
  2055.            skip_animations=true
  2056.            table.remove(tArgs,i)
  2057.        elseif tArgs[i]=="-SD" or tArgs[i]=="--skip-description" then
  2058.            skip_desc=true
  2059.            table.remove(tArgs,i)
  2060.        elseif tArgs[i]=="-SL" or tArgs[i]=="--skip-licence" then
  2061.            skip_licence=true
  2062.            table.remove(tArgs,i)
  2063.        elseif tArgs[i]=="-ST" or tArgs[i]=="--skip-timer" then
  2064.            skip_timer=true
  2065.            table.remove(tArgs,i)
  2066.        else
  2067.            i=i+1
  2068.        end
  2069.    end
  2070. end
  2071.  
  2072. --SILENT MODE
  2073. if #tArgs>0 then
  2074.    local type_api="LZSS-SEP"
  2075.    local path_to_cssc
  2076.    local path_to_startup
  2077.    local install_prog=false
  2078.    for i=1,#tArgs do
  2079.        if tArgs[i]=="--help" or tArgs[i]=="-H" then
  2080.            print("Usage:\n"..
  2081.                  "  -H  --help --Show this message and exit\n"..
  2082.                  "  -P=*path* --path=*path*\n"..
  2083.                  "        --Set path to installation folder\n"..
  2084.                  "  -S=*path* --startup=*path*\n"..
  2085.                  "        --Enable startup and set the name of startup file\n"..
  2086.                  "  -P  --program\n"..
  2087.                  "        --Enable launching LZSS from shell\n"..
  2088.                  "  -M  --minified\n"..
  2089.                  "        --Set API version to minified\n"..
  2090.                  "  -O  --original\n"..
  2091.                  "        --Set API version to original\n"..
  2092.                  "  -L  --lzss\n"..
  2093.                  "        --Set API version to LZSS archive (LZSS Required)\n"..
  2094.                  "  -S  --lzss-sep  [Default API]\n"..
  2095.                  "        --Set API version to self-extracting archive\n"..
  2096.                  "\n"..
  2097.                  "  -SD --skip-description\n"..
  2098.                  "  -SL --skip-licence\n"..
  2099.                  "  -ST --skip-timer\n")
  2100.            return
  2101.        elseif tArgs[i]:find"^%-%-path=" or tArgs[i]:find"^%-P=" then
  2102.            path_to_cssc=tArgs[i]:match"=(.+)$"
  2103.            print("CSSC> path:",path_to_cssc)
  2104.        elseif tArgs[i]:find"^%-%-startup=" or tArgs[i]:find"^%-S=" then
  2105.            path_to_startup=tArgs[i]:match"=(.+)$"
  2106.            print("CSSC> startup:",path_to_startup)
  2107.        elseif tArgs[i]=="--program" or tArgs[i]=="-P" then
  2108.            install_prog=true
  2109.            print("CSSC> launcher: enabled")
  2110.        elseif tArgs[i]=="--original" or tArgs[i]=="-O" then
  2111.            type_api="Original"
  2112.            print("CSSC> API:",type_api)
  2113.        elseif tArgs[i]=="--minified" or tArgs[i]=="-M" then
  2114.            type_api="Minified"
  2115.            print("CSSC> API:",type_api)
  2116.        elseif tArgs[i]=="--lzss" or tArgs[i]=="-L" then
  2117.            type_api="LZSS"
  2118.            print("CSSC> API:",type_api)
  2119.        elseif tArgs[i]=="--lzss-sep" or tArgs[i]=="-S" then
  2120.            type_api="LZSS-SEP"
  2121.            print("CSSC> API:",type_api)
  2122.        else
  2123.            error("Unexpected argument: "..tArgs[i])
  2124.        end
  2125.    end
  2126.    if not path_to_cssc then error"Path to instalation directory not set! Use <-P=*path_to_dir*> or <--path=*path_to_dir*>.\nP.S:(You can launch cssc_install with no args to use GUI)"end
  2127.    print("\nCSSC> API:",fs.combine(path_to_cssc,"cssc_api.lua"))
  2128.    install(path_to_cssc, type_api ,install_prog and fs.combine(path_to_cssc,"cssc.lua") or nil ,fs.combine(path_to_cssc,"cssc_api.lua") , path_to_startup)
  2129.    print("CSSC> Instalation complete...")
  2130.    print("CSSC> Please reload OS...")
  2131.    return
  2132. end
  2133. --SILENT MODE END
  2134.  
  2135. -- MAIN PROGRAM PART
  2136. function Main() --that part will be launched after all UI functions will be load
  2137.    local act,_,scroll_box="done"
  2138.    savePal()
  2139.    if not skip_animations then
  2140.        -- Splash Screen
  2141.        sleep(0.2)
  2142.        Splash_Screen() --show the logo
  2143.        term.setBackgroundColor(colors.lightBlue)--restore color
  2144.        term.clear()
  2145.        --paintutils.drawFilledBox(1,1,maxX,maxY)
  2146.        sleep(0.2)
  2147.    end
  2148.    
  2149.    if not skip_desc then
  2150.        --Show description
  2151.        PrimeUI.clear()
  2152.        make_gui()
  2153.        paintutils.drawFilledBox(4,5,max_x-x+3,max_y-y+4,colors.white)
  2154.        scroll_box=PrimeUI.scrollBox(main,5,5,max_x-x-1, max_y-y,999,true,true,colors.blue,colors.white)
  2155.        PrimeUI.drawText(scroll_box,description,true,colors.brown,colors.white)
  2156.        _,act = PrimeUI.run()
  2157.        --local ind=1
  2158.    end
  2159.  
  2160.    --Show Licence (with timer)
  2161.    if act=="done" and not skip_licence then
  2162.        PrimeUI.clear()
  2163.        local time=skip_timer and 0 or 3--time to accept
  2164.        make_gui("license")
  2165.        paintutils.drawFilledBox(4,5,max_x-x+3,max_y-y+4,colors.white)
  2166.        local is_active={active=false}
  2167.        scroll_box=PrimeUI.scrollBox(main,5,5,max_x-x-1, max_y-y,999,true,true,colors.blue,colors.white)
  2168.        PrimeUI.drawText(scroll_box,license,true,colors.brown,colors.white)
  2169.        PrimeUI.button(main,3,max_y-1,"Accept","done",colors.orange,colors.blue,colors.cyan,is_active)
  2170.        PrimeUI.keyAction(keys.enter,function()if time<1 then PrimeUI.resolve(nil,"done")end end)
  2171.        PrimeUI.addTask(function()
  2172.            local sz=11
  2173.            while time>0 do
  2174.                term.setCursorPos(3,max_y-1)
  2175.                term.blit(" Accept["..time.."] ",colors.toBlit(colors.lightGray):rep(sz),colors.toBlit(colors.blue):rep(sz))
  2176.                time=time-1
  2177.                sleep(1)
  2178.            end
  2179.            term.setCursorPos(3,max_y-1)
  2180.            term.blit(" Accept    ", colors.toBlit(colors.orange):rep(sz),colors.toBlit(colors.blue):rep(sz-3)..colors.toBlit(colors.lightBlue):rep(3))
  2181.            is_active.active=true
  2182.            while true do sleep(1)end
  2183.        end)
  2184.        _,act = PrimeUI.run()
  2185.    end
  2186.    
  2187.    --Module choose
  2188.    --CSSC (REQUIRED)
  2189.    --STRATUP
  2190.    --ENV-Pack -- ENV-Pack will be inserted, after it's creation.
  2191.     local wnd=window.create(term.current(),5,7,max_x-x-1,7)--API chooser window
  2192.     local base_modules={ --CSSC and Env-Pack Modules
  2193.         ["Original"]=false,
  2194.         ["Minified"]=false,--For persons who don't like LZSS
  2195.         ["LZSS"    ]=false,--Recomended
  2196.         ["LZSS-SEP"]= true,--default value - LZSS-SEP
  2197.         ["Startup" ]= true,--Enable/disable startup
  2198.         ["Program" ]= true,--Enable/disable program
  2199.         ["ENV-Pack"]=  "R",--Comming soon...
  2200.     }
  2201.     --Module Descriptions
  2202.     local desc={
  2203.         ["Original"]="Original C SuS SuS package.",
  2204.         ["Minified"]="Minified C SuS SuS package.",
  2205.         ["LZSS"]    ="C SuS SuS compressed with LZSS. LZSS package required.",
  2206.         ["LZSS-SEP"]="C SuS SuS Self-Extracting LZSS archive. LZSS independent.",
  2207.         ["Startup"] ="Startup module. CSSC API auto-load.",
  2208.         ["Program"] ="Program to launch CSSC programs from shell. Recomended to install.",
  2209.         ["ENV-Pack"]="Comming soon..."--"Package with additions to 'edit','lua' and other shell programs."
  2210.     }
  2211.     setmetatable(base_modules,{__pairs=function(a)
  2212.         return function(t,i)
  2213.             local order={"Original",
  2214.             ["Original"]="Minified",
  2215.             ["Minified"]="LZSS",
  2216.             ["LZSS"]="LZSS-SEP",
  2217.             ["LZSS-SEP"]="Startup",
  2218.             ["Startup"]="Program",
  2219.             ["Program"]="ENV-Pack",
  2220.             ["ENV-Pack"]=nil}
  2221.             local ind=order[i or 1]
  2222.             return ind,base_modules[ind]
  2223.         end,desc
  2224.     end})
  2225.     local sel_desk=desc["LZSS-SEP"]--defalut
  2226.     local redr_func=function()PrimeUI.textBox(main,4,15,max_x-x,1,sel_desk or "",colors.blue,colors.lightBlue)end
  2227.    
  2228.     --savePal()
  2229.     scnd_clr=colors.gray
  2230.     --wnd.setPaletteColor(colors.pink,0xA33C22)--0xAB2328)
  2231.     --wnd.setPaletteColor(colors.purple,0xB3632B)
  2232.     if act=="done" then
  2233.         local selc="Original"
  2234.         repeat
  2235.             PrimeUI.clear()
  2236.             make_gui(nil,true)
  2237.             PrimeUI.label(main,4,5,"Select API and modules to install:",colors.blue,colors.lightBlue)
  2238.             redr_func()--PrimeUI.textBox(main,4,15,max_x-x,1,sel_desk,colors.blue,colors.lightBlue)
  2239.             PrimeUI.checkSelectionBox(wnd,1, 1,max_x-x,8,base_modules,
  2240.                 function(k)
  2241.                     local i = 0
  2242.                     for kk in pairs(base_modules)do
  2243.                         i=i+1
  2244.                         if not({["Startup"]=1,["ENV-Pack"]=1,["Program"]=1})[k] and i<5 then
  2245.                             base_modules[kk]=false
  2246.                         end
  2247.                     end
  2248.                     if i<5 then
  2249.                         base_modules[k]=true
  2250.                     else
  2251.                         base_modules[k]=not base_modules[k]
  2252.                     end
  2253.                     sel_desk=desc[k]
  2254.                     selc=k
  2255.                     PrimeUI.resolve(_,"api")
  2256.                 end,colors.brown,colors.lightBlue)
  2257.             PrimeUI.addTask(--task to put cursor on it's place
  2258.                     function()
  2259.                         for k,v in pairs(base_modules)do
  2260.                             if k~=selc then os.queueEvent("key",keys.down,false)
  2261.                             else break end
  2262.                         end
  2263.                         while true do coroutine.yield() end
  2264.                     end)
  2265.                 --wnd.redraw()PrimeUI.checkSelectionBox(main,4,12,max_x-x,2,mod,function(k,v)end)
  2266.             _,act,key,value=PrimeUI.run()
  2267.         until act~="api"
  2268.     end
  2269.     --loadPal()
  2270.    
  2271.     --[[PrimeUI.clear()
  2272.     term.setBackgroundColor(colors.black)
  2273.     term.clear()
  2274.     local pret=require"cc.pretty"
  2275.     pret.pretty_print(base_modules)--]]
  2276.    
  2277.     local LZSS={["Install LZSS"]=false}
  2278.     --Install LZSS if needed
  2279.     if not _G.lzss and base_modules["LZSS"] and act=="done" then
  2280.         PrimeUI.clear()
  2281.         make_gui(nil,true)
  2282.         PrimeUI.label(main,4,5,"WARNING! LZSS package not found!",colors.red,colors.lightBlue)
  2283.         PrimeUI.label(main,4,7,"Continue instalation?",colors.brown,colors.lightBlue)
  2284.         PrimeUI.checkSelectionBox(main,5,8 ,max_x-x,1,LZSS,nil,colors.brown,colors.lightBlue)
  2285.         _,act=PrimeUI.run()
  2286.         if LZSS["Install LZSS"] then
  2287.             shell.run("fg pastebin run MxnRb6E8") --launch LZSS installer
  2288.         end
  2289.     end
  2290.     --loadPal()
  2291.    
  2292.     --Path to cssc directory
  2293.     local cssc_folder,prev_folder,err
  2294.     if act=="done" then
  2295.         local histor={"/","/progs/cssc","/programs/cssc","/disk/cssc","/lib/cssc","/apis/cssc","/cssc"}-- posible names for directory
  2296.         repeat
  2297.             cssc_folder=nil
  2298.             PrimeUI.clear()
  2299.             make_gui("print",true)
  2300.             PrimeUI.label(main,4,5,"Choose instalation folder (use \x12):",colors.blue,colors.lightBlue)
  2301.             paintutils.drawLine(4,7,max_x-x+3,8,colors.lightGray)
  2302.             PrimeUI.inputBox(main,5,7,max_x-x-2,"done",colors.white,colors.lightGray,nil,histor,
  2303.                 function(sLine) if #sLine>0 then return comp.dir(shell,sLine)end end,histor[#histor])
  2304.            
  2305.             PrimeUI.textBox(main,4,8,max_x-x,3,err or"",colors.red,colors.lightBlue)
  2306.             _,act,cssc_folder=PrimeUI.run()--attempt to get the way
  2307.             _,err=pcall(function()
  2308.                 if cssc_folder then --create files if posible
  2309.                     if prev_folder~=cssc_folder and fs.isDir(cssc_folder) and (fs.exists(fs.combine(cssc_folder,"cssc.lua")) or fs.exists(fs.combine(cssc_folder,"cssc_api.lua")))then
  2310.                         prev_folder=cssc_folder
  2311.                         error("Warning! Files 'cssc.lua' and 'cssc_api.lua' will be rewriten! Are you sure? [Enter]")
  2312.                     end
  2313.                     local tmp1,err1
  2314.                     if base_modules["Program"] then
  2315.                         tmp1=not fs.isReadOnly(fs.combine(cssc_folder,"cssc.lua")) or error("File is read-only!")
  2316.                     end
  2317.                     local tmp2=not fs.isReadOnly(fs.combine(cssc_folder,"cssc_api.lua")) or error("File is read-only!")
  2318.                    
  2319.                     path1=tmp1 and fs.combine(cssc_folder,"cssc.lua")
  2320.                     path2=tmp2 and fs.combine(cssc_folder,"cssc_api.lua")
  2321.                 end
  2322.             end)
  2323.             histor[#histor+1]=cssc_folder~=histor[#histor] and cssc_folder or nil
  2324.         until path2 or act=="exit"
  2325.     end
  2326.    
  2327.     err=nil
  2328.     local st_path_tmp,prev_st_path
  2329.     --Startup path
  2330.     if act=="done" and base_modules["Startup"] then
  2331.         local histor={"/startup.lua","/disk/startup.lua","/disk/startup/00_cssc.lua","/startup/cssc.lua","/startup/02_cssc.lua","/startup/01_cssc.lua"}
  2332.         repeat
  2333.             PrimeUI.clear()
  2334.             make_gui("print",true)
  2335.             PrimeUI.label(main,4,5,"Enter startup (use \x12):",colors.blue,colors.lightBlue)
  2336.             paintutils.drawLine(4,7,max_x-x+3,8,colors.lightGray)
  2337.             PrimeUI.inputBox(main,5,7,max_x-x-2,"done",colors.white,colors.lightGray,nil,histor,
  2338.                 function(sLine) if #sLine>0 then return comp.dirOrFile(shell,sLine)end end, histor[#histor])
  2339.             PrimeUI.textBox(main,4,8,max_x-x,3,err or"",colors.red,colors.lightBlue)
  2340.             _,act,st_path_tmp=PrimeUI.run()
  2341.             _,err=pcall(function()
  2342.                     if st_path_tmp then
  2343.                         if fs.exists(st_path_tmp) and prev_st_path~=st_path_tmp then
  2344.                             prev_st_path=st_path_tmp
  2345.                             error("Warning! File '"..st_path_tmp.."' will be rewriten! Are you sure? [Enter]")
  2346.                         end
  2347.                         local tmp =not fs.isReadOnly(st_path_tmp) or error("File is read-only!")
  2348.                         st_path=tmp and fs.combine(st_path_tmp)
  2349.                     end
  2350.                 end)
  2351.             histor[#histor+1]=st_path_tmp~=histor[#histor] and st_path_tmp or nil
  2352.         until st_path or act=="exit"
  2353.         end
  2354.    
  2355.     --Show selcted size
  2356.     if act=="done" then
  2357.         local type_api="LZSS-SEP"
  2358.         local i = 0
  2359.         for k,v in pairs(base_modules)do
  2360.             i=i+1
  2361.             type_api=i<5 and v and k or type_api
  2362.         end
  2363.  
  2364.         if type_api:find"SEP" then
  2365.             lzss_sep()
  2366.         elseif type_api:find"LZSS" then
  2367.             lzss_hash()
  2368.         end
  2369.  
  2370.         local s_api=#cssc_api[type_api]/1024
  2371.         local s_prog = base_modules["Program"]and #cssc_prog_code/1024 or 0
  2372.         local s_stp = st_path and (((base_modules["Program"] and #startup or #startup_small) - 9 + #cssc_folder)/1024) or 0
  2373.         PrimeUI.clear()
  2374.         --wnd.clear()
  2375.         make_gui(nil,true)
  2376.         PrimeUI.label(main ,4,5,("Startup:   %6.2fKb's"):format(s_stp),colors.blue,colors.lightBlue)
  2377.         PrimeUI.label(main ,4,6,("    API:   %6.2fKb's"):format(s_api),colors.blue,colors.lightBlue)
  2378.         PrimeUI.label(main ,4,7,("   Prog:   %6.2fKb's"):format(s_prog),colors.blue,colors.lightBlue)
  2379.         PrimeUI.label(main ,4,8,("Total Size:%6.2fKb's"):format(s_api+s_prog+s_stp),colors.blue,colors.lightBlue)
  2380.         PrimeUI.label(main ,4,9,"Continue instalation?",colors.blue,colors.lightBlue)
  2381.         _,act=PrimeUI.run()
  2382.     end
  2383.    
  2384.     --Install Part
  2385.     if act=="done" then
  2386.         local type_api="LZSS-SEP"
  2387.         local i = 0
  2388.         for k,v in pairs(base_modules)do
  2389.             i=i+1
  2390.             type_api=i<5 and v and k or type_api
  2391.         end
  2392.         install(cssc_folder,type_api,path1,path2,st_path)
  2393.    
  2394.         PrimeUI.clear()
  2395.         --wnd.clear()
  2396.         make_gui(nil,true)
  2397.         PrimeUI.label(main ,4,5,"Instalation completed...",colors.blue,colors.lightBlue)
  2398.         PrimeUI.label(main ,4,6,"Please reload OS...",colors.blue,colors.lightBlue)
  2399.         PrimeUI.label(main ,4,7,"Press any key to continue...",colors.blue,colors.lightBlue)
  2400.         PrimeUI.label(main ,4,8,"Program will exit automaticly after 3 seconds.",colors.blue,colors.lightBlue)
  2401.         PrimeUI.addTask(function()while true do
  2402.             local ev=os.pullEvent"key"
  2403.             ev=ev and PrimeUI.resolve()
  2404.             end
  2405.         end)
  2406.         PrimeUI.timeout(3,"timeout")
  2407.         _,act=PrimeUI.run()
  2408.     elseif act=="exit"then
  2409.         PrimeUI.clear()
  2410.         --wnd.clear()
  2411.         make_gui(nil,true)
  2412.         PrimeUI.label(main ,4,5,"Instalation canceled. Press any key to exit.",colors.red,colors.lightBlue)
  2413.         PrimeUI.label(main ,4,6,"Program will exit automaticly after 3 seconds.",colors.blue,colors.lightBlue)
  2414.         PrimeUI.addTask(function()while true do
  2415.             local ev=os.pullEvent"key"
  2416.             ev=ev and PrimeUI.resolve()
  2417.             end
  2418.         end)
  2419.         PrimeUI.timeout(3,"timeout")
  2420.         _,act=PrimeUI.run()
  2421.     end
  2422.    
  2423.     --END ANIMATION
  2424.     if not skip_animations then
  2425.         --term.clear()
  2426.         savePal()
  2427.        
  2428.         parallel.waitForAny(
  2429.         function()
  2430.             repeat
  2431.             local ev,key=os.pullEvent"key"
  2432.             if key==keys.space or key==keys.enter then
  2433.                 break
  2434.             end
  2435.             until false
  2436.             loadPal()
  2437.         end,
  2438.         function()
  2439.             parallel.waitForAny(
  2440.                 function()animate_color(colors.blue,colors.lightBlue,0.01,50)end,
  2441.                 function()animate_color(colors.cyan,colors.lightBlue,0.01,50)end,
  2442.                 function()animate_color(colors.orange,colors.lightBlue,0.01,50)end,
  2443.                 function()animate_color(colors.red,colors.lightBlue,0.01,50)end)
  2444.             term.clear()
  2445.             animate_color(colors.lightBlue,colors.black,0.02,50)
  2446.         end)
  2447.     end
  2448.     PrimeUI.clear()
  2449.     loadPal()
  2450.     term.setTextColor(Fg)
  2451.     term.setBackgroundColor(Bg)
  2452.     term.clear()
  2453.     --END
  2454. end
  2455.  
  2456. -- MAIN PROGRAM PART END
  2457.  
  2458. ---DATA PART    ---
  2459. comp=require"cc.shell.completion"
  2460. main=term.current()
  2461. x,y=6,8
  2462. max_x,max_y=term.getSize()
  2463. version="3.5-beta"
  2464. description=[[--PACKAGE DESCRIPTION--
  2465.  
  2466. This package has quiet install mode.
  2467. Use `-H` or `--help` option for more information.
  2468.  
  2469. Controls:
  2470.  Enter  == Continue
  2471.  Ctrl+c == Exit / Cancel
  2472.  Space  == Select option
  2473.  
  2474. Package version: 3.5-beta
  2475. Package creator: M.A.G.Gen.
  2476. Git: https://github.com/MAGGen-hub
  2477.  
  2478. PrimeUI creator: JackMacWindows
  2479. Git: https://github.com/MCJack123/PrimeUI
  2480.  
  2481. What is "C SuS SuS"?
  2482. C SuS SuS is Lua5.1 based modular macro language created by M.A.G.Gen..
  2483. C SuS SuS Compiller (CSSC) has no own parcer and
  2484. act like preproccessor that turns C SuS SuS code into Lua5.1 code.
  2485.  
  2486. What C SuS SuS provides?
  2487. 1. Full support of Lua5.3 operators
  2488.    Such as ">>" "//" "&"
  2489. 2. Keywords shortcuts
  2490.    (and -> "&&", or -> "||", local ->"@", return -> "$", ...)
  2491. 3. Assignment operators
  2492.    ("+=", "-=", "*=", "^=" ...)
  2493. 4. IS keyword
  2494.    (variable is "string")
  2495.    with {__type="your_type"} metamethod support
  2496. 5. Nil forgiving operators
  2497.    (object?.method()) error will not be emited if "method" is nil.
  2498. 6. Lambdas
  2499.    "(*args*)=>" will be turned into "function(args)"
  2500. 7. Defautl  arguments for functions
  2501.    function demo(A := *default_value*) *code* end
  2502. 8. More custom features...
  2503.  
  2504. To know more about C SuS SuS features,
  2505. how to use them and how to works with them,
  2506. please visit official github
  2507. and read or download the documentation [in development].
  2508.  
  2509. --END OF PACKAGE DESCRIPTION--
  2510. ]]
  2511. license=([[--LICENSE--
  2512.  
  2513. The MIT License (MIT)
  2514.  
  2515. Copyright CPRT 2023 github.com/MAGGen-hub, M.A.G.Gen. .
  2516.  
  2517. Permission is hereby granted, free of charge, to any person obtaining a copy of this software
  2518. and associated documentation files (the "Software"), to deal in the Software without
  2519. restriction, including without limitation the rights to use, copy, modify, merge, publish,
  2520. distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
  2521. Software is furnished to do so, subject to the following conditions:
  2522.  
  2523. The above copyright notice and this permission notice shall be included in all copies
  2524. or substantial portions of the Software.
  2525.  
  2526. THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
  2527. BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  2528. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  2529. DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  2530. FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  2531.  
  2532. --LICENCE END--
  2533. ]]):gsub("CPRT","\xA9")
  2534. ---DATA PART END---
  2535.  
  2536.  
  2537. ------------------------------------------------------------------------------------
  2538. ------------------------------------------------------------------------------------
  2539. ------------------------------------------------------------------------------------
  2540. ---FUNCTIONS PART---
  2541.  
  2542. function make_gui(tp,tm)
  2543.     local fg,bg,sel=
  2544.      colors.orange
  2545.     ,colors.blue
  2546.     ,colors.cyan
  2547.     -- Custom logo
  2548.     local logo= " Installer V1.3 "
  2549.     term.setCursorPos(5,2)
  2550.     term.blit("\x96\x83 \x8C\x82 \x8C\x82","bb3b33b3","333ee3ee")
  2551.     term.setCursorPos(5,3)
  2552.     term.blit("\x82\x83 \x81\x81 \x81\x81","bb3ee3ee","33333333")
  2553.     term.setTextColor(colors.blue)
  2554.     print(logo)
  2555.     -- Create box
  2556.     --PrimeUI.horizontalLine(main,4,4,8+#logo,colors.blue,colors.lightBlue)
  2557.     if tm then
  2558.         PrimeUI.borderBox(main,4,5,max_x-x,max_y-y,colors.blue,colors.lightBlue)
  2559.     else
  2560.         paintutils.drawBox(3,4,max_x-2,max_y-3,colors.blue,colors.lightBlue)
  2561.     end
  2562.     --PrimeUI.keyCombo(keys.c,true,false,false,"exit")
  2563.     PrimeUI.keyCombo(keys.c,true,false,false,"exit")
  2564.     --buttons
  2565.     if tp== "license" then
  2566.         --if time then
  2567.         --    PrimeUI.label(main,3,max_y-2,(" Accept[%i] "):format(time),colors.lightGray,colors.blue)
  2568.         --else
  2569.         --PrimeUI.keyAction(keys.enter,"done")
  2570.         --PrimeUI.button(main,3,max_y-2,"Accept","done",colors.lightGray,colors.blue)
  2571.         --end
  2572.         PrimeUI.button(main,15,max_y-1,"Cancel" ,"exit",fg,bg,sel)
  2573.     elseif tp=="print"then
  2574.         PrimeUI.label(main,3,max_y-1," Continue ",colors.lightGray,bg)
  2575.         PrimeUI.button(main,14,max_y-1,"Cancel" ,"exit",fg,bg,sel)
  2576.     else
  2577.         PrimeUI.keyAction(keys.enter,"done")
  2578.         PrimeUI.button(main,3,max_y-1,"Continue","done",fg,bg,sel)
  2579.         PrimeUI.button(main,14,max_y-1,"Cancel" ,"exit",fg,bg,sel)
  2580.     end
  2581. end
  2582.  
  2583. function rainbowPrintEffect(text,delay)
  2584.     local next,fg,bg,X,Y,prev=0,term.getTextColor(),term.getBackgroundColor()
  2585.     for char in (text.." "):gmatch"."do
  2586.         if prev then
  2587.             term.setCursorPos(X-1,Y)
  2588.             term.write(prev)
  2589.             prev=nil
  2590.         end
  2591.         if char:find"%s" then
  2592.             term.write(char)
  2593.         else
  2594.             repeat
  2595.                 next=(next+1)%16
  2596.             until 2^next ~= fg and 2^next ~= bg
  2597.         term.blit(char,colors.toBlit(2^next),colors.toBlit(bg))
  2598.         prev=char
  2599.         sleep(delay or 0.4)
  2600.         end
  2601.         X,Y=term.getCursorPos()
  2602.     end
  2603. end
  2604.  
  2605. function animate_color(first, second, delay,count)
  2606.     local s_clr={term.getPaletteColor(first)}
  2607.     local e_clr={term.getPaletteColor(second)}
  2608.     local step= {(e_clr[1]-s_clr[1])/count,
  2609.                  (e_clr[2]-s_clr[2])/count,
  2610.                  (e_clr[3]-s_clr[3])/count}
  2611.     for i=1,count do
  2612.         --print(unpack(e_clr))
  2613.         for j=1,3 do
  2614.             s_clr[j]=s_clr[j]+step[j]
  2615.         end
  2616.         sleep(delay)
  2617.         term.setPaletteColor(first,unpack(s_clr))
  2618.     end
  2619. end
  2620.  
  2621. pal={}
  2622. function savePal()
  2623.     for i=0,15 do
  2624.         pal[i]={term.getPaletteColor(2^i)}
  2625.     end
  2626. end
  2627. function loadPal()
  2628.     for i=0,15 do
  2629.         term.setPaletteColor(2^i,unpack(pal[i]))
  2630.     end
  2631. end
  2632.  
  2633. --Cool start
  2634. function Splash_Screen()
  2635. -- Set words
  2636. local wlc="W E L C O M E"
  2637. local maxX,maxY=term.getSize()
  2638.  
  2639. --skip or not intro
  2640. parallel.waitForAny(
  2641.     function()
  2642.         repeat
  2643.         local ev,key=os.pullEvent"key"
  2644.         if key==keys.space or key==keys.enter then
  2645.             break
  2646.         end
  2647.         until false
  2648.         loadPal()
  2649.     end,
  2650. function()
  2651. --backup
  2652. savePal()--save default pallete
  2653. local last_bg=term.getBackgroundColor()
  2654.  
  2655. --animate bg
  2656. term.setPaletteColor(colors.lightGray,term.getPaletteColor(last_bg))
  2657. term.setBackgroundColor(colors.lightGray)
  2658. paintutils.drawFilledBox(1,1,maxX,maxY)
  2659.  
  2660. animate_color(colors.lightGray,colors.lightBlue,0.03,50)
  2661.  
  2662. term.setBackgroundColor(colors.lightBlue)
  2663. paintutils.drawFilledBox(1,1,maxX,maxY)
  2664. loadPal()
  2665.  
  2666. --print welcome
  2667. term.setCursorPos((maxX-#wlc)/2,maxY/2-4)
  2668. term.setPaletteColor(colors.orange,term.getPaletteColor(colors.red))
  2669. term.setTextColor(colors.orange)
  2670. rainbowPrintEffect(wlc,0.3)
  2671. sleep(0.3)
  2672.  
  2673. --print to
  2674. term.setCursorPos((maxX-3)/2,maxY/2-2)
  2675. term.setPaletteColor(colors.green,term.getPaletteColor(colors.blue))
  2676. term.setTextColor(colors.green)
  2677. textutils.slowWrite("t o",5)
  2678.  
  2679. --images
  2680. local s_up= {t="\x98\x8C\x9B ",f="ee3e",b="33e3"}
  2681. local s_mid={t="\x89\x8C\x9B ",f="ee3e",b="33e3"}
  2682. local s_dwn={t="\x89\x8C\x86 ",f="eeee",b="3333"}
  2683. local u_up= {t="    "--[["\x90 \x9F "]],  f="eeee",b="3333"}
  2684. local u_mid={t="\x95 \x95 ",f="ee3e",b="33e3"}
  2685.  
  2686. --set new pal colors
  2687. --pink / lightGray
  2688.  
  2689. term.setPaletteColor(colors.lightGray,term.getPaletteColor(colors.blue))
  2690. term.setPaletteColor(colors.pink,term.getPaletteColor(colors.red))
  2691. term.setPaletteColor(colors.red,term.getPaletteColor(colors.lightBlue))
  2692. term.setPaletteColor(colors.blue,term.getPaletteColor(colors.lightBlue))
  2693.  
  2694. --blit images
  2695. term.setTextColor(colors.lightGray)
  2696. term.setCursorPos((maxX-28.5)/2,maxY/2)
  2697. term.blit("\x98\x8C\x9B  "..(s_up .t..u_up.t..s_up.t.." "):rep(2),"bb3bb"..(s_up.f..u_up.f..s_up.f.."8"):rep(2),"33b33"..(s_up.b..u_up.b..s_up.b.."3"):rep(2))
  2698. term.setCursorPos((maxX-28.5)/2,maxY/2+1)
  2699. term.blit("\x95    "      ..(s_mid.t..u_mid.t..s_mid.t.." "):rep(2),"bbbbb"..(s_mid.f..u_mid.f..s_mid.f.."6"):rep(2),"33333"..(s_mid.b..u_mid.b..s_mid.b.."3"):rep(2))
  2700. term.setCursorPos((maxX-28.5)/2,maxY/2+2)
  2701. term.blit("\x89\x8C\x86  "..(s_dwn.t:rep(3).." "):rep(2),"bbbbb"..(s_dwn.f:rep(3).."6"):rep(2),"33333"..(s_dwn.b:rep(3).."3"):rep(2))
  2702.  
  2703. animate_color(colors.blue,colors.lightGray,0.02,50)
  2704. animate_color(colors.red,colors.pink,0.02,50)
  2705.  
  2706. d=colors.lightBlue
  2707. --hide text
  2708. parallel.waitForAll(
  2709.     function()animate_color(colors.blue,d,0.03,40)end,
  2710.     function()animate_color(colors.red,d,0.03,40)end,
  2711.     function()animate_color(colors.orange,d,0.03,40)end,
  2712.     function()animate_color(colors.green,d,0.03,40)end)
  2713.  
  2714. --reload pallete
  2715. sleep(0.5)
  2716.  
  2717. loadPal()
  2718. end)
  2719. end
  2720.  
  2721.  
  2722. ------------------------------------------------------------------------------------
  2723. ------------------------------------------------------------------------------------
  2724. ------------------------------------------------------------------------------------
  2725. --PrimeUI INIT SECTION (This part of code was created by JackMacWindows)
  2726. local expect = require "cc.expect".expect
  2727.  
  2728. -- Initialization code
  2729. PrimeUI = {}
  2730. do
  2731.     local coros = {}
  2732.     local restoreCursor
  2733.  
  2734.     --- Adds a task to run in the main loop.
  2735.     ---@param func function The function to run, usually an `os.pullEvent` loop
  2736.     function PrimeUI.addTask(func)
  2737.         expect(1, func, "function")
  2738.         local t = {coro = coroutine.create(func)}
  2739.         coros[#coros+1] = t
  2740.         _, t.filter = coroutine.resume(t.coro)
  2741.     end
  2742.  
  2743.     --- Sends the provided arguments to the run loop, where they will be returned.
  2744.     ---@param ... any The parameters to send
  2745.     function PrimeUI.resolve(...)
  2746.         coroutine.yield(coros, ...)
  2747.     end
  2748.  
  2749.     --- Clears the screen and resets all components. Do not use any previously
  2750.     --- created components after calling this function.
  2751.     function PrimeUI.clear()
  2752.         -- Reset the screen.
  2753.         term.setCursorPos(1, 1)
  2754.         term.setCursorBlink(false)
  2755.         term.setBackgroundColor(colors.lightBlue)
  2756.         term.setTextColor(colors.white)
  2757.         term.clear()
  2758.         -- Reset the task list and cursor restore function.
  2759.         coros = {}
  2760.         restoreCursor = nil
  2761.     end
  2762.  
  2763.     --- Sets or clears the window that holds where the cursor should be.
  2764.     ---@param win window|nil The window to set as the active window
  2765.     function PrimeUI.setCursorWindow(win)
  2766.         expect(1, win, "table", "nil")
  2767.         restoreCursor = win and win.restoreCursor
  2768.     end
  2769.  
  2770.     --- Gets the absolute position of a coordinate relative to a window.
  2771.     ---@param win window The window to check
  2772.     ---@param x number The relative X position of the point
  2773.     ---@param y number The relative Y position of the point
  2774.     ---@return number x The absolute X position of the window
  2775.     ---@return number y The absolute Y position of the window
  2776.     function PrimeUI.getWindowPos(win, x, y)
  2777.         if win == term then return x, y end
  2778.         while win ~= term.native() and win ~= term.current() do
  2779.             if not win.getPosition then return x, y end
  2780.             local wx, wy = win.getPosition()
  2781.             x, y = x + wx - 1, y + wy - 1
  2782.             _, win = debug.getupvalue(select(2, debug.getupvalue(win.isColor, 1)), 1) -- gets the parent window through an upvalue
  2783.         end
  2784.         return x, y
  2785.     end
  2786.  
  2787.     --- Runs the main loop, returning information on an action.
  2788.     ---@return any ... The result of the coroutine that exited
  2789.     function PrimeUI.run()
  2790.         while true do
  2791.             -- Restore the cursor and wait for the next event.
  2792.             if restoreCursor then restoreCursor() end
  2793.             local ev = table.pack(os.pullEvent())
  2794.             -- Run all coroutines.
  2795.             for _, v in ipairs(coros) do
  2796.                 if v.filter == nil or v.filter == ev[1] then
  2797.                     -- Resume the coroutine, passing the current event.
  2798.                     local res = table.pack(coroutine.resume(v.coro, table.unpack(ev, 1, ev.n)))
  2799.                     -- If the call failed, bail out. Coroutines should never exit.
  2800.                     if not res[1] then error(res[2], 2) end
  2801.                     -- If the coroutine resolved, return its values.
  2802.                     if res[2] == coros then return table.unpack(res, 3, res.n) end
  2803.                     -- Set the next event filter.
  2804.                     v.filter = res[2]
  2805.                 end
  2806.             end
  2807.         end
  2808.     end
  2809. end
  2810.  
  2811. --- Draws a line of text at a position.
  2812. ---@param win window The window to draw on
  2813. ---@param x number The X position of the left side of the text
  2814. ---@param y number The Y position of the text
  2815. ---@param text string The text to draw
  2816. ---@param fgColor color|nil The color of the text (defaults to white)
  2817. ---@param bgColor color|nil The color of the background (defaults to black)
  2818. function PrimeUI.label(win, x, y, text, fgColor, bgColor)
  2819.     expect(1, win, "table")
  2820.     expect(2, x, "number")
  2821.     expect(3, y, "number")
  2822.     expect(4, text, "string")
  2823.     fgColor = expect(5, fgColor, "number", "nil") or colors.white
  2824.     bgColor = expect(6, bgColor, "number", "nil") or colors.black
  2825.     win.setCursorPos(x, y)
  2826.     win.setTextColor(fgColor)
  2827.     win.setBackgroundColor(bgColor)
  2828.     win.write(text)
  2829. end
  2830.  
  2831. --- Draws a horizontal line at a position with the specified width.
  2832. ---@param win window The window to draw on
  2833. ---@param x number The X position of the left side of the line
  2834. ---@param y number The Y position of the line
  2835. ---@param width number The width/length of the line
  2836. ---@param fgColor color|nil The color of the line (defaults to white)
  2837. ---@param bgColor color|nil The color of the background (defaults to black)
  2838. function PrimeUI.horizontalLine(win, x, y, width, fgColor, bgColor)
  2839.     expect(1, win, "table")
  2840.     expect(2, x, "number")
  2841.     expect(3, y, "number")
  2842.     expect(4, width, "number")
  2843.     fgColor = expect(5, fgColor, "number", "nil") or colors.white
  2844.     bgColor = expect(6, bgColor, "number", "nil") or colors.black
  2845.     -- Use drawing characters to draw a thin line.
  2846.     win.setCursorPos(x, y)
  2847.     win.setTextColor(fgColor)
  2848.     win.setBackgroundColor(bgColor)
  2849.     win.write(("\x8C"):rep(width))
  2850. end
  2851.  
  2852. --- Creates a clickable button on screen with text.
  2853. ---@param win window The window to draw on
  2854. ---@param x number The X position of the button
  2855. ---@param y number The Y position of the button
  2856. ---@param text string The text to draw on the button
  2857. ---@param action function|string A function to call when clicked, or a string to send with a `run` event
  2858. ---@param fgColor color|nil The color of the button text (defaults to white)
  2859. ---@param bgColor color|nil The color of the button (defaults to light gray)
  2860. ---@param clickedColor color|nil The color of the button when clicked (defaults to gray)
  2861. function PrimeUI.button(win, x, y, text, action, fgColor, bgColor, clickedColor,is_active)
  2862.     expect(1, win, "table")
  2863.     expect(2, x, "number")
  2864.     expect(3, y, "number")
  2865.     expect(4, text, "string")
  2866.     expect(5, action, "function", "string")
  2867.     fgColor = expect(6, fgColor, "number", "nil") or colors.white
  2868.     bgColor = expect(7, bgColor, "number", "nil") or colors.gray
  2869.     clickedColor = expect(8, clickedColor, "number", "nil") or colors.lightGray
  2870.     -- Draw the initial button.
  2871.     win.setCursorPos(x, y)
  2872.     win.setBackgroundColor(bgColor)
  2873.     win.setTextColor(fgColor)
  2874.     win.write(" " .. text .. " ")
  2875.     -- Get the screen position and add a click handler.
  2876.     PrimeUI.addTask(function()
  2877.         local buttonDown = false
  2878.         while true do
  2879.             local event, button, clickX, clickY = os.pullEvent()
  2880.             local screenX, screenY = PrimeUI.getWindowPos(win, x, y)
  2881.             local work=not is_active and true or is_active.active
  2882.             if work then
  2883.             if event == "mouse_click" and button == 1 and clickX >= screenX and clickX < screenX + #text + 2 and clickY == screenY then
  2884.                 -- Initiate a click action (but don't trigger until mouse up).
  2885.                 buttonDown = true
  2886.                 -- Redraw the button with the clicked background color.
  2887.                 win.setCursorPos(x, y)
  2888.                 win.setBackgroundColor(clickedColor)
  2889.                 win.setTextColor(fgColor)
  2890.                 win.write(" " .. text .. " ")
  2891.             elseif event == "mouse_up" and button == 1 and buttonDown then
  2892.                 -- Finish a click event.
  2893.                 if clickX >= screenX and clickX < screenX + #text + 2 and clickY == screenY then
  2894.                     -- Trigger the action.
  2895.                     if type(action) == "string" then PrimeUI.resolve("button", action)
  2896.                     else action() end
  2897.                 end
  2898.                 -- Redraw the original button state.
  2899.                 win.setCursorPos(x, y)
  2900.                 win.setBackgroundColor(bgColor)
  2901.                 win.setTextColor(fgColor)
  2902.                 win.write(" " .. text .. " ")
  2903.             end
  2904.             end
  2905.         end
  2906.     end)
  2907. end
  2908.  
  2909. --- Adds an action to trigger when a key is pressed.
  2910. ---@param key key The key to trigger on, from `keys.*`
  2911. ---@param action function|string A function to call when clicked, or a string to use as a key for a `run` return event
  2912. function PrimeUI.keyAction(key, action)
  2913.     expect(1, key, "number")
  2914.     expect(2, action, "function", "string")
  2915.     PrimeUI.addTask(function()
  2916.         while true do
  2917.             local _, param1 = os.pullEvent("key") -- wait for key
  2918.             if param1 == key then
  2919.                 if type(action) == "string" then PrimeUI.resolve("keyAction", action)
  2920.                 else action() end
  2921.             end
  2922.         end
  2923.     end)
  2924. end
  2925.  
  2926. --- Adds an action to trigger when a key is pressed with modifier keys.
  2927. ---@param key key The key to trigger on, from `keys.*`
  2928. ---@param withCtrl boolean Whether Ctrl is required
  2929. ---@param withAlt boolean Whether Alt is required
  2930. ---@param withShift boolean Whether Shift is required
  2931. ---@param action function|string A function to call when clicked, or a string to use as a key for a `run` return event
  2932. function PrimeUI.keyCombo(key, withCtrl, withAlt, withShift, action)
  2933.     expect(1, key, "number")
  2934.     expect(2, withCtrl, "boolean")
  2935.     expect(3, withAlt, "boolean")
  2936.     expect(4, withShift, "boolean")
  2937.     expect(5, action, "function", "string")
  2938.     PrimeUI.addTask(function()
  2939.         local heldCtrl, heldAlt, heldShift = false, false, false
  2940.         while true do
  2941.             local event, param1, param2 = os.pullEvent() -- wait for key
  2942.             if event == "key" then
  2943.                 -- check if key is down, all modifiers are correct, and that it's not held
  2944.                 if param1 == key and heldCtrl == withCtrl and heldAlt == withAlt and heldShift == withShift and not param2 then
  2945.                     if type(action) == "string" then PrimeUI.resolve("keyCombo", action)
  2946.                     else action() end
  2947.                 -- activate modifier keys
  2948.                 elseif param1 == keys.leftCtrl or param1 == keys.rightCtrl then heldCtrl = true
  2949.                 elseif param1 == keys.leftAlt or param1 == keys.rightAlt then heldAlt = true
  2950.                 elseif param1 == keys.leftShift or param1 == keys.rightShift then heldShift = true end
  2951.             elseif event == "key_up" then
  2952.                 -- deactivate modifier keys
  2953.                 if param1 == keys.leftCtrl or param1 == keys.rightCtrl then heldCtrl = false
  2954.                 elseif param1 == keys.leftAlt or param1 == keys.rightAlt then heldAlt = false
  2955.                 elseif param1 == keys.leftShift or param1 == keys.rightShift then heldShift = false end
  2956.             end
  2957.         end
  2958.     end)
  2959. end
  2960.  
  2961. --- Creates a scrollable window, which allows drawing large content in a small area.
  2962. ---@param win window The parent window of the scroll box
  2963. ---@param x number The X position of the box
  2964. ---@param y number The Y position of the box
  2965. ---@param width number The width of the box
  2966. ---@param height number The height of the outer box
  2967. ---@param innerHeight number The height of the inner scroll area
  2968. ---@param allowArrowKeys boolean|nil Whether to allow arrow keys to scroll the box (defaults to true)
  2969. ---@param showScrollIndicators boolean|nil Whether to show arrow indicators on the right side when scrolling is available, which reduces the inner width by 1 (defaults to false)
  2970. ---@param fgColor number|nil The color of scroll indicators (defaults to white)
  2971. ---@param bgColor color|nil The color of the background (defaults to black)
  2972. ---@return window inner The inner window to draw inside
  2973. function PrimeUI.scrollBox(win, x, y, width, height, innerHeight, allowArrowKeys, showScrollIndicators, fgColor, bgColor)
  2974.     expect(1, win, "table")
  2975.     expect(2, x, "number")
  2976.     expect(3, y, "number")
  2977.     expect(4, width, "number")
  2978.     expect(5, height, "number")
  2979.     expect(6, innerHeight, "number")
  2980.     expect(7, allowArrowKeys, "boolean", "nil")
  2981.     expect(8, showScrollIndicators, "boolean", "nil")
  2982.     fgColor = expect(9, fgColor, "number", "nil") or colors.white
  2983.     bgColor = expect(10, bgColor, "number", "nil") or colors.black
  2984.     if allowArrowKeys == nil then allowArrowKeys = true end
  2985.     -- Create the outer container box.
  2986.     local outer = window.create(win == term and term.current() or win, x, y, width, height)
  2987.     outer.setBackgroundColor(bgColor)
  2988.     outer.clear()
  2989.     -- Create the inner scrolling box.
  2990.     local inner = window.create(outer, 1, 1, width - (showScrollIndicators and 1 or 0), innerHeight)
  2991.     inner.setBackgroundColor(bgColor)
  2992.     inner.clear()
  2993.     -- Draw scroll indicators if desired.
  2994.     if showScrollIndicators then
  2995.         outer.setBackgroundColor(bgColor)
  2996.         outer.setTextColor(fgColor)
  2997.         outer.setCursorPos(width, height)
  2998.         outer.write(innerHeight > height and "\31" or " ")
  2999.     end
  3000.     -- Get the absolute position of the window.
  3001.     x, y = PrimeUI.getWindowPos(win, x, y)
  3002.     -- Add the scroll handler.
  3003.     PrimeUI.addTask(function()
  3004.         local scrollPos = 1
  3005.         while true do
  3006.             -- Wait for next event.
  3007.             local ev = table.pack(os.pullEvent())
  3008.             -- Update inner height in case it changed.
  3009.             innerHeight = select(2, inner.getSize())
  3010.             -- Check for scroll events and set direction.
  3011.             local dir
  3012.             if ev[1] == "key" and allowArrowKeys then
  3013.                 if ev[2] == keys.up then dir = -1
  3014.                 elseif ev[2] == keys.down then dir = 1 end
  3015.             elseif ev[1] == "mouse_scroll" and ev[3] >= x and ev[3] < x + width and ev[4] >= y and ev[4] < y + height then
  3016.                 dir = ev[2]
  3017.             end
  3018.             -- If there's a scroll event, move the window vertically.
  3019.             if dir and (scrollPos + dir >= 1 and scrollPos + dir <= innerHeight - height) then
  3020.                 scrollPos = scrollPos + dir
  3021.                 inner.reposition(1, 2 - scrollPos)
  3022.             end
  3023.             -- Redraw scroll indicators if desired.
  3024.             if showScrollIndicators then
  3025.                 outer.setBackgroundColor(bgColor)
  3026.                 outer.setTextColor(fgColor)
  3027.                 outer.setCursorPos(width, 1)
  3028.                 outer.write(scrollPos > 1 and "\30" or " ")
  3029.                 outer.setCursorPos(width, height)
  3030.                 outer.write(scrollPos < innerHeight - height and "\31" or " ")
  3031.             end
  3032.         end
  3033.     end)
  3034.     return inner
  3035. end
  3036.  
  3037. --- Creates a text input box.
  3038. ---@param win window The window to draw on
  3039. ---@param x number The X position of the left side of the box
  3040. ---@param y number The Y position of the box
  3041. ---@param width number The width/length of the box
  3042. ---@param action function|string A function or `run` event to call when the enter key is pressed
  3043. ---@param fgColor color|nil The color of the text (defaults to white)
  3044. ---@param bgColor color|nil The color of the background (defaults to black)
  3045. ---@param replacement string|nil A character to replace typed characters with
  3046. ---@param history string[]|nil A list of previous entries to provide
  3047. ---@param completion function|nil A function to call to provide completion
  3048. ---@param default string|nil A string to return if the box is empty
  3049. function PrimeUI.inputBox(win, x, y, width, action, fgColor, bgColor, replacement, history, completion, default)
  3050.     expect(1, win, "table")
  3051.     expect(2, x, "number")
  3052.     expect(3, y, "number")
  3053.     expect(4, width, "number")
  3054.     expect(5, action, "function", "string")
  3055.     fgColor = expect(6, fgColor, "number", "nil") or colors.white
  3056.     bgColor = expect(7, bgColor, "number", "nil") or colors.black
  3057.     expect(8, replacement, "string", "nil")
  3058.     expect(9, history, "table", "nil")
  3059.     expect(10, completion, "function", "nil")
  3060.     expect(11, default, "string", "nil")
  3061.     -- Create a window to draw the input in.
  3062.     local box = window.create(win, x, y, width, 1)
  3063.     box.setTextColor(fgColor)
  3064.     box.setBackgroundColor(bgColor)
  3065.     box.clear()
  3066.     -- Call read() in a new coroutine.
  3067.     PrimeUI.addTask(function()
  3068.         -- We need a child coroutine to be able to redirect back to the window.
  3069.         local coro = coroutine.create(read)
  3070.         -- Run the function for the first time, redirecting to the window.
  3071.         local old = term.redirect(box)
  3072.         local ok, res = coroutine.resume(coro, replacement, history, completion, default)
  3073.         term.redirect(old)
  3074.         -- Run the coroutine until it finishes.
  3075.         while coroutine.status(coro) ~= "dead" do
  3076.             -- Get the next event.
  3077.             local ev = table.pack(os.pullEvent())
  3078.             -- Redirect and resume.
  3079.             old = term.redirect(box)
  3080.             ok, res = coroutine.resume(coro, table.unpack(ev, 1, ev.n))
  3081.             term.redirect(old)
  3082.             -- Pass any errors along.
  3083.             if not ok then error(res) end
  3084.         end
  3085.         -- Send the result to the receiver.
  3086.         if type(action) == "string" then PrimeUI.resolve("inputBox", action, res)
  3087.         else action(res) end
  3088.         -- Spin forever, because tasks cannot exit.
  3089.         while true do os.pullEvent() end
  3090.     end)
  3091. end
  3092.  
  3093. --- Creates a list of entries with toggleable check boxes.
  3094. ---@param win window The window to draw on
  3095. ---@param x number The X coordinate of the inside of the box
  3096. ---@param y number The Y coordinate of the inside of the box
  3097. ---@param width number The width of the inner box
  3098. ---@param height number The height of the inner box
  3099. ---@param selections {string: string|boolean} A list of entries to show, where the value is whether the item is pre-selected (or `"R"` for required/forced selected)
  3100. ---@param action function|string|nil A function or `run` event that's called when a selection is made
  3101. ---@param fgColor color|nil The color of the text (defaults to white)
  3102. ---@param bgColor color|nil The color of the background (defaults to black)
  3103. function PrimeUI.checkSelectionBox(win, x, y, width, height, selections, action, fgColor, bgColor)
  3104.     expect(1, win, "table")
  3105.     expect(2, x, "number")
  3106.     expect(3, y, "number")
  3107.     expect(4, width, "number")
  3108.     expect(5, height, "number")
  3109.     expect(6, selections, "table")
  3110.     expect(7, action, "function", "string", "nil")
  3111.     fgColor = expect(8, fgColor, "number", "nil") or colors.white
  3112.     bgColor = expect(9, bgColor, "number", "nil") or colors.black
  3113.     -- Calculate how many selections there are.
  3114.     local nsel = 0
  3115.     for _ in pairs(selections) do nsel = nsel + 1 end
  3116.     -- Create the outer display box.
  3117.     local outer = window.create(win, x, y, width, height)
  3118.     outer.setBackgroundColor(bgColor)
  3119.     outer.clear()
  3120.     -- Create the inner scroll box.
  3121.     local inner = window.create(outer, 1, 1, width - 1, nsel)
  3122.     inner.setBackgroundColor(bgColor)
  3123.     inner.setTextColor(fgColor)
  3124.     inner.clear()
  3125.     -- Draw each line in the window.
  3126.     local lines = {}
  3127.     local nl, selected = 1, 1
  3128.     local bebra = 0
  3129.     for k, v in pairs(selections) do
  3130.         bebra=bebra+1
  3131.         inner.setCursorPos(1, nl)
  3132.         if bebra > 4 then inner.setTextColor(scnd_clr) end
  3133.         inner.write((v and (v == "R" and "[-] " or "[\xD7] ") or "[ ] ") .. k)
  3134.         lines[nl] = {k, not not v}
  3135.         nl = nl + 1
  3136.     end
  3137.     -- Draw a scroll arrow if there is scrolling.
  3138.     if nsel > height then
  3139.         outer.setCursorPos(width, height)
  3140.         outer.setBackgroundColor(bgColor)
  3141.         outer.setTextColor(fgColor)
  3142.         outer.write("\31")
  3143.     end
  3144.     -- Set cursor blink status.
  3145.     inner.setCursorPos(2, selected)
  3146.     inner.setCursorBlink(true)
  3147.     PrimeUI.setCursorWindow(inner)
  3148.     -- Get screen coordinates & add run task.
  3149.     local screenX, screenY = PrimeUI.getWindowPos(win, x, y)
  3150.     PrimeUI.addTask(function()
  3151.         local scrollPos = 1
  3152.         while true do
  3153.             inner.setTextColor(fgColor)
  3154.             -- Wait for an event.
  3155.             local ev = table.pack(os.pullEvent())
  3156.             -- Look for a scroll event or a selection event.
  3157.             local dir
  3158.             if ev[1] == "key" then
  3159.                 if ev[2] == keys.up then dir = -1
  3160.                 elseif ev[2] == keys.down then dir = 1
  3161.                 elseif ev[2] == keys.space and selections[lines[selected][1]] ~= "R" then
  3162.                     -- (Un)select the item.
  3163.                     lines[selected][2] = not lines[selected][2]
  3164.                     inner.setCursorPos(2, selected)
  3165.                     if selected > 4 then inner.setTextColor(scnd_clr) end
  3166.                     inner.write(lines[selected][2] and "\xD7" or " ")
  3167.                     -- Call the action if passed; otherwise, set the original table.
  3168.                     if type(action) == "string" then PrimeUI.resolve("checkSelectionBox", action, lines[selected][1], lines[selected][2])
  3169.                     elseif action then action(lines[selected][1], lines[selected][2])
  3170.                     else selections[lines[selected][1]] = lines[selected][2] end
  3171.                     -- Redraw all lines in case of changes.
  3172.                     for i, v in ipairs(lines) do
  3173.                         local vv = selections[v[1]] == "R" and "R" or v[2]
  3174.                         inner.setCursorPos(2, i)
  3175.                         if i > 4 then inner.setTextColor(scnd_clr) end
  3176.                         inner.write((vv and (vv == "R" and "-" or "\xD7") or " "))
  3177.                     end
  3178.                     inner.setCursorPos(2, selected)
  3179.                 end
  3180.             elseif ev[1] == "mouse_scroll" and ev[3] >= screenX and ev[3] < screenX + width and ev[4] >= screenY and ev[4] < screenY + height then
  3181.                 dir = ev[2]
  3182.             end
  3183.             -- Scroll the screen if required.
  3184.             if dir and (selected + dir >= 1 and selected + dir <= nsel) then
  3185.                 selected = selected + dir
  3186.                 if selected - scrollPos < 0 or selected - scrollPos >= height then
  3187.                     scrollPos = scrollPos + dir
  3188.                     inner.reposition(1, 2 - scrollPos)
  3189.                 end
  3190.                 inner.setCursorPos(2, selected)
  3191.             end
  3192.             -- Redraw scroll arrows and reset cursor.
  3193.             outer.setCursorPos(width, 1)
  3194.             outer.write(scrollPos > 1 and "\30" or " ")
  3195.             outer.setCursorPos(width, height)
  3196.             outer.write(scrollPos < nsel - height + 1 and "\31" or " ")
  3197.             inner.restoreCursor()
  3198.         end
  3199.     end)
  3200. end
  3201.  
  3202. --- Creates a text box that wraps text and can have its text modified later.
  3203. ---@param win window The parent window of the text box
  3204. ---@param x number The X position of the box
  3205. ---@param y number The Y position of the box
  3206. ---@param width number The width of the box
  3207. ---@param height number The height of the box
  3208. ---@param text string The initial text to draw
  3209. ---@param fgColor color|nil The color of the text (defaults to white)
  3210. ---@param bgColor color|nil The color of the background (defaults to black)
  3211. ---@return function redraw A function to redraw the window with new contents
  3212. function PrimeUI.textBox(win, x, y, width, height, text, fgColor, bgColor)
  3213.     expect(1, win, "table")
  3214.     expect(2, x, "number")
  3215.     expect(3, y, "number")
  3216.     expect(4, width, "number")
  3217.     expect(5, height, "number")
  3218.     expect(6, text, "string")
  3219.     fgColor = expect(7, fgColor, "number", "nil") or colors.white
  3220.     bgColor = expect(8, bgColor, "number", "nil") or colors.black
  3221.     -- Create the box window.
  3222.     local box = window.create(win, x, y, width, height)
  3223.     -- Override box.getSize to make print not scroll.
  3224.     function box.getSize()
  3225.         return width, math.huge
  3226.     end
  3227.     -- Define a function to redraw with.
  3228.     local function redraw(_text)
  3229.         expect(1, _text, "string")
  3230.         -- Set window parameters.
  3231.         box.setBackgroundColor(bgColor)
  3232.         box.setTextColor(fgColor)
  3233.         box.clear()
  3234.         box.setCursorPos(1, 1)
  3235.         -- Redirect and draw with `print`.
  3236.         local old = term.redirect(box)
  3237.         print(_text)
  3238.         term.redirect(old)
  3239.     end
  3240.     redraw(text)
  3241.     return redraw
  3242. end
  3243.  
  3244. --- Draws a thin border around a screen region.
  3245. ---@param win window The window to draw on
  3246. ---@param x number The X coordinate of the inside of the box
  3247. ---@param y number The Y coordinate of the inside of the box
  3248. ---@param width number The width of the inner box
  3249. ---@param height number The height of the inner box
  3250. ---@param fgColor color|nil The color of the border (defaults to white)
  3251. ---@param bgColor color|nil The color of the background (defaults to black)
  3252. function PrimeUI.borderBox(win, x, y, width, height, fgColor, bgColor)
  3253.     expect(1, win, "table")
  3254.     expect(2, x, "number")
  3255.     expect(3, y, "number")
  3256.     expect(4, width, "number")
  3257.     expect(5, height, "number")
  3258.     fgColor = expect(6, fgColor, "number", "nil") or colors.white
  3259.     bgColor = expect(7, bgColor, "number", "nil") or colors.black
  3260.     -- Draw the top-left corner & top border.
  3261.     win.setBackgroundColor(bgColor)
  3262.     win.setTextColor(fgColor)
  3263.     win.setCursorPos(x - 1, y - 1)
  3264.     win.write("\x9C" .. ("\x8C"):rep(width))
  3265.     -- Draw the top-right corner.
  3266.     win.setBackgroundColor(fgColor)
  3267.     win.setTextColor(bgColor)
  3268.     win.write("\x93")
  3269.     -- Draw the right border.
  3270.     for i = 1, height do
  3271.         win.setCursorPos(win.getCursorPos() - 1, y + i - 1)
  3272.         win.write("\x95")
  3273.     end
  3274.     -- Draw the left border.
  3275.     win.setBackgroundColor(bgColor)
  3276.     win.setTextColor(fgColor)
  3277.     for i = 1, height do
  3278.         win.setCursorPos(x - 1, y + i - 1)
  3279.         win.write("\x95")
  3280.     end
  3281.     -- Draw the bottom border and corners.
  3282.     win.setCursorPos(x - 1, y + height)
  3283.     win.write("\x8D" .. ("\x8C"):rep(width) .. "\x8E")
  3284. end
  3285.  
  3286. --- Draws a block of text inside a window with word wrapping, optionally resizing the window to fit.
  3287. ---@param win window The window to draw in
  3288. ---@param text string The text to draw
  3289. ---@param resizeToFit boolean|nil Whether to resize the window to fit the text (defaults to false). This is useful for scroll boxes.
  3290. ---@param fgColor color|nil The color of the text (defaults to white)
  3291. ---@param bgColor color|nil The color of the background (defaults to black)
  3292. ---@return number lines The total number of lines drawn
  3293. function PrimeUI.drawText(win, text, resizeToFit, fgColor, bgColor)
  3294.     expect(1, win, "table")
  3295.     expect(2, text, "string")
  3296.     expect(3, resizeToFit, "boolean", "nil")
  3297.     fgColor = expect(4, fgColor, "number", "nil") or colors.white
  3298.     bgColor = expect(5, bgColor, "number", "nil") or colors.black
  3299.     -- Set colors.
  3300.     win.setBackgroundColor(bgColor)
  3301.     win.setTextColor(fgColor)
  3302.     -- Redirect to the window to use print on it.
  3303.     local old = term.redirect(win)
  3304.     -- Draw the text using print().
  3305.     local lines = print(text)
  3306.     -- Redirect back to the original terminal.
  3307.     term.redirect(old)
  3308.     -- Resize the window if desired.
  3309.     if resizeToFit then
  3310.         -- Get original parameters.
  3311.         local x, y = win.getPosition()
  3312.         local w = win.getSize()
  3313.         -- Resize the window.
  3314.         win.reposition(x, y, w, lines)
  3315.     end
  3316.     return lines
  3317. end
  3318.  
  3319. --- Runs a function or action after the specified time period, with optional canceling.
  3320. ---@param time number The amount of time to wait for, in seconds
  3321. ---@param action function|string The function to call when the timer completes, or a `run` event to send
  3322. ---@return function cancel A function to cancel the timer
  3323. function PrimeUI.timeout(time, action)
  3324.     expect(1, time, "number")
  3325.     expect(2, action, "function", "string")
  3326.     -- Start the timer.
  3327.     local timer = os.startTimer(time)
  3328.     -- Add a task to wait for the timer.
  3329.     PrimeUI.addTask(function()
  3330.         while true do
  3331.             -- Wait for a timer event.
  3332.             local _, tm = os.pullEvent("timer")
  3333.             if tm == timer then
  3334.                 -- Fire the timer action.
  3335.                 if type(action) == "string" then PrimeUI.resolve("timeout", action)
  3336.                 else action() end
  3337.             end
  3338.         end
  3339.     end)
  3340.     -- Return a function to cancel the timer.
  3341.     return function() os.cancelTimer(timer) end
  3342. end
  3343.  
  3344. --PrimeUI INIT END
  3345. ------------------------------------------------------------------------------------
  3346. ------------------------------------------------------------------------------------
  3347. ------------------------------------------------------------------------------------
  3348. Main() --execute main prog
  3349.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement