Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --LOCAL PART
- 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=
- {},{["LZSS"]="",["LZSS-SEP"]="",["Original"]="",["Minified"]=""},{["LZSS"]="",["LZSS-SEP"]="",["Original"]="",["Minified"]=""},"","",term.getTextColor(),term.getBackgroundColor(),{...}
- ------------------------------------------------------------------------------------
- --CODE PART
- startup_small=[=[local S,C,d=settings,"cssc.enable","CSSC_PATH"S.define(C,{default=true,type="boolean"})if S.get(C)then
- shell.run(d.."cssc_api.lua")cssc.addPath(d.."modules/",1)end]=]
- cssc_prog_code =[===========[if#{...}<1 then print"Usage: cssc <prog>"return end
- local p,E,a,t,f,e,r=shell.resolveProgram(...),error,{...},table.remove
- p=p or E("Program `"..a[1].."` not found!")
- f,e=fs.open(p,"r")
- e=e and E(e)
- r=f.readAll():gsub("^#!cssc\n","",1)
- r=r:find"^[^<]"and"<A,err>"..r or r
- r,e=cssc.load(r,"@"..p,nil,_ENV)
- f.close()
- e=e and E(e)
- t(a,1)
- arg[0]=t(arg,1)
- return r(unpack(a))]===========] -- 11
- 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
- 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]=]
- cssc_api["Original"]=[=============[ -- C SuS SuS Programming language compiler 3.5 - alpha
- --CODE START
- --this section contain all lua keywords for specific features
- K={}
- Ks="if function for while repeat elseif else do then end until local return in break "
- Kb={}
- Ks:gsub("(%S+)( )", function (x,s)K[#K+1]=s..x..s Kb[x]=#K end )
- NL=load --native CraftOS load function
- --initialize lambda function feature
- local l= function (C,o) --DO NOT PLACE LAMBDA AT THE START OF FILE!!! You will got ")" instead of "function(*args*)"
- local i,a,e,p=#C.R,1
- e=C.R[i]
- p=e:find"^%)%s*" and "" or "("
- 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
- i,a=i-1,not a
- e=C.R[i] end
- table.insert(C.R,#p<1 and i or i+1,K[2]..p)-- K[2] - function keyword K[13] - return
- C.R[#C.R+1]=(#p>0 and ")" or "")..(o:sub(1,1)=="-" and K[13] or "") --WARNING!!! Thanks for your attention! =)
- if C.L then --core exist
- C.pv=2 -- Lua5.3 operators compatability patch (and for some future things)
- C.C.L("function",1)
- end
- end
- --FEATURES TABLE
- F={
- --initialise main features::
- -- keywords and "if else then" shortcut section
- E={ ["/|"]=K[1],--if
- ["?"]=K[9],--then
- [":|"]=K[6],--elseif
- ["\\|"]=K[7]},--else
- K={ ["@"]=K[12],--local
- ["$"]=K[13],--return
- ["||"]=" or ",--or
- ["&&"]=" and ",--and
- ["!"]=" not ",--not
- [";"]=K[10]},--end
- --lambda section
- F={ ["->"]=l,
- ["=>"]=l}
- }
- -- C SuS SuS Compiller (CSSC)
- -- Base function for all cores and modules
- L= function (x,name,mode,env)
- if type(x)=="string" then -- x might be a function or a string
- local c=x:match"^<.->" or x:match"^#!.-\n?<.->" -- locate control string
- if c then --control string exists!
- --INITIALISE LOCALS
- 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
- x=x:sub(#c+1) --remove control string to start parsing
- C={O=O,C= function () end ,R=R,F={},c={},l=1,pv=1} -- initialise control tablet for special functions call
- --S -> the core module (empty by default)
- --INITIALIZE COMPILLER
- for K,V in c:gmatch"([%w_]+)%(?([%w_. ]*)"do--load flags that used in control string: K - feature name V - feature argument
- if F[K] then -- feature exist
- for k,v in pairs(F[K])do O[k]=v end
- l=F[K][1] and F[K][1](C,V,x,name,mode,env)-- [1] index is used to store special compiller directives
- if l then return l end --PRELOAD CHECK
- end -- if special has argumet V ex: "<pre(V)>" then F["pre"][1](ctrl_table,"V")
- end
- O[1]=nil -- remove trash from current_operators table (all specials in S table now)
- --COMPILE -- o: operator, w: word
- l=#x+1
- for o,w,i in x:gmatch"([%s!#-&(-/:-@\\-^{-~`]*%[?=*[%['\"]?%s*)([%w_]*[^%w%p%[-`{-~\\-_%s]*[^\n%S]*)()"do
- -- see that pattern? Now try to spell it in one breath! =P
- --LINE COUNTER -- in this pattern the word (w) will never be "^%s*$"!
- o:gsub("\n", function ()C.l=C.l+1 end )
- --STRING MODE: string or comment located and must be captured
- if s then
- a,b,e=o:find(#s<2 and "(\\*[\n"..s.."])%s*" or "(%]=*%])%s*") --locate posible end of string (depends on string type)
- 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
- b=b or i
- t=t..o:sub(0,b) --finish string
- if c then c=C.c
- else
- t=C.C(nil,t,i)or t --CORE module
- c=R
- end
- c[#c+1]=t -- insert object
- o=po..o:sub(b+1) --form new operators sequence
- s,t=nil --disable string mode
- else
- t=t..o..w --continue string
- end
- end
- --DEFAULT MODE: main compiler part
- if not s then
- --STRING LOCATOR
- o=o:gsub("-%-%s-\n","\n")--remove all empty comments (they may corrupt a lot of things!)
- c=o:match"-%-%[?=*%[?" --if start found: init str_mode
- s=o:match"%[=*%["or o:match"['\"]"
- if c or s then
- a=o:find(c or s,1,1)
- s=c and (c:sub(3)==s and s or "\n") or s --(string/long_string/long_comment) or small_comment
- t,w=o:sub(a)..w,"" -- save temp string and errase word
- o=o:sub(0,a-1)..(c and "\0" or '"') -- correct opeartor seq add control character
- po=c and (o or "") or "" -- set previous operator
- end
- --IF NOT COMMENT
- if not c or i==l then
- --OPERATOR PARCE: Default parcer and custom functions launcher
- while #o>0 do
- a=o:match"^%s*" --this code was made to decrase the length of result table and allow spacing in operators capture section
- R[#R]=R[#R]..a
- o=o:sub(#a+1)
- for i=3,1,-1 do --WARNING! Max operator length: 3
- a=o:sub(1,i) -- a variable here used to store enabled_operators[posible operator]
- b=O[a] or i<2 and a
- if b and #o>0 then --if O[posible_operator] -> C SuS SuS enabled operator (or something else) found and must be parced
- b=C.C(a,b,i) or b -- CORE module call
- if 7>#type(b) then --type<7 -> string; >7 - function | these can't be any othere values
- R[#R+1]=b --string located
- o=o:sub(i+1)
- else
- b={b(C,o,w,i)} --if there is a special replacement function
- o,w=b[1] or o:sub(i+1),b[2] or w
- end
- break -- operator found! break out...
- end
- end
- end
- --WORD
- if #w>0 then
- w=C.C(nil,w,i) or w --CORE module call
- R[#R+1]=w
- end
- end
- end
- end
- --FINISH COMPILE
- for k,v in pairs(C.F)do
- local a,n,m,e=v(x,name,mode,env)--launch all finalizer function
- if C.rt then return a,n end -- if finaliser return something then return it vithout calling native load
- x=a or x
- name=n or name
- mode=m or mode
- env=e or env
- end
- x=table.concat(R)
- if mode=="c" then return R end
- end
- end
- return NL(x,name,mode,env)
- end
- --COMPILLER CORES AND MODULES:load other features of compiler using compiler ITSELF
- a,b=L([=[<K,E,F>
- F.K[';']=C,o,w=> -- any ";" that stand near ";,)]" or "\n" will be replaced by " end " for ex ";;" equal to " end end "
- @a,p=o:match"(;*) *([%S\n]?)%s*"
- /|#p>0&&p~="("||#a>1?
- for i=1,#a do
- C.R[#C.R+1]=K[10]
- /|C.L?C.C.L("end");--K[10]="end"
- end
- \|C.R[#C.R+1]=";";
- $o:sub(#a+1);
- --OBJ: object separator function
- OBJ=o=>$type(o)=='string'&&o:match"%S+"||"";
- do--CSSC Environmet table (CC:T-f)
- @o=setmetatable({},{__index=os})
- clone=value,arg=>
- @D,v,a=debug,value,arg||{}
- @t=type(v)
- /|t=="function"?
- @I=D.getinfo(v)
- @f=NL(t.dump(v),I.source,nil,a.env||getfenv(v))
- for i=1,I.nups do
- /|a.ref?D.upvaluejoin(f,i,v,i)
- \|@n,d=D.getupvalue(v,i)D.setupvalue(f,i,d);
- end $f
- :|t=="table"?
- t={}for k,v in pairs(v)do t[k]=v end
- $setmetatable(t,a.meta||getmetatable(v));;
- @m={__index=_G}
- env={os=o,
- clone=clone,
- load=L,
- loadfile=clone(loadfile,{env=setmetatable({load=L},m)}),
- include=name,force=>
- @e=getfenv(2)
- @r=e.require
- /|!r?error("Unable to include '"..name.."', _ENV has no require function!",2);
- @f,t=pcall(r,name)
- /|!f?error(t,2);
- for k,v in pairs(t)do
- e[k]=!force&&e[k]||v
- end $t;}
- @e={env=setmetatable({loadfile=env.loadfile},m)}
- o.run=clone(os.run,e)
- o.loadAPI=clone(os.loadAPI,e)
- end
- --Error detector
- err=C,s=>C.err=C.err||"SuS["..C.l.."]:"..s;
- F.err={C=>
- C.F.err==>
- /|C.err?C.rt=1$ nil,C.err;;;}
- --Preload feature
- F.pre={C,V,x,n,m,e=>
- /|!cssc.preload?cssc.preload={};
- @P=cssc.preload
- /|P[V]?$NL(P[V],n,m,e);
- C.F.pre==>P[V]=table.concat(C.R);;}
- --Debug feature (old debug will be removed in final version)
- F.dbg={C,V=>-- V - argument
- @v=V
- C.F.dbg=x,n,m=>
- /|v=="P"?require"cc.pretty".pretty_print(C.R)
- :|v=="p"?print(table.concat(C.R));
- /|m=="c"?C.rt=1$C.R
- :|m=="s"?C.rt=1$table.concat(C.R);;;}
- --0b0000000 and 0o0000.000 number format support (avaliable exponenta: E+-x)
- F.b={C=>--return function that will be inserted in special extensions table
- F.c[1](C)
- C.C.W.b=o,w=>
- @a,b,c,r,t=w:match"^0([bo])(%d*)([eE]?.*)" --RUSH EEEEEEEEEEEEE for exponenta
- /|C.b&&C.R[#C.R]=="."?t,b,c=C.b,w:match"(%d+)([eE]?.*)"--b located! posible floating point!
- \|C.b=nil;
- /|b?--number exist
- t,r=t||(a>"b"&&"8"||"2"),0--You are a good person if you read this (^_^)
- for i,k in b:gmatch"()(.)"do
- /|k>=t?err(C,"This is not a valid number: 0"..a..b..c);--if number is weird
- r=r+k*t^(#b-i)-- t: number base system, r - result, i - current position in number string
- end
- r=C.b&&tostring(r/t^#b):sub(3)||r--this is a floating point! recalculate required!
- C.b=!C.b&&#c<1&&t||nil--floating point support
- $r..c;;;}
- --This function works as #include directive in C++
- --include"module" inserts all module values to _ENV (_ENV must have 'require' inside it!)
- do
- -- Add path
- @N=fs.combine
- adp=str,full=>cssc.path=full and cssc.path..N(str,"?;")..N(str,"?.lua;")..N(str,"?/init.lua;")or cssc.path..str..";";
- --ATP: Attempt to perform
- ATP=C,wt,on=>err(C,"Attempt to perform '"..wt.."' on '"..on.."'!");
- --C SuS SuS LANGUAGE CORE
- F.c={C=>
- /|C.CR?$;
- C.CR=1--mark & skip
- C.L={{st=1,t="main"},o={},c={}}--leveling table [o -> on lvl open, c -> on lvl close]
- @l=C.L
- @r=C.R
- --add uncatched operators
- for k in("=~<>"):gfind"."do k=k..'='C.O[k]=k end
- --EVENT invocator
- @f=T,o,w,i=>for k,v in pairs(T)do w=v(o,w,i)or w end $w;
- --table print f
- @pt=t=>@r=""for k in pairs(t)do r=r..k.."' or '"end$r:sub(1,-7);
- --CORE table
- C.C={W={},O={},A={},K={},o={['and']=1,['or']=1,['not']=1}, -- o for operators
- --LEVELING controller
- 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)
- L=o,v=>/|v?l[#l+1]=f(l.o,o,{t=o}) -- level+
- \|@e=C.C.l[l[#l].t] -- level-
- @t=#type(e)==5
- /|!t&&e&&e~=o||t&&!e[o]?err(C,"Expected '"..(te&&pt(e)||e).."' after '"..l[#l].t.."' but got '"..o.."'!");--level error detection
- /|#l<2?err(C,"Unexpected '"..o.."'!");
- @cl=l[#l]
- l[#l]=#l<2&&l[#l]||nil
- f(l.c,o,cl);;}-- level-
- @c=C.C
- C.F[1]=x,n,m,e=>
- /|#l>1?err(C,"Unclosed construction! Missing '"..(c.l[l[#l].t]||"end").."'!"..#l);
- @p=e&&e.package --CC:T require
- /|p?p.path=p.path..cssc.path--if package.path exist then add additional path
- setfenv(p.loaders[2],setmetatable({loadfile=env.loadfile},{_index=_G}))
- for k,v in pairs(env)do e[k]=rawget(e,k)||v end;;
- --CORE function
- setmetatable(C.C,{__call=S,o,w,i=>
- /|o=='"'||o=='\0'?$;--skip string markers and comments
- C.pv=C.cv -- set previous value
- C.cv=nil
- /|#type(w)==6?
- @ow=OBJ(w)
- @k=Kb[ow]--get keyword id if keyword
- /|k?C.cv=1--KEYWORD
- --keywords leveling part
- /|k>5&&k<12?c.L(ow);--end level
- /|k<10?c.L(ow,1); --open level
- w=f(c.K,o,w,i)||w
- :|c.o[ow]?C.cv=2 w=f(c.O,o,w,i)||w;;--OPERATOR (and or not)
- /|!C.cv?
- /|!o?C.cv=w:find"^['\"%[]"&&6||3 w=f(c.W,o,w,i)||w --KEYWORD(1) WORD(3) STRING(6)
- \|C.cv=o:find"^[%[%({]"&&4||o:find"^[%]%)}]"&&5||2
- /|C.cv==4?c.L(o,1); --breaket+
- /|C.cv==5?c.L(o); --breaket-
- w=f(c.O,o,w,i)||w;; --OPERATOR(2) BREAKET_OPEN(4) BREAKET_CLOSE(5)
- w=f(c.A,o,w,i)||w--ALL
- $w;})
- --START SEARCHER
- --@lb=->OBJ(r[#r]):find"^ ?[%]%)}\"']";
- l.o[#l.o+1]=o,t=>--on level open
- @s=#r+1
- /|C.pv&&C.pv<3?l[#l].st=s;--previous level
- t.st=s+1;--next level table
- c.W.st=o,w=>
- @p=OBJ(r[#r])
- /|p:find"[.:]"&&#p<2?$;--default start searcher allowed operators
- /|C.cv==6&&C.pv>2?$;--current word is string and previous word was an operator or keyword
- l[#l].st=#r+1;
- ;}
- end
- --UE:Unexpected value
- UE=C,o=>err(C,"Unexpected '"..o.."'!");
- -- Default function arguments feature
- F.D={C=>
- F.c[1](C)
- @l=C.L
- @r=C.R
- l.o[#l.o+1]=o,t=>
- /|t.t=="function"?t.ada=1;-- allow_default_args for nex level
- /|l[#l].ada?
- l[#l].ada=nil
- /|t.t=="("?t.da={};;;
- l.c[#l.c+1]=o,t=>--on level close
- l[#l].ada=nil
- /|t.da&&#t.da>0&&t.t=="("? -- da - default_args
- r[#r+1]=")"
- t.da[#t.da].nd=t.da[#t.da].nd||#r-1 --set last index if not exist
- --remove default statements and finalise default args
- for i=#t.da,1,-1 do
- --print(r[t.da[i].st],t.da[i].nd,#r,t.t)
- @ob=r[t.da[i].st-1]
- r[#r+1]="if "..ob.."==nil then "..ob.."="--insert start
- for j=t.da[i].st,t.da[i].nd do r[#r+1]=r[j]end--insert obj
- r[#r+1]=" end "--insert end
- for j=t.da[i].nd,t.da[i].st,-1 do table.remove(r,j)end--remove default arg
- end
- t.da=nil
- 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)
- C.C.O.da=o,w=> --catch coma and ';'
- @d=l[#l].da
- /|d&&o==';'?UE(C,';');
- /|d&&#d>0&&o==','?
- d[#d].nd=d[#d].nd||#r;;
- C.O[":="]=C,o,w=>
- /|!l[#l].da?UE(C,':=')--emit an error
- \|@d=l[#l].da
- d[#d+1]={st=#r+1};;
- ;}
- --Prohibited area check
- PAch=t->t:find"[{(%[]"||t=="if"||t=="elseif"||t=="for"||t=="while";
- -- Nil forgiving operators feature
- do
- @c,d=setmetatable--nil returning object | nilF feature: nil forgiving operators | d -> default c-> colon
- d=c({},{__call=->nil;,__index=->nil;})
- c=c({},{__index=->()->nil;;})
- N=(o,i)=>-- o -> object, i -> index
- /|o==nil?$i&&c||d;--> obj not exist (false and other variables are allowed)
- /|i?$o[i]&&o||c;--> obj and index exist -> colon mode
- $o;-- obj exist but not index
- F.N={C=>
- F.c[1](C)
- C.C.O.N=o=>/|F.N[o]?C.cv=C.pv;;;}--mark F.N operators as start searcher allowed (core-invisible)
- for v,k in('.:"({'):gfind"()(.)"do
- F.N['?'..k]=C,o,w=>
- @r=C.R
- /|#r<2||C.pv<3?ATP(C,k,r[#r]);--previous value was a keyword or operator
- /|o:sub(3):find"[^\0%s]"?ATP(C,OBJ(o:sub(3)),k);
- table.insert(C.R,C.L[#C.L].st," cssc.nilF(")--first part
- r[#r+1]=v==2&&",'"..w.."')"||')'
- /|v==1?--no error and index detected
- C.ci=#r--index of ?
- C.pc=#r+2-- index of word
- C.C.A.str=o=>
- /|C.pc<=#r? print(C.cv,w,r[#r],r[#r-1],r[#r-2],#r,o)
- /|C.cv>4||C.cv>3&&!o:find'^[)%]}]'?
- table.insert(r,C.ci,",'"..w.."'");
- C.C.A.str=nil;;;
- $o:sub(2);
- end
- end
- -- X= operators feature.
- --WARNING! They don't support multiple asignemnt (a,b X= *code*) - is prohibited!
- --Add initialiser function to F.K feature to enable support of &&= and ||=
- F.K[1]=C=>C.EQ={"&&","||",unpack(C.EQ||{})};
- -- ?= function
- @qeq=b,a=> --b - base, a - adition
- /|a==nil?$b
- \|$a;;
- F.C={C=>
- F.c[1](C)--load start searcher
- --EQ - table with operators that support *op*= behaviour
- C.EQ={"+","-","*","%","/","..","^","?",unpack(C.EQ||{})}
- @l=C.L
- @r=C.R
- C.C.A.br=o,w=>
- /|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
- l[#l].br=nil
- r[#r+1]=")";;
- l.c[#l.c+1]=o,t=>/|t.br?r[#r+1]=")";; -- on level end
- C.F.c==>/|l[#l].br?r[#r+1]=")";;
- --operator main parce function
- @op=C,o,w=>
- @lt=l[#l].t
- /|PAch(lt)?err(C,"Attempt to use X= operator in prohibited area! '"..lt.." *var* X= *val* "..C.C.l[lt].."'");
- /|OBJ(r[l[#l].st-1]||"")==","?err(C,"Comma detected! X= operators has no multiple assignments support!");
- /|#r<2||C.pv<3?ATP(C,k,r[#r]);
- o=o:match"(.-)="--for this we need only the first part of operator
- r[#r+1]="="..(o=="?"&&"cssc.q_eq("||"")--insert equality or ?=
- l[#l].m={bor=#r+1} --Lua5.3 feature support
- for i=l[#l].st,#r-1 do r[#r+1]=r[i]end --copy variable from the start of an object
- @t=#type(C.O[o])
- /|o=="?"?r[#r+1]=","
- :|t==6?r[#r+1]=C.O[o]--string
- :|t==3?r[#r+1]=o--operator
- \|C.O[o](C,o,w);--function
- --print(C,o,w)
- /|o~="?"?r[#r+1]="("; --add opening breaket
- l[#l].br=1 --request closing breaet for this level
- l[#l].m={bor=#r+1}; --Lua5.3 feature support
- -- main function initialiser
- for i=1,#C.EQ do C.O[C.EQ[i].."=" ]=op end;--END OF F.C
- }
- --IS keyword simular to typeof()
- @tof=o->(getmetatable(o)||{}).__type||type(o);
- @is=setmetatable({},{__concat=v,a=>$setmetatable({a},--is inited
- {__concat=v,a=> --a args v value
- /|type(a[1])=="table"?a=a[1];
- for i=1,#a do
- /|tof(v)==a[i]?$true;
- end
- $false;});})
- _G.typeof=tof--include typeof into global environment
- F.IS={C=>
- F.c[1](C)
- C.C.o['is']=1
- @l=C.L
- C.C.O[1]=o,w=>
- w=OBJ(w)
- /|w=='is'?
- /|#C.R<2||C.pv<3?ATP(C,'is',C.R[#C.R]);
- $" ..cssc.is.. ";;;}
- --Lua5.3 operators feature! Bitwise and idiv operators support!
- do
- @B={}
- for k,v in pairs(bit32)do B[k]=v end
- B.idiv=a,b->math.floor(a/b);
- B.shl=B.lshift
- B.shr=B.rshift
- @bt={shl='<<',shr='>>',bxor='~',bor='|',band='&',idiv='//'}
- @kp={}('and or , = ; > < >= <= ~= == '):gsub("%S+",(x)=>kp[x]=1;) -- all operators that has lower priority than bitise operators
- @f=t,m->"Attempt to perform "..t.." bitwise operation on a "..m.." value";
- M={bnot=setmetatable({},{
- __pow=a,b=>
- @m=(getmetatable(b)||{}).bnot
- /|m?$m(b);
- m=type(b)
- /|m~='number'?error(f('bitwise',m),3);
- $B.bnot(b);})}
- for k,v in pairs(bt)do
- @n='__'..k--name of metamethod
- @t='number'--number value type
- @e=v=='//'&&'idiv'||'bitwise'
- @f=a,b=>--base calculation function
- @m=(getmetatable(a[1])||{})[n]||(getmetatable(b)||{})[n]
- /|m?$m(a,b);--metamethod located! Calculation override!
- m=type(a[1])
- m=m==t&&type(b)||m
- /|m~=t?error(f(e,m),3);
- $B[k](a[1],b);
- M[k]=v=='//'&&{__div=f}||{__concat=f}
- end
- F.M={C=>
- C.EQ={">>","<<","&","|",unpack(C.EQ||{})}--additional equality
- F.c[1](C)--enable core
- @l=C.L
- @r=C.R
- l[#l].m={bor=1}
- --on level open
- l.o[#l.o+1]=o,t=>
- /|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
- t.m={bor=#r+2};
- --function to correct priority of sequence (set on O and on W)
- C.C.A.pc=o,w=>
- @i=#r+2
- @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
- l[#l].m.sk=nil--reset end skip
- /|b?l[#l].m={bor=i};--reset the starter table
- /|b||o&&(" .. + -"):find(' '..o..' ',1,1)?l[#l].m.idiv=i;;--start of sequence and reset!
- for k,v in pairs(bt)do
- C.O[v]=C,o,w=>
- @p=OBJ(r[#r])-- grep the value, skip the comments
- /|v=='~'&&--posible unary operator
- ((p:find"[^%)}%]'\"%P]"&&!p:find"%[=*%[")||--there is no breaket or string before op or string
- Kb[p]||kp[p])?-- there is no keyword before op
- r[#r+1]="cssc.mt.bnot^" $;--bnot located. Insert and return...
- table.insert(r,l[#l].m[k]||l[#l].m.bor||l[#l].st,"setmetatable({")
- r[#r+1]="},cssc.mt."..k..(v=='//'&&')/'||')..')
- @i=#r+1
- @l=l[#l]
- /|v=='|'?l.m.bxor=i;
- /|v:find'[|~]'?l.m.band=i;
- /|v:find'[|~&]'?l.m.shl,l.m.shr,l.m.idiv=i,i,i;-- Full support of bitwizes!111 Finaly!
- /|v:find"([><])%1"?l.m.idiv=i;;-- Full support of idiv
- end;}
- end
- --DEFAULT: ALL INCLUSIVE (E feature disabled!)
- F.A={C=>
- F.M[1](C) -- Lua5.3 opts
- F.K[1](C) -- Keyword shortcuts
- F.IS[1](C)-- IS keyword
- F.N[1](C) -- nil forgiving operators
- F.C[1](C) -- X= operators
- F.D[1](C) -- default function arguments
- F.b[1](C) -- octal and binary number formats
- C.O['..']=' ..' --fix number concatenation bug
- for K,V in pairs{F.K,F.F}do
- for k,v in pairs(V)do
- C.O[k]=v
- end
- end
- ;}
- _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}
- ]=],"SuS",nil,_ENV)--]=]
- b=b and error(b)
- a=a and a(...)
- ]=============] -- 13
- cssc_api["Minified"]=[==============[
- K={}
- Ks="if function for while repeat elseif else do then end until local return in break "
- Kb={}
- Ks:gsub("(%S+)( )", function (x,s)K[#K+1]=s..x..s Kb[x]=#K end )
- NL=load
- a,b=NL(([=[
- local l=C,o)
- local i,a,e,p=#R,1
- e=R[i]
- p=e"^%)%s*""" "("
- while i>0(#p>0(a(e:[%w_]+" "."e) ","e) #p<1 not e"^%(%s*")do
- i,a=i-1,not a
- e=R[i] end
- .insert(R,#p<1i i+1,K[2]p)
- R[#R+1]=(#p>0")" "")(o1,1)"-"K[13] "")
- if L
- pv=2
- L("function",1)
- end
- end
- F={
- E={ ["/|"]=K[1],
- ["?"]=K[9],
- [":|"]=K[6],
- ["\\|"]=K[7]},
- K={ ["@"]=K[12],
- ["$"]=K[13],
- ["||"]=" ",
- ["&&"]="",
- ["!"]=" not ",
- [";"]=K[10]},
- F={ ["->"]=l,
- ["=>"]=l}
- }
- L=x,name,mode,env)
- if x)"string"
- local c=x:^<.->" x:^#!.-\n?<.->"
- if c
- local po,R,O,C,s,t,a,b,l,e="",{""},{['"']=),["\0"]=C) local r=R r[#r]=r[#r]" "(.remove(c,1) ""),['']='',['.']='.'}
- x=x#c+1)
- C={O=O,C=),R=R,F={},c={},l=1,pv=1}
- fK,V in c:g([%w_]+)%(?([%w_. ]*)" if F[K]
- fF[K])do O[k]=v end
- l=F[K][1]F[K][1](C,V,x,name,mode,env)
- if ll
- end
- O[1]=
- l=#x+1
- f,i in x:g([%s!#-&(-/:-@\\-^{-~`]*%[?=*[%['\"]?%s*)([%w_]*[^%w%p%[-`{-~\\-_%s]*[^\n%S]*)()"
- o:gsub("\n",)l=l+1)
- if s then
- a,b,e=o(#s<2"(\\*[\n"s"])%s*" "(%]=*%])%s*")
- if a(#s<2(s"\n" #e%2>0) #s#e) il
- b=b i
- t=to0,b)
- if cc=c
- t=C(,t,i)t
- c=R
- end
- c[#c+1]=t
- o=poob+1)
- s,t=
- t=tow
- end
- end
- if not s then
- o=o:gsub("-%-%s-\n","\n")
- c=o:-%-%[?=*%[?"
- s=o:%[=*%["o:['\"]"
- if c s then
- a=o(c s,1,1)
- s=c(c3)ss "\n") s
- t,w=oa)w,""
- o=o0,a-1)(c"\0" '"')
- po=c(o "") ""
- end
- if not c il then
- while #o>0 a=o:^%s*"
- R[#R]=R[#R]a
- o=o#a+1)
- fi=3,1,-1 do
- a=o1,i)
- b=O[a] i<2a
- if b#o>0
- b=C(a,b,i) b
- if 7>#b)
- R[#R+1]=b
- o=oi+1)
- b={b(C,,i)}
- =b[1] oi+1),b[2] w
- end
- break
- end
- end
- end
- if #w>0 then
- w=C(,w,i) w
- R[#R+1]=w
- end
- end
- end
- fF) local a,n,m,e=v(x,name,mode,env)
- if rta,n
- x=a x
- name=n name
- mode=m mode
- env=e env
- end
- x=.concat(R)
- if mode"c"R
- end
- end
- NL(x,name,mode,env)
- end
- F.K[';']=C,)
- local a,p=o:(;*) *([%S\n]?)%s*"
- if #p>0p~="(" #a>1
- fi=1,#a R[#R+1]=K[10]
- if LL("end")
- end
- R[#R+1]=";"
- o#a+1)
- OBJ=o)o)'string'o:%S+" ""
- do o=s({},{__index=os})
- clone=value,arg)
- local D,v,a=debug,value,arg {}
- local t=v)
- if t"function"
- local I=D.getinfo(v)
- local f=NL(t.dump(v),I.source,,a.env getfenv(v))
- fi=1,I.nups if a.refD.upvaluejoin(f,i,v,i)
- local n,d=D.getupvalue(v,i)D.setupvalue(f,i,d)
- f
- if t""
- t={}fv)do t[k]=v
- s(t,a.meta g(v))m={__index=_G}
- env={os=o,
- clone=clone,
- load=L,
- loadfile=clone(loadfile,{env=s({load=L},m)}),
- include=name,force)
- local e=getfenv(2)
- local r=e.require
- if not rerror("Unable to include '"name"', _ENV has no require function!",2)
- local f,t=pcall(r,name)
- if not ferror(t,2)
- ft) e[k]= not forcee[k] v
- t}
- e={env=s({loadfile=env.loadfile},m)}
- o.run=clone(os.run,e)
- o.loadAPI=clone(os.loadAPI,e)
- end
- err=C,s)err=err "SuS["l"]:"s
- F.err={C)
- F.err=)
- if errrt=1 ,err}
- F.pre={C,V,x,n,m,e)
- if not cssc.preloadcssc.preload={}
- local P=cssc.preload
- if P[V]NL(P[V],n,m,e)
- F.pre=)P[V]=.concat(R)}
- F.dbg={C,V)
- local v=V
- F.dbg=x,n,m)
- if v"P"require"cc.pretty".pretty_print(R)
- if v"p"print(.concat(R))
- if m"c"rt=1R
- if m"s"rt=1.concat(R)}
- F.b={C)
- F.c
- W.b=)
- local a,b,c,r,t=w:^0([bo])(%d*)([eE]?.*)"
- if bR[#R]"."t,b,c=b,w:(%d+)([eE]?.*)"
- b=
- if b
- t,r=t (a>"b""8" "2"),0
- fi,k in b:g()(.)" if k>=terr(C,"This is not a valid number: 0"abc)
- r=r+k*t^(#b-i)
- end
- r=btostring(r/t^#b)3) r
- b= not b#c<1t
- rc}
- N=fs.combine
- adp=str,full)cssc.path=fullcssc.pathN(str,"?;")N(str,"?.lua;")N(str,"?/init.lua;")cssc.pathstr";"
- ATP=C,wt,on)err(C,"Attempt to perform '"wt"' on '"on"'!")
- F.c={C)
- if CR
- CR=1
- L={{st=1,t="main"},o={},c={}}
- local l=L
- local r=R
- fk in("=~<>"):gfind"."do k=k'='O[k]=k end
- local f=T,,i)fT)do w=v(,i)ww
- local pt=t) local r=""fk in pairs(t)do r=rk"' '"endr1,-7)
- C={W={},O={},A={},K={},o={['and']=1,['or']=1,['not']=1},
- l={["for"]="do",["while"]="do",["repeat"]="until",["if"]="then",["then"]={[""]=1,["if"]=1,["end"]=1},["if"]="then",[""]="end",["do"]="end",["function"]="end",["{"]="}",["("]=")",["["]="]"},
- L=o,v) if vl[#l+1]=f(l.o,o,{t=o})
- local e=l[t]
- local t=#e)5
- if not tee~=o t not e[o]err(C,"Expected '"(tept(e) e)"' after '"t"' but got '"o"'!")
- if #l<2err(C,"Unexpected '"o"'!")
- local cl=l[#l]
- l[#l]=#l<2l[#l]
- f(l.c,o,cl)}
- local c=C
- F[1]=x,n,m,e)
- if #l>1err(C,"Unclosed construction! Missing '"(c.l[t] "end")"'!"#l)
- local p=ee.package
- if pp.path=p.pathcssc.path
- setfenv(p.loaders[2],s({loadfile=env.loadfile},{_index=_G}))
- fenv)do e[k]=rawget(e,k) vend
- s(C,{__call=S,,i)
- if o'"' o'\0'
- pv=cv
- cv=
- if #w)6
- local ow=OBJ(w)
- local k=Kb[ow]
- if kcv=1
- if k>5k<12c.L(ow)
- if k<10c.L(ow,1)
- w=f(c.K,,i) w
- if c.o[ow]cv=2 w=f(c.O,,i) w
- if not cv
- if not ocv=w"^['\"%[]"6 3 w=f(c.W,,i) w
- cv=o"^[%[%({]"4 o"^[%]%)}]"5 2
- if cv4c.L(o,1)
- if cv5c.L(o)
- w=f(c.O,,i) w
- w=f(c.A,,i) w
- w})
- l.o[#l.o+1]=o,t)
- local s=#r+1
- if pvpv<3st=s
- t.st=s+1
- c.W.st=)
- local p=OBJ(r[#r])
- if p"[.:]"#p<2
- if cv6pv>2
- st=#r+1
- }
- end
- UE=C,o)err(C,"Unexpected '"o"'!")
- F.D={C)
- F.c
- local l=L
- local r=R
- l.o[#l.o+1]=o,t)
- if t.t"function"t.ada=1
- if ada
- ada=
- if t.t"("t.da={}
- l.c[#l.c+1]=o,t)
- ada=
- if t.da#t.da>0t.t"("
- ")"
- t.da[#t.da].nd=t.da[#t.da].nd #r-1
- fi=#t.da,1,-1
- local ob=r[t.da[i].st-1]
- "if "ob""ob"="
- fj=t.da[i].st,t.da[i].nd do r[j]end
- ""
- fj=t.da[i].nd,t.da[i].st,-1 do .remove(r,j)end
- end
- t.da=
- A.da=)A.da=)
- O.da=)
- local d=da
- if do';'UE(C,';')
- if d#d>0o','
- d[#d].nd=d[#d].nd #r
- O[":="]=C,)
- if not daUE(C,':=')
- local d=da
- d[#d+1]={st=#r+1}
- }
- PAch=t)t"[{(%[]" t"if" t"if" t"for" t"while"
- doc,d=s
- d=c({},{__call=),__index=)})
- c=c({},{__index=))})
- N=o,i)
- if oic d
- if io[i]o c
- o
- F.N={C)
- F.c
- O.N=o) if F.N[o]cv=pv}
- fv,k in('.:"({'):gfind"()(.)" F.N['?'k]=C,)
- local r=R
- if #r<2 pv<3ATP(C,k,r[#r])
- if o3)"[^\0%s]"ATP(C,OBJ(o3)),k)
- .insert(R,L[#L].st," cssc.F(")
- v2",'"w"')" ')'
- if v1
- ci=#r
- pc=#r+2
- A.str=o)
- if pc<=#r print(cv,w,r[#r],r[#r-1],r[#r-2],#r,o)
- if cv>4 cv>3 not o'^[)%]}]'
- .insert(r,ci,",'"w"'")
- A.str=
- o2)
- end
- end
- F.K[1]=C)EQ={"&&","||",unpack(EQ {})}
- qeq=b,a) ab
- a
- F.C={C)
- F.c
- EQ={"+","-","*","%","/","","^","?",unpack(EQ {})}
- local l=L
- local r=R
- A.br=)
- if br(pv3 pv>4)(cv1 cv3 (o',' o';'))
- br=
- ")"
- l.c[#l.c+1]=o,t) if t.br")"
- F.c=) if br")"
- local op=C,)
- local lt=t
- if PAch(lt)err(C,"Attempt to use X= operatin prohibited area! '"lt" *var* X= *val* "l[lt]"'")
- if OBJ(r[st-1] "")","err(C,"Comma detected! X= operators has no multiple assignments support!")
- if #r<2 pv<3ATP(C,k,r[#r])
- o=o:(.-)="
- "="(o"?""cssc.q_eq(" "")
- m={bor=#r+1}
- fi=st,#r-1 do r[i]end
- local t=#O[o])
- if o"?"","
- if t6O[o]
- if t3o
- O[o](C,)
- if o~="?""("
- br=1
- m={bor=#r+1}
- fi=1,#EQ do O[EQ[i]"=" ]=opend
- }
- tof=o)(g(o) {}).__type o)is=s({},{__concat=v,a)s({a},
- {__concat=v,a)
- if a[1])""a=a[1]
- fi=1,#a if tof(v)a[i]true
- end
- false})})
- _G.typeof=tof
- F.IS={C)
- F.c
- o['is']=1
- local l=L
- O[1]=)
- w=OBJ(w)
- if w'is'
- if #R<2 pv<3ATP(C,'is',R[#R])
- " cssc.is "}
- doB={}
- fbit32)do B[k]=v end
- B.idiv=a,b)math.floor(a/b)
- B.shl=B.lshift
- 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"
- M={bnot=s({},{
- __pow=a,b)
- local m=(g(b) {}).bnot
- if mm(b)
- m=b)
- if m~='number'error(f('bitwise',m),3)
- B.bnot(b)})}
- fbt) local n='__'k
- local t='number'
- local e=v'//''idiv' 'bitwise'
- local f=a,b)
- local m=(g(a[1]) {})[n] (g(b) {})[n]
- if mm(a,b)
- m=a[1])
- m=mtb) m
- if m~=terror(f(e,m),3)
- B[k](a[1],b)
- M[k]=v'//'{__div=f} {__concat=f}
- end
- F.M={C)
- EQ={">>","<<","&","|",unpack(EQ {})}
- F.c
- local l=L
- local r=R
- m={bor=1}
- l.o[#l.o+1]=o,t)
- if o"function"pv2m.sk=1
- t.m={bor=#r+2}
- A.pc=)
- local i=#r+2
- local b=cv<2 not m.sk okp[o]
- m.sk=
- if bm={bor=i}
- if b o(" + -")(' 'o' ',1,1)m.idiv=i
- fbt) O[v]=C,)
- local p=OBJ(r[#r])
- if v'~'
- ((p"[^%)}%]'\"%P]" not p"%[=*%[")
- Kb[p] kp[p])
- "cssc.mt.bnot^"
- .insert(r,m[k] m.bst,"s({")
- "},cssc.mt."k(v'//'')/' ')')
- local i=#r+1
- local l=l[#l]
- if v'|'l.m.bxor=i
- if v'[|~]'l.m.band=i
- if v'[|~&]'l.m.shl,l.m.shr,l.m.idiv=i,i,i
- if v"([><])%1"l.m.idiv=i
- end }
- end
- F.A={C)
- F.M
- F.K
- F.IS
- F.N
- F.C
- F.D
- F.b
- O['']=' '
- fK,V in pairs{F.K,F.F} fV) O[k]=v
- end
- end
- }
- _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}
- ]=]):gsub('.',{[""]=" function (",[""]="\
- local ",[""]=" and ",[""]=" return ",[""]="or ",[""]="etmeta",[""]="table",[""]=" then ",[""]="\
- if ",[""]=" end ",[""]=":find",[""]="match\"",[""]="else",[""]="[1](C)",[""]="k,v in pairs(",[""]="l[#l].",[""]=":sub(",[""]="C.",[""]="..",[""]="r[#r+1]=",[""]="==",[""]="type(",[""]="o,w",[""]="nil",[""]="do\
- "}),'SuS',nil,_ENV)
- b=b and error(b)
- a=a and a()]==============] -- 14
- env_pack["Original"]=[===============[
- K={}
- Ks="if function for while repeat elseif else do then end until local return in break "
- Kb={}
- Ks:gsub("(%S+)( )", function (x,s)K[#K+1]=s..x..s Kb[x]=#K end )
- NL=load
- a,b=NL(([=[
- local l=C,o)
- local i,a,e,p=#R,1
- e=R[i]
- p=e"^%)%s*""" "("
- while i>0(#p>0(a(e:[%w_]+" "."e) ","e) #p<1 not e"^%(%s*")do
- i,a=i-1,not a
- e=R[i] end
- .insert(R,#p<1i i+1,K[2]p)
- R[#R+1]=(#p>0")" "")(o1,1)"-"K[13] "")
- if L
- pv=2
- L("function",1)
- end
- end
- F={
- E={ ["/|"]=K[1],
- ["?"]=K[9],
- [":|"]=K[6],
- ["\\|"]=K[7]},
- K={ ["@"]=K[12],
- ["$"]=K[13],
- ["||"]=" ",
- ["&&"]="",
- ["!"]=" not ",
- [";"]=K[10]},
- F={ ["->"]=l,
- ["=>"]=l}
- }
- L=x,name,mode,env)
- if x)"string"
- local c=x:^<.->" x:^#!.-\n?<.->"
- if c
- local po,R,O,C,s,t,a,b,l,e="",{""},{['"']=),["\0"]=C) local r=R r[#r]=r[#r]" "(.remove(c,1) ""),['']='',['.']='.'}
- x=x#c+1)
- C={O=O,C=),R=R,F={},c={},l=1,pv=1}
- fK,V in c:g([%w_]+)%(?([%w_. ]*)" if F[K]
- fF[K])do O[k]=v end
- l=F[K][1]F[K][1](C,V,x,name,mode,env)
- if ll
- end
- O[1]=
- l=#x+1
- f,i in x:g([%s!#-&(-/:-@\\-^{-~`]*%[?=*[%['\"]?%s*)([%w_]*[^%w%p%[-`{-~\\-_%s]*[^\n%S]*)()"
- o:gsub("\n",)l=l+1)
- if s then
- a,b,e=o(#s<2"(\\*[\n"s"])%s*" "(%]=*%])%s*")
- if a(#s<2(s"\n" #e%2>0) #s#e) il
- b=b i
- t=to0,b)
- if cc=c
- t=C(,t,i)t
- c=R
- end
- c[#c+1]=t
- o=poob+1)
- s,t=
- t=tow
- end
- end
- if not s then
- o=o:gsub("-%-%s-\n","\n")
- c=o:-%-%[?=*%[?"
- s=o:%[=*%["o:['\"]"
- if c s then
- a=o(c s,1,1)
- s=c(c3)ss "\n") s
- t,w=oa)w,""
- o=o0,a-1)(c"\0" '"')
- po=c(o "") ""
- end
- if not c il then
- while #o>0 a=o:^%s*"
- R[#R]=R[#R]a
- o=o#a+1)
- fi=3,1,-1 do
- a=o1,i)
- b=O[a] i<2a
- if b#o>0
- b=C(a,b,i) b
- if 7>#b)
- R[#R+1]=b
- o=oi+1)
- b={b(C,,i)}
- =b[1] oi+1),b[2] w
- end
- break
- end
- end
- end
- if #w>0 then
- w=C(,w,i) w
- R[#R+1]=w
- end
- end
- end
- fF) local a,n,m,e=v(x,name,mode,env)
- if rta,n
- x=a x
- name=n name
- mode=m mode
- env=e env
- end
- x=.concat(R)
- if mode"c"R
- end
- end
- NL(x,name,mode,env)
- end
- F.K[';']=C,)
- local a,p=o:(;*) *([%S\n]?)%s*"
- if #p>0p~="(" #a>1
- fi=1,#a R[#R+1]=K[10]
- if LL("end")
- end
- R[#R+1]=";"
- o#a+1)
- OBJ=o)o)'string'o:%S+" ""
- do o=s({},{__index=os})
- clone=value,arg)
- local D,v,a=debug,value,arg {}
- local t=v)
- if t"function"
- local I=D.getinfo(v)
- local f=NL(t.dump(v),I.source,,a.env getfenv(v))
- fi=1,I.nups if a.refD.upvaluejoin(f,i,v,i)
- local n,d=D.getupvalue(v,i)D.setupvalue(f,i,d)
- f
- if t""
- t={}fv)do t[k]=v
- s(t,a.meta g(v))m={__index=_G}
- env={os=o,
- clone=clone,
- load=L,
- loadfile=clone(loadfile,{env=s({load=L},m)}),
- include=name,force)
- local e=getfenv(2)
- local r=e.require
- if not rerror("Unable to include '"name"', _ENV has no require function!",2)
- local f,t=pcall(r,name)
- if not ferror(t,2)
- ft) e[k]= not forcee[k] v
- t}
- e={env=s({loadfile=env.loadfile},m)}
- o.run=clone(os.run,e)
- o.loadAPI=clone(os.loadAPI,e)
- end
- err=C,s)err=err "SuS["l"]:"s
- F.err={C)
- F.err=)
- if errrt=1 ,err}
- F.pre={C,V,x,n,m,e)
- if not cssc.preloadcssc.preload={}
- local P=cssc.preload
- if P[V]NL(P[V],n,m,e)
- F.pre=)P[V]=.concat(R)}
- F.dbg={C,V)
- local v=V
- F.dbg=x,n,m)
- if v"P"require"cc.pretty".pretty_print(R)
- if v"p"print(.concat(R))
- if m"c"rt=1R
- if m"s"rt=1.concat(R)}
- F.b={C)
- F.c
- W.b=)
- local a,b,c,r,t=w:^0([bo])(%d*)([eE]?.*)"
- if bR[#R]"."t,b,c=b,w:(%d+)([eE]?.*)"
- b=
- if b
- t,r=t (a>"b""8" "2"),0
- fi,k in b:g()(.)" if k>=terr(C,"This is not a valid number: 0"abc)
- r=r+k*t^(#b-i)
- end
- r=btostring(r/t^#b)3) r
- b= not b#c<1t
- rc}
- N=fs.combine
- adp=str,full)cssc.path=fullcssc.pathN(str,"?;")N(str,"?.lua;")N(str,"?/init.lua;")cssc.pathstr";"
- ATP=C,wt,on)err(C,"Attempt to perform '"wt"' on '"on"'!")
- F.c={C)
- if CR
- CR=1
- L={{st=1,t="main"},o={},c={}}
- local l=L
- local r=R
- fk in("=~<>"):gfind"."do k=k'='O[k]=k end
- local f=T,,i)fT)do w=v(,i)ww
- local pt=t) local r=""fk in pairs(t)do r=rk"' '"endr1,-7)
- C={W={},O={},A={},K={},o={['and']=1,['or']=1,['not']=1},
- l={["for"]="do",["while"]="do",["repeat"]="until",["if"]="then",["then"]={[""]=1,["if"]=1,["end"]=1},["if"]="then",[""]="end",["do"]="end",["function"]="end",["{"]="}",["("]=")",["["]="]"},
- L=o,v) if vl[#l+1]=f(l.o,o,{t=o})
- local e=l[t]
- local t=#e)5
- if not tee~=o t not e[o]err(C,"Expected '"(tept(e) e)"' after '"t"' but got '"o"'!")
- if #l<2err(C,"Unexpected '"o"'!")
- local cl=l[#l]
- l[#l]=#l<2l[#l]
- f(l.c,o,cl)}
- local c=C
- F[1]=x,n,m,e)
- if #l>1err(C,"Unclosed construction! Missing '"(c.l[t] "end")"'!"#l)
- local p=ee.package
- if pp.path=p.pathcssc.path
- setfenv(p.loaders[2],s({loadfile=env.loadfile},{_index=_G}))
- fenv)do e[k]=rawget(e,k) vend
- s(C,{__call=S,,i)
- if o'"' o'\0'
- pv=cv
- cv=
- if #w)6
- local ow=OBJ(w)
- local k=Kb[ow]
- if kcv=1
- if k>5k<12c.L(ow)
- if k<10c.L(ow,1)
- w=f(c.K,,i) w
- if c.o[ow]cv=2 w=f(c.O,,i) w
- if not cv
- if not ocv=w"^['\"%[]"6 3 w=f(c.W,,i) w
- cv=o"^[%[%({]"4 o"^[%]%)}]"5 2
- if cv4c.L(o,1)
- if cv5c.L(o)
- w=f(c.O,,i) w
- w=f(c.A,,i) w
- w})
- l.o[#l.o+1]=o,t)
- local s=#r+1
- if pvpv<3st=s
- t.st=s+1
- c.W.st=)
- local p=OBJ(r[#r])
- if p"[.:]"#p<2
- if cv6pv>2
- st=#r+1
- }
- end
- UE=C,o)err(C,"Unexpected '"o"'!")
- F.D={C)
- F.c
- local l=L
- local r=R
- l.o[#l.o+1]=o,t)
- if t.t"function"t.ada=1
- if ada
- ada=
- if t.t"("t.da={}
- l.c[#l.c+1]=o,t)
- ada=
- if t.da#t.da>0t.t"("
- ")"
- t.da[#t.da].nd=t.da[#t.da].nd #r-1
- fi=#t.da,1,-1
- local ob=r[t.da[i].st-1]
- "if "ob""ob"="
- fj=t.da[i].st,t.da[i].nd do r[j]end
- ""
- fj=t.da[i].nd,t.da[i].st,-1 do .remove(r,j)end
- end
- t.da=
- A.da=)A.da=)
- O.da=)
- local d=da
- if do';'UE(C,';')
- if d#d>0o','
- d[#d].nd=d[#d].nd #r
- O[":="]=C,)
- if not daUE(C,':=')
- local d=da
- d[#d+1]={st=#r+1}
- }
- PAch=t)t"[{(%[]" t"if" t"if" t"for" t"while"
- doc,d=s
- d=c({},{__call=),__index=)})
- c=c({},{__index=))})
- N=o,i)
- if oic d
- if io[i]o c
- o
- F.N={C)
- F.c
- O.N=o) if F.N[o]cv=pv}
- fv,k in('.:"({'):gfind"()(.)" F.N['?'k]=C,)
- local r=R
- if #r<2 pv<3ATP(C,k,r[#r])
- if o3)"[^\0%s]"ATP(C,OBJ(o3)),k)
- .insert(R,L[#L].st," cssc.F(")
- v2",'"w"')" ')'
- if v1
- ci=#r
- pc=#r+2
- A.str=o)
- if pc<=#r print(cv,w,r[#r],r[#r-1],r[#r-2],#r,o)
- if cv>4 cv>3 not o'^[)%]}]'
- .insert(r,ci,",'"w"'")
- A.str=
- o2)
- end
- end
- F.K[1]=C)EQ={"&&","||",unpack(EQ {})}
- qeq=b,a) ab
- a
- F.C={C)
- F.c
- EQ={"+","-","*","%","/","","^","?",unpack(EQ {})}
- local l=L
- local r=R
- A.br=)
- if br(pv3 pv>4)(cv1 cv3 (o',' o';'))
- br=
- ")"
- l.c[#l.c+1]=o,t) if t.br")"
- F.c=) if br")"
- local op=C,)
- local lt=t
- if PAch(lt)err(C,"Attempt to use X= operatin prohibited area! '"lt" *var* X= *val* "l[lt]"'")
- if OBJ(r[st-1] "")","err(C,"Comma detected! X= operators has no multiple assignments support!")
- if #r<2 pv<3ATP(C,k,r[#r])
- o=o:(.-)="
- "="(o"?""cssc.q_eq(" "")
- m={bor=#r+1}
- fi=st,#r-1 do r[i]end
- local t=#O[o])
- if o"?"","
- if t6O[o]
- if t3o
- O[o](C,)
- if o~="?""("
- br=1
- m={bor=#r+1}
- fi=1,#EQ do O[EQ[i]"=" ]=opend
- }
- tof=o)(g(o) {}).__type o)is=s({},{__concat=v,a)s({a},
- {__concat=v,a)
- if a[1])""a=a[1]
- fi=1,#a if tof(v)a[i]true
- end
- false})})
- _G.typeof=tof
- F.IS={C)
- F.c
- o['is']=1
- local l=L
- O[1]=)
- w=OBJ(w)
- if w'is'
- if #R<2 pv<3ATP(C,'is',R[#R])
- " cssc.is "}
- doB={}
- fbit32)do B[k]=v end
- B.idiv=a,b)math.floor(a/b)
- B.shl=B.lshift
- 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"
- M={bnot=s({},{
- __pow=a,b)
- local m=(g(b) {}).bnot
- if mm(b)
- m=b)
- if m~='number'error(f('bitwise',m),3)
- B.bnot(b)})}
- fbt) local n='__'k
- local t='number'
- local e=v'//''idiv' 'bitwise'
- local f=a,b)
- local m=(g(a[1]) {})[n] (g(b) {})[n]
- if mm(a,b)
- m=a[1])
- m=mtb) m
- if m~=terror(f(e,m),3)
- B[k](a[1],b)
- M[k]=v'//'{__div=f} {__concat=f}
- end
- F.M={C)
- EQ={">>","<<","&","|",unpack(EQ {})}
- F.c
- local l=L
- local r=R
- m={bor=1}
- l.o[#l.o+1]=o,t)
- if o"function"pv2m.sk=1
- t.m={bor=#r+2}
- A.pc=)
- local i=#r+2
- local b=cv<2 not m.sk okp[o]
- m.sk=
- if bm={bor=i}
- if b o(" + -")(' 'o' ',1,1)m.idiv=i
- fbt) O[v]=C,)
- local p=OBJ(r[#r])
- if v'~'
- ((p"[^%)}%]'\"%P]" not p"%[=*%[")
- Kb[p] kp[p])
- "cssc.mt.bnot^"
- .insert(r,m[k] m.bst,"s({")
- "},cssc.mt."k(v'//'')/' ')')
- local i=#r+1
- local l=l[#l]
- if v'|'l.m.bxor=i
- if v'[|~]'l.m.band=i
- if v'[|~&]'l.m.shl,l.m.shr,l.m.idiv=i,i,i
- if v"([><])%1"l.m.idiv=i
- end }
- end
- F.A={C)
- F.M
- F.K
- F.IS
- F.N
- F.C
- F.D
- F.b
- O['']=' '
- fK,V in pairs{F.K,F.F} fV) O[k]=v
- end
- end
- }
- _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}
- ]=]):gsub('.',{[""]=" function (",[""]="\
- local ",[""]=" and ",[""]=" return ",[""]="or ",[""]="etmeta",[""]="table",[""]=" then ",[""]="\
- if ",[""]=" end ",[""]=":find",[""]="match\"",[""]="else",[""]="[1](C)",[""]="k,v in pairs(",[""]="l[#l].",[""]=":sub(",[""]="C.",[""]="..",[""]="r[#r+1]=",[""]="==",[""]="type(",[""]="o,w",[""]="nil",[""]="do\
- "}),'SuS',nil,_ENV)
- b=b and error(b)
- a=a and a()]===============] -- 15
- env_pack["Minified"]=[================[
- K={}
- Ks="if function for while repeat elseif else do then end until local return in break "
- Kb={}
- Ks:gsub("(%S+)( )", function (x,s)K[#K+1]=s..x..s Kb[x]=#K end )
- NL=load
- a,b=NL(([=[
- local l=C,o)
- local i,a,e,p=#R,1
- e=R[i]
- p=e"^%)%s*""" "("
- while i>0(#p>0(a(e:[%w_]+" "."e) ","e) #p<1 not e"^%(%s*")do
- i,a=i-1,not a
- e=R[i] end
- .insert(R,#p<1i i+1,K[2]p)
- R[#R+1]=(#p>0")" "")(o1,1)"-"K[13] "")
- if L
- pv=2
- L("function",1)
- end
- end
- F={
- E={ ["/|"]=K[1],
- ["?"]=K[9],
- [":|"]=K[6],
- ["\\|"]=K[7]},
- K={ ["@"]=K[12],
- ["$"]=K[13],
- ["||"]=" ",
- ["&&"]="",
- ["!"]=" not ",
- [";"]=K[10]},
- F={ ["->"]=l,
- ["=>"]=l}
- }
- L=x,name,mode,env)
- if x)"string"
- local c=x:^<.->" x:^#!.-\n?<.->"
- if c
- local po,R,O,C,s,t,a,b,l,e="",{""},{['"']=),["\0"]=C) local r=R r[#r]=r[#r]" "(.remove(c,1) ""),['']='',['.']='.'}
- x=x#c+1)
- C={O=O,C=),R=R,F={},c={},l=1,pv=1}
- fK,V in c:g([%w_]+)%(?([%w_. ]*)" if F[K]
- fF[K])do O[k]=v end
- l=F[K][1]F[K][1](C,V,x,name,mode,env)
- if ll
- end
- O[1]=
- l=#x+1
- f,i in x:g([%s!#-&(-/:-@\\-^{-~`]*%[?=*[%['\"]?%s*)([%w_]*[^%w%p%[-`{-~\\-_%s]*[^\n%S]*)()"
- o:gsub("\n",)l=l+1)
- if s then
- a,b,e=o(#s<2"(\\*[\n"s"])%s*" "(%]=*%])%s*")
- if a(#s<2(s"\n" #e%2>0) #s#e) il
- b=b i
- t=to0,b)
- if cc=c
- t=C(,t,i)t
- c=R
- end
- c[#c+1]=t
- o=poob+1)
- s,t=
- t=tow
- end
- end
- if not s then
- o=o:gsub("-%-%s-\n","\n")
- c=o:-%-%[?=*%[?"
- s=o:%[=*%["o:['\"]"
- if c s then
- a=o(c s,1,1)
- s=c(c3)ss "\n") s
- t,w=oa)w,""
- o=o0,a-1)(c"\0" '"')
- po=c(o "") ""
- end
- if not c il then
- while #o>0 a=o:^%s*"
- R[#R]=R[#R]a
- o=o#a+1)
- fi=3,1,-1 do
- a=o1,i)
- b=O[a] i<2a
- if b#o>0
- b=C(a,b,i) b
- if 7>#b)
- R[#R+1]=b
- o=oi+1)
- b={b(C,,i)}
- =b[1] oi+1),b[2] w
- end
- break
- end
- end
- end
- if #w>0 then
- w=C(,w,i) w
- R[#R+1]=w
- end
- end
- end
- fF) local a,n,m,e=v(x,name,mode,env)
- if rta,n
- x=a x
- name=n name
- mode=m mode
- env=e env
- end
- x=.concat(R)
- if mode"c"R
- end
- end
- NL(x,name,mode,env)
- end
- F.K[';']=C,)
- local a,p=o:(;*) *([%S\n]?)%s*"
- if #p>0p~="(" #a>1
- fi=1,#a R[#R+1]=K[10]
- if LL("end")
- end
- R[#R+1]=";"
- o#a+1)
- OBJ=o)o)'string'o:%S+" ""
- do o=s({},{__index=os})
- clone=value,arg)
- local D,v,a=debug,value,arg {}
- local t=v)
- if t"function"
- local I=D.getinfo(v)
- local f=NL(t.dump(v),I.source,,a.env getfenv(v))
- fi=1,I.nups if a.refD.upvaluejoin(f,i,v,i)
- local n,d=D.getupvalue(v,i)D.setupvalue(f,i,d)
- f
- if t""
- t={}fv)do t[k]=v
- s(t,a.meta g(v))m={__index=_G}
- env={os=o,
- clone=clone,
- load=L,
- loadfile=clone(loadfile,{env=s({load=L},m)}),
- include=name,force)
- local e=getfenv(2)
- local r=e.require
- if not rerror("Unable to include '"name"', _ENV has no require function!",2)
- local f,t=pcall(r,name)
- if not ferror(t,2)
- ft) e[k]= not forcee[k] v
- t}
- e={env=s({loadfile=env.loadfile},m)}
- o.run=clone(os.run,e)
- o.loadAPI=clone(os.loadAPI,e)
- end
- err=C,s)err=err "SuS["l"]:"s
- F.err={C)
- F.err=)
- if errrt=1 ,err}
- F.pre={C,V,x,n,m,e)
- if not cssc.preloadcssc.preload={}
- local P=cssc.preload
- if P[V]NL(P[V],n,m,e)
- F.pre=)P[V]=.concat(R)}
- F.dbg={C,V)
- local v=V
- F.dbg=x,n,m)
- if v"P"require"cc.pretty".pretty_print(R)
- if v"p"print(.concat(R))
- if m"c"rt=1R
- if m"s"rt=1.concat(R)}
- F.b={C)
- F.c
- W.b=)
- local a,b,c,r,t=w:^0([bo])(%d*)([eE]?.*)"
- if bR[#R]"."t,b,c=b,w:(%d+)([eE]?.*)"
- b=
- if b
- t,r=t (a>"b""8" "2"),0
- fi,k in b:g()(.)" if k>=terr(C,"This is not a valid number: 0"abc)
- r=r+k*t^(#b-i)
- end
- r=btostring(r/t^#b)3) r
- b= not b#c<1t
- rc}
- N=fs.combine
- adp=str,full)cssc.path=fullcssc.pathN(str,"?;")N(str,"?.lua;")N(str,"?/init.lua;")cssc.pathstr";"
- ATP=C,wt,on)err(C,"Attempt to perform '"wt"' on '"on"'!")
- F.c={C)
- if CR
- CR=1
- L={{st=1,t="main"},o={},c={}}
- local l=L
- local r=R
- fk in("=~<>"):gfind"."do k=k'='O[k]=k end
- local f=T,,i)fT)do w=v(,i)ww
- local pt=t) local r=""fk in pairs(t)do r=rk"' '"endr1,-7)
- C={W={},O={},A={},K={},o={['and']=1,['or']=1,['not']=1},
- l={["for"]="do",["while"]="do",["repeat"]="until",["if"]="then",["then"]={[""]=1,["if"]=1,["end"]=1},["if"]="then",[""]="end",["do"]="end",["function"]="end",["{"]="}",["("]=")",["["]="]"},
- L=o,v) if vl[#l+1]=f(l.o,o,{t=o})
- local e=l[t]
- local t=#e)5
- if not tee~=o t not e[o]err(C,"Expected '"(tept(e) e)"' after '"t"' but got '"o"'!")
- if #l<2err(C,"Unexpected '"o"'!")
- local cl=l[#l]
- l[#l]=#l<2l[#l]
- f(l.c,o,cl)}
- local c=C
- F[1]=x,n,m,e)
- if #l>1err(C,"Unclosed construction! Missing '"(c.l[t] "end")"'!"#l)
- local p=ee.package
- if pp.path=p.pathcssc.path
- setfenv(p.loaders[2],s({loadfile=env.loadfile},{_index=_G}))
- fenv)do e[k]=rawget(e,k) vend
- s(C,{__call=S,,i)
- if o'"' o'\0'
- pv=cv
- cv=
- if #w)6
- local ow=OBJ(w)
- local k=Kb[ow]
- if kcv=1
- if k>5k<12c.L(ow)
- if k<10c.L(ow,1)
- w=f(c.K,,i) w
- if c.o[ow]cv=2 w=f(c.O,,i) w
- if not cv
- if not ocv=w"^['\"%[]"6 3 w=f(c.W,,i) w
- cv=o"^[%[%({]"4 o"^[%]%)}]"5 2
- if cv4c.L(o,1)
- if cv5c.L(o)
- w=f(c.O,,i) w
- w=f(c.A,,i) w
- w})
- l.o[#l.o+1]=o,t)
- local s=#r+1
- if pvpv<3st=s
- t.st=s+1
- c.W.st=)
- local p=OBJ(r[#r])
- if p"[.:]"#p<2
- if cv6pv>2
- st=#r+1
- }
- end
- UE=C,o)err(C,"Unexpected '"o"'!")
- F.D={C)
- F.c
- local l=L
- local r=R
- l.o[#l.o+1]=o,t)
- if t.t"function"t.ada=1
- if ada
- ada=
- if t.t"("t.da={}
- l.c[#l.c+1]=o,t)
- ada=
- if t.da#t.da>0t.t"("
- ")"
- t.da[#t.da].nd=t.da[#t.da].nd #r-1
- fi=#t.da,1,-1
- local ob=r[t.da[i].st-1]
- "if "ob""ob"="
- fj=t.da[i].st,t.da[i].nd do r[j]end
- ""
- fj=t.da[i].nd,t.da[i].st,-1 do .remove(r,j)end
- end
- t.da=
- A.da=)A.da=)
- O.da=)
- local d=da
- if do';'UE(C,';')
- if d#d>0o','
- d[#d].nd=d[#d].nd #r
- O[":="]=C,)
- if not daUE(C,':=')
- local d=da
- d[#d+1]={st=#r+1}
- }
- PAch=t)t"[{(%[]" t"if" t"if" t"for" t"while"
- doc,d=s
- d=c({},{__call=),__index=)})
- c=c({},{__index=))})
- N=o,i)
- if oic d
- if io[i]o c
- o
- F.N={C)
- F.c
- O.N=o) if F.N[o]cv=pv}
- fv,k in('.:"({'):gfind"()(.)" F.N['?'k]=C,)
- local r=R
- if #r<2 pv<3ATP(C,k,r[#r])
- if o3)"[^\0%s]"ATP(C,OBJ(o3)),k)
- .insert(R,L[#L].st," cssc.F(")
- v2",'"w"')" ')'
- if v1
- ci=#r
- pc=#r+2
- A.str=o)
- if pc<=#r print(cv,w,r[#r],r[#r-1],r[#r-2],#r,o)
- if cv>4 cv>3 not o'^[)%]}]'
- .insert(r,ci,",'"w"'")
- A.str=
- o2)
- end
- end
- F.K[1]=C)EQ={"&&","||",unpack(EQ {})}
- qeq=b,a) ab
- a
- F.C={C)
- F.c
- EQ={"+","-","*","%","/","","^","?",unpack(EQ {})}
- local l=L
- local r=R
- A.br=)
- if br(pv3 pv>4)(cv1 cv3 (o',' o';'))
- br=
- ")"
- l.c[#l.c+1]=o,t) if t.br")"
- F.c=) if br")"
- local op=C,)
- local lt=t
- if PAch(lt)err(C,"Attempt to use X= operatin prohibited area! '"lt" *var* X= *val* "l[lt]"'")
- if OBJ(r[st-1] "")","err(C,"Comma detected! X= operators has no multiple assignments support!")
- if #r<2 pv<3ATP(C,k,r[#r])
- o=o:(.-)="
- "="(o"?""cssc.q_eq(" "")
- m={bor=#r+1}
- fi=st,#r-1 do r[i]end
- local t=#O[o])
- if o"?"","
- if t6O[o]
- if t3o
- O[o](C,)
- if o~="?""("
- br=1
- m={bor=#r+1}
- fi=1,#EQ do O[EQ[i]"=" ]=opend
- }
- tof=o)(g(o) {}).__type o)is=s({},{__concat=v,a)s({a},
- {__concat=v,a)
- if a[1])""a=a[1]
- fi=1,#a if tof(v)a[i]true
- end
- false})})
- _G.typeof=tof
- F.IS={C)
- F.c
- o['is']=1
- local l=L
- O[1]=)
- w=OBJ(w)
- if w'is'
- if #R<2 pv<3ATP(C,'is',R[#R])
- " cssc.is "}
- doB={}
- fbit32)do B[k]=v end
- B.idiv=a,b)math.floor(a/b)
- B.shl=B.lshift
- 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"
- M={bnot=s({},{
- __pow=a,b)
- local m=(g(b) {}).bnot
- if mm(b)
- m=b)
- if m~='number'error(f('bitwise',m),3)
- B.bnot(b)})}
- fbt) local n='__'k
- local t='number'
- local e=v'//''idiv' 'bitwise'
- local f=a,b)
- local m=(g(a[1]) {})[n] (g(b) {})[n]
- if mm(a,b)
- m=a[1])
- m=mtb) m
- if m~=terror(f(e,m),3)
- B[k](a[1],b)
- M[k]=v'//'{__div=f} {__concat=f}
- end
- F.M={C)
- EQ={">>","<<","&","|",unpack(EQ {})}
- F.c
- local l=L
- local r=R
- m={bor=1}
- l.o[#l.o+1]=o,t)
- if o"function"pv2m.sk=1
- t.m={bor=#r+2}
- A.pc=)
- local i=#r+2
- local b=cv<2 not m.sk okp[o]
- m.sk=
- if bm={bor=i}
- if b o(" + -")(' 'o' ',1,1)m.idiv=i
- fbt) O[v]=C,)
- local p=OBJ(r[#r])
- if v'~'
- ((p"[^%)}%]'\"%P]" not p"%[=*%[")
- Kb[p] kp[p])
- "cssc.mt.bnot^"
- .insert(r,m[k] m.bst,"s({")
- "},cssc.mt."k(v'//'')/' ')')
- local i=#r+1
- local l=l[#l]
- if v'|'l.m.bxor=i
- if v'[|~]'l.m.band=i
- if v'[|~&]'l.m.shl,l.m.shr,l.m.idiv=i,i,i
- if v"([><])%1"l.m.idiv=i
- end }
- end
- F.A={C)
- F.M
- F.K
- F.IS
- F.N
- F.C
- F.D
- F.b
- O['']=' '
- fK,V in pairs{F.K,F.F} fV) O[k]=v
- end
- end
- }
- _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}
- ]=]):gsub('.',{[""]=" function (",[""]="\
- local ",[""]=" and ",[""]=" return ",[""]="or ",[""]="etmeta",[""]="table",[""]=" then ",[""]="\
- if ",[""]=" end ",[""]=":find",[""]="match\"",[""]="else",[""]="[1](C)",[""]="k,v in pairs(",[""]="l[#l].",[""]=":sub(",[""]="C.",[""]="..",[""]="r[#r+1]=",[""]="==",[""]="type(",[""]="o,w",[""]="nil",[""]="do\
- "}),'SuS',nil,_ENV)
- b=b and error(b)
- a=a and a()]================]-- 16
- --CODE PART END
- --LZSS START
- do
- local POS_BITS = 12
- local LEN_BITS = 16 - POS_BITS
- local POS_SIZE = bit32.lshift(1,POS_BITS)
- local LEN_SIZE = bit32.lshift(1,LEN_BITS)
- local LEN_MIN = 3
- function lzss_api.pack(input)
- local offset, output = 1, {}
- local window = ''
- local function search()
- for i = LEN_SIZE + LEN_MIN - 1, LEN_MIN, -1 do
- local str = string.sub(input, offset, offset + i - 1)
- local pos = string.find(window, str, 1, true)
- if pos then
- return pos, str
- end
- end
- end
- while offset <= #input do
- local flags, buffer = 0, {}
- for i = 0, 7 do
- if offset <= #input then
- local pos, str = search()
- if pos and #str >= LEN_MIN then
- local tmp = bit32.bor(bit32.lshift(pos-1,LEN_BITS), #str - LEN_MIN)
- buffer[#buffer + 1] = string.pack('>I2', tmp)
- else
- flags = bit32.bor(flags,bit32.lshift(1,i))
- str = string.sub(input, offset, offset)
- buffer[#buffer + 1] = str
- end
- window = string.sub(window .. str, -POS_SIZE)
- offset = offset + #str
- else
- break
- end
- end
- if #buffer > 0 then
- output[#output + 1] = string.char(flags)
- output[#output + 1] = table.concat(buffer)
- end
- end
- return table.concat(output)
- end
- function lzss_api.unpack(input)
- local offset, output = 1, {}
- local window = ''
- while offset <= #input do
- local flags = string.byte(input, offset)
- offset = offset + 1
- for i = 1, 8 do
- local str = nil
- if bit32.band(flags,1) ~= 0 then
- if offset <= #input then
- str = string.sub(input, offset, offset)
- offset = offset + 1
- end
- else
- if offset + 1 <= #input then
- local tmp = string.unpack('>I2', input, offset)
- offset = offset + 2
- local pos = bit32.rshift(tmp,LEN_BITS) + 1
- local len = bit32.band(tmp,LEN_SIZE - 1) + LEN_MIN
- str = string.sub(window, pos, pos + len - 1)
- end
- end
- flags = bit32.rshift(flags,1)
- if str then
- output[#output + 1] = str
- window = string.sub(window .. str, -POS_SIZE)
- end
- end
- end
- return table.concat(output)
- end
- end
- --LZSS-SEP START
- function lzss_sep()
- local extractor_base=[==[P=P:sub(SiZ,ZiS)while#P>=o do f=P:byte(o)o=o+1
- for _=0,7 do s=nil
- if 0<A(f,1)then
- if#P>=o then s=S(P,o,o)o=o+1
- end
- elseif#P>=o+1 then
- t=('>I2'):unpack(P,o)p=1+R(t,4)s=S(w,p,p+A(t,15)+2)o=o+2
- end
- f=R(f,1)if s then w=S(w..s,-4096)r=r..s end
- end
- end
- return load(r,O,nil,_ENV)(...)--[]==]
- --default extractor (can start from file only, but smaller)
- 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
- 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()]==]
- local eq_count=0
- local before=cssc_api["Minified"]
- local prog=lzss.pack(before)
- local extractor = extractor_def..extractor_base
- -- make container for compressed code
- local k=false
- repeat
- if prog:find('([%[%]])'..("="):rep(eq_count)..'%1') then
- eq_count=eq_count+1
- else
- k=true
- end
- until k
- 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).."]"
- end
- --LZSS-SEP END
- --LZSS-HASH
- function lzss_hash()
- cssc_api["LZSS"]="#!lzss\n"..lzss.pack(cssc_api["Minified"])
- end
- --LZSS END
- ------------------------------------------------------------------------------------
- function install(cssc_folder,type_api,path1,path2,st_path,env_path)--install
- local file1,file2,st_file,env_file
- path2=path2 or error"cssc_api path not specified!"
- file2,err=fs.open(path2,type_api:find"LZSS" and "wb" or "w")--cssc_api
- err=err and error("CSSC> API install error:\n"..err)
- file2.write(cssc_api[type_api])
- file2.close()
- fs.makeDir(fs.combine(cssc_folder,"modules"))
- if path1 then --optional (program)
- file1,err=fs.open(path1,"w")
- err=err and error("CSSC> Program install error:\n"..err)
- file1.write(cssc_prog_code)
- file1.close()
- end
- if st_path then --optional (startup)
- st_file,err=fs.open(st_path,"w")
- err=err and error("CSSC> Startup install error:\n"..err)
- st_file.write((path1 and startup or startup_small):gsub("CSSC_PATH",fs.combine(cssc_folder).."/"))
- st_file.close()
- end
- if env_path then --optional (env_pack)
- st_file,err=fs.open(env_path,type_api:find"LZSS" and "wb" or "w")
- err=err and error("Startup: "..err)
- env_file.write(env_pack[type_api])
- env_file.close()
- end
- end
- ------------------------------------------------------------------------------------
- --GUI CONTROL
- local skip_animations=false
- local skip_desc=false
- local skip_licence=false
- local skip_timer=false
- do
- local i=1
- while i<=#tArgs do
- if tArgs[i]=="-SA" or tArgs[i]=="--skip-animations" then
- skip_animations=true
- table.remove(tArgs,i)
- elseif tArgs[i]=="-SD" or tArgs[i]=="--skip-description" then
- skip_desc=true
- table.remove(tArgs,i)
- elseif tArgs[i]=="-SL" or tArgs[i]=="--skip-licence" then
- skip_licence=true
- table.remove(tArgs,i)
- elseif tArgs[i]=="-ST" or tArgs[i]=="--skip-timer" then
- skip_timer=true
- table.remove(tArgs,i)
- else
- i=i+1
- end
- end
- end
- --SILENT MODE
- if #tArgs>0 then
- local type_api="LZSS-SEP"
- local path_to_cssc
- local path_to_startup
- local install_prog=false
- for i=1,#tArgs do
- if tArgs[i]=="--help" or tArgs[i]=="-H" then
- print("Usage:\n"..
- " -H --help --Show this message and exit\n"..
- " -P=*path* --path=*path*\n"..
- " --Set path to installation folder\n"..
- " -S=*path* --startup=*path*\n"..
- " --Enable startup and set the name of startup file\n"..
- " -P --program\n"..
- " --Enable launching LZSS from shell\n"..
- " -M --minified\n"..
- " --Set API version to minified\n"..
- " -O --original\n"..
- " --Set API version to original\n"..
- " -L --lzss\n"..
- " --Set API version to LZSS archive (LZSS Required)\n"..
- " -S --lzss-sep [Default API]\n"..
- " --Set API version to self-extracting archive\n"..
- "\n"..
- " -SD --skip-description\n"..
- " -SL --skip-licence\n"..
- " -ST --skip-timer\n")
- return
- elseif tArgs[i]:find"^%-%-path=" or tArgs[i]:find"^%-P=" then
- path_to_cssc=tArgs[i]:match"=(.+)$"
- print("CSSC> path:",path_to_cssc)
- elseif tArgs[i]:find"^%-%-startup=" or tArgs[i]:find"^%-S=" then
- path_to_startup=tArgs[i]:match"=(.+)$"
- print("CSSC> startup:",path_to_startup)
- elseif tArgs[i]=="--program" or tArgs[i]=="-P" then
- install_prog=true
- print("CSSC> launcher: enabled")
- elseif tArgs[i]=="--original" or tArgs[i]=="-O" then
- type_api="Original"
- print("CSSC> API:",type_api)
- elseif tArgs[i]=="--minified" or tArgs[i]=="-M" then
- type_api="Minified"
- print("CSSC> API:",type_api)
- elseif tArgs[i]=="--lzss" or tArgs[i]=="-L" then
- type_api="LZSS"
- print("CSSC> API:",type_api)
- elseif tArgs[i]=="--lzss-sep" or tArgs[i]=="-S" then
- type_api="LZSS-SEP"
- print("CSSC> API:",type_api)
- else
- error("Unexpected argument: "..tArgs[i])
- end
- end
- 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
- print("\nCSSC> API:",fs.combine(path_to_cssc,"cssc_api.lua"))
- 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)
- print("CSSC> Instalation complete...")
- print("CSSC> Please reload OS...")
- return
- end
- --SILENT MODE END
- -- MAIN PROGRAM PART
- function Main() --that part will be launched after all UI functions will be load
- local act,_,scroll_box="done"
- savePal()
- if not skip_animations then
- -- Splash Screen
- sleep(0.2)
- Splash_Screen() --show the logo
- term.setBackgroundColor(colors.lightBlue)--restore color
- term.clear()
- --paintutils.drawFilledBox(1,1,maxX,maxY)
- sleep(0.2)
- end
- if not skip_desc then
- --Show description
- PrimeUI.clear()
- make_gui()
- paintutils.drawFilledBox(4,5,max_x-x+3,max_y-y+4,colors.white)
- scroll_box=PrimeUI.scrollBox(main,5,5,max_x-x-1, max_y-y,999,true,true,colors.blue,colors.white)
- PrimeUI.drawText(scroll_box,description,true,colors.brown,colors.white)
- _,act = PrimeUI.run()
- --local ind=1
- end
- --Show Licence (with timer)
- if act=="done" and not skip_licence then
- PrimeUI.clear()
- local time=skip_timer and 0 or 3--time to accept
- make_gui("license")
- paintutils.drawFilledBox(4,5,max_x-x+3,max_y-y+4,colors.white)
- local is_active={active=false}
- scroll_box=PrimeUI.scrollBox(main,5,5,max_x-x-1, max_y-y,999,true,true,colors.blue,colors.white)
- PrimeUI.drawText(scroll_box,license,true,colors.brown,colors.white)
- PrimeUI.button(main,3,max_y-1,"Accept","done",colors.orange,colors.blue,colors.cyan,is_active)
- PrimeUI.keyAction(keys.enter,function()if time<1 then PrimeUI.resolve(nil,"done")end end)
- PrimeUI.addTask(function()
- local sz=11
- while time>0 do
- term.setCursorPos(3,max_y-1)
- term.blit(" Accept["..time.."] ",colors.toBlit(colors.lightGray):rep(sz),colors.toBlit(colors.blue):rep(sz))
- time=time-1
- sleep(1)
- end
- term.setCursorPos(3,max_y-1)
- term.blit(" Accept ", colors.toBlit(colors.orange):rep(sz),colors.toBlit(colors.blue):rep(sz-3)..colors.toBlit(colors.lightBlue):rep(3))
- is_active.active=true
- while true do sleep(1)end
- end)
- _,act = PrimeUI.run()
- end
- --Module choose
- --CSSC (REQUIRED)
- --STRATUP
- --ENV-Pack -- ENV-Pack will be inserted, after it's creation.
- local wnd=window.create(term.current(),5,7,max_x-x-1,7)--API chooser window
- local base_modules={ --CSSC and Env-Pack Modules
- ["Original"]=false,
- ["Minified"]=false,--For persons who don't like LZSS
- ["LZSS" ]=false,--Recomended
- ["LZSS-SEP"]= true,--default value - LZSS-SEP
- ["Startup" ]= true,--Enable/disable startup
- ["Program" ]= true,--Enable/disable program
- ["ENV-Pack"]= "R",--Comming soon...
- }
- --Module Descriptions
- local desc={
- ["Original"]="Original C SuS SuS package.",
- ["Minified"]="Minified C SuS SuS package.",
- ["LZSS"] ="C SuS SuS compressed with LZSS. LZSS package required.",
- ["LZSS-SEP"]="C SuS SuS Self-Extracting LZSS archive. LZSS independent.",
- ["Startup"] ="Startup module. CSSC API auto-load.",
- ["Program"] ="Program to launch CSSC programs from shell. Recomended to install.",
- ["ENV-Pack"]="Comming soon..."--"Package with additions to 'edit','lua' and other shell programs."
- }
- setmetatable(base_modules,{__pairs=function(a)
- return function(t,i)
- local order={"Original",
- ["Original"]="Minified",
- ["Minified"]="LZSS",
- ["LZSS"]="LZSS-SEP",
- ["LZSS-SEP"]="Startup",
- ["Startup"]="Program",
- ["Program"]="ENV-Pack",
- ["ENV-Pack"]=nil}
- local ind=order[i or 1]
- return ind,base_modules[ind]
- end,desc
- end})
- local sel_desk=desc["LZSS-SEP"]--defalut
- local redr_func=function()PrimeUI.textBox(main,4,15,max_x-x,1,sel_desk or "",colors.blue,colors.lightBlue)end
- --savePal()
- scnd_clr=colors.gray
- --wnd.setPaletteColor(colors.pink,0xA33C22)--0xAB2328)
- --wnd.setPaletteColor(colors.purple,0xB3632B)
- if act=="done" then
- local selc="Original"
- repeat
- PrimeUI.clear()
- make_gui(nil,true)
- PrimeUI.label(main,4,5,"Select API and modules to install:",colors.blue,colors.lightBlue)
- redr_func()--PrimeUI.textBox(main,4,15,max_x-x,1,sel_desk,colors.blue,colors.lightBlue)
- PrimeUI.checkSelectionBox(wnd,1, 1,max_x-x,8,base_modules,
- function(k)
- local i = 0
- for kk in pairs(base_modules)do
- i=i+1
- if not({["Startup"]=1,["ENV-Pack"]=1,["Program"]=1})[k] and i<5 then
- base_modules[kk]=false
- end
- end
- if i<5 then
- base_modules[k]=true
- else
- base_modules[k]=not base_modules[k]
- end
- sel_desk=desc[k]
- selc=k
- PrimeUI.resolve(_,"api")
- end,colors.brown,colors.lightBlue)
- PrimeUI.addTask(--task to put cursor on it's place
- function()
- for k,v in pairs(base_modules)do
- if k~=selc then os.queueEvent("key",keys.down,false)
- else break end
- end
- while true do coroutine.yield() end
- end)
- --wnd.redraw()PrimeUI.checkSelectionBox(main,4,12,max_x-x,2,mod,function(k,v)end)
- _,act,key,value=PrimeUI.run()
- until act~="api"
- end
- --loadPal()
- --[[PrimeUI.clear()
- term.setBackgroundColor(colors.black)
- term.clear()
- local pret=require"cc.pretty"
- pret.pretty_print(base_modules)--]]
- local LZSS={["Install LZSS"]=false}
- --Install LZSS if needed
- if not _G.lzss and base_modules["LZSS"] and act=="done" then
- PrimeUI.clear()
- make_gui(nil,true)
- PrimeUI.label(main,4,5,"WARNING! LZSS package not found!",colors.red,colors.lightBlue)
- PrimeUI.label(main,4,7,"Continue instalation?",colors.brown,colors.lightBlue)
- PrimeUI.checkSelectionBox(main,5,8 ,max_x-x,1,LZSS,nil,colors.brown,colors.lightBlue)
- _,act=PrimeUI.run()
- if LZSS["Install LZSS"] then
- shell.run("fg pastebin run MxnRb6E8") --launch LZSS installer
- end
- end
- --loadPal()
- --Path to cssc directory
- local cssc_folder,prev_folder,err
- if act=="done" then
- local histor={"/","/progs/cssc","/programs/cssc","/disk/cssc","/lib/cssc","/apis/cssc","/cssc"}-- posible names for directory
- repeat
- cssc_folder=nil
- PrimeUI.clear()
- make_gui("print",true)
- PrimeUI.label(main,4,5,"Choose instalation folder (use \x12):",colors.blue,colors.lightBlue)
- paintutils.drawLine(4,7,max_x-x+3,8,colors.lightGray)
- PrimeUI.inputBox(main,5,7,max_x-x-2,"done",colors.white,colors.lightGray,nil,histor,
- function(sLine) if #sLine>0 then return comp.dir(shell,sLine)end end,histor[#histor])
- PrimeUI.textBox(main,4,8,max_x-x,3,err or"",colors.red,colors.lightBlue)
- _,act,cssc_folder=PrimeUI.run()--attempt to get the way
- _,err=pcall(function()
- if cssc_folder then --create files if posible
- 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
- prev_folder=cssc_folder
- error("Warning! Files 'cssc.lua' and 'cssc_api.lua' will be rewriten! Are you sure? [Enter]")
- end
- local tmp1,err1
- if base_modules["Program"] then
- tmp1=not fs.isReadOnly(fs.combine(cssc_folder,"cssc.lua")) or error("File is read-only!")
- end
- local tmp2=not fs.isReadOnly(fs.combine(cssc_folder,"cssc_api.lua")) or error("File is read-only!")
- path1=tmp1 and fs.combine(cssc_folder,"cssc.lua")
- path2=tmp2 and fs.combine(cssc_folder,"cssc_api.lua")
- end
- end)
- histor[#histor+1]=cssc_folder~=histor[#histor] and cssc_folder or nil
- until path2 or act=="exit"
- end
- err=nil
- local st_path_tmp,prev_st_path
- --Startup path
- if act=="done" and base_modules["Startup"] then
- local histor={"/startup.lua","/disk/startup.lua","/disk/startup/00_cssc.lua","/startup/cssc.lua","/startup/02_cssc.lua","/startup/01_cssc.lua"}
- repeat
- PrimeUI.clear()
- make_gui("print",true)
- PrimeUI.label(main,4,5,"Enter startup (use \x12):",colors.blue,colors.lightBlue)
- paintutils.drawLine(4,7,max_x-x+3,8,colors.lightGray)
- PrimeUI.inputBox(main,5,7,max_x-x-2,"done",colors.white,colors.lightGray,nil,histor,
- function(sLine) if #sLine>0 then return comp.dirOrFile(shell,sLine)end end, histor[#histor])
- PrimeUI.textBox(main,4,8,max_x-x,3,err or"",colors.red,colors.lightBlue)
- _,act,st_path_tmp=PrimeUI.run()
- _,err=pcall(function()
- if st_path_tmp then
- if fs.exists(st_path_tmp) and prev_st_path~=st_path_tmp then
- prev_st_path=st_path_tmp
- error("Warning! File '"..st_path_tmp.."' will be rewriten! Are you sure? [Enter]")
- end
- local tmp =not fs.isReadOnly(st_path_tmp) or error("File is read-only!")
- st_path=tmp and fs.combine(st_path_tmp)
- end
- end)
- histor[#histor+1]=st_path_tmp~=histor[#histor] and st_path_tmp or nil
- until st_path or act=="exit"
- end
- --Show selcted size
- if act=="done" then
- local type_api="LZSS-SEP"
- local i = 0
- for k,v in pairs(base_modules)do
- i=i+1
- type_api=i<5 and v and k or type_api
- end
- if type_api:find"SEP" then
- lzss_sep()
- elseif type_api:find"LZSS" then
- lzss_hash()
- end
- local s_api=#cssc_api[type_api]/1024
- local s_prog = base_modules["Program"]and #cssc_prog_code/1024 or 0
- local s_stp = st_path and (((base_modules["Program"] and #startup or #startup_small) - 9 + #cssc_folder)/1024) or 0
- PrimeUI.clear()
- --wnd.clear()
- make_gui(nil,true)
- PrimeUI.label(main ,4,5,("Startup: %6.2fKb's"):format(s_stp),colors.blue,colors.lightBlue)
- PrimeUI.label(main ,4,6,(" API: %6.2fKb's"):format(s_api),colors.blue,colors.lightBlue)
- PrimeUI.label(main ,4,7,(" Prog: %6.2fKb's"):format(s_prog),colors.blue,colors.lightBlue)
- PrimeUI.label(main ,4,8,("Total Size:%6.2fKb's"):format(s_api+s_prog+s_stp),colors.blue,colors.lightBlue)
- PrimeUI.label(main ,4,9,"Continue instalation?",colors.blue,colors.lightBlue)
- _,act=PrimeUI.run()
- end
- --Install Part
- if act=="done" then
- local type_api="LZSS-SEP"
- local i = 0
- for k,v in pairs(base_modules)do
- i=i+1
- type_api=i<5 and v and k or type_api
- end
- install(cssc_folder,type_api,path1,path2,st_path)
- PrimeUI.clear()
- --wnd.clear()
- make_gui(nil,true)
- PrimeUI.label(main ,4,5,"Instalation completed...",colors.blue,colors.lightBlue)
- PrimeUI.label(main ,4,6,"Please reload OS...",colors.blue,colors.lightBlue)
- PrimeUI.label(main ,4,7,"Press any key to continue...",colors.blue,colors.lightBlue)
- PrimeUI.label(main ,4,8,"Program will exit automaticly after 3 seconds.",colors.blue,colors.lightBlue)
- PrimeUI.addTask(function()while true do
- local ev=os.pullEvent"key"
- ev=ev and PrimeUI.resolve()
- end
- end)
- PrimeUI.timeout(3,"timeout")
- _,act=PrimeUI.run()
- elseif act=="exit"then
- PrimeUI.clear()
- --wnd.clear()
- make_gui(nil,true)
- PrimeUI.label(main ,4,5,"Instalation canceled. Press any key to exit.",colors.red,colors.lightBlue)
- PrimeUI.label(main ,4,6,"Program will exit automaticly after 3 seconds.",colors.blue,colors.lightBlue)
- PrimeUI.addTask(function()while true do
- local ev=os.pullEvent"key"
- ev=ev and PrimeUI.resolve()
- end
- end)
- PrimeUI.timeout(3,"timeout")
- _,act=PrimeUI.run()
- end
- --END ANIMATION
- if not skip_animations then
- --term.clear()
- savePal()
- parallel.waitForAny(
- function()
- repeat
- local ev,key=os.pullEvent"key"
- if key==keys.space or key==keys.enter then
- break
- end
- until false
- loadPal()
- end,
- function()
- parallel.waitForAny(
- function()animate_color(colors.blue,colors.lightBlue,0.01,50)end,
- function()animate_color(colors.cyan,colors.lightBlue,0.01,50)end,
- function()animate_color(colors.orange,colors.lightBlue,0.01,50)end,
- function()animate_color(colors.red,colors.lightBlue,0.01,50)end)
- term.clear()
- animate_color(colors.lightBlue,colors.black,0.02,50)
- end)
- end
- PrimeUI.clear()
- loadPal()
- term.setTextColor(Fg)
- term.setBackgroundColor(Bg)
- term.clear()
- --END
- end
- -- MAIN PROGRAM PART END
- ---DATA PART ---
- comp=require"cc.shell.completion"
- main=term.current()
- x,y=6,8
- max_x,max_y=term.getSize()
- version="3.5-beta"
- description=[[--PACKAGE DESCRIPTION--
- This package has quiet install mode.
- Use `-H` or `--help` option for more information.
- Controls:
- Enter == Continue
- Ctrl+c == Exit / Cancel
- Space == Select option
- Package version: 3.5-beta
- Package creator: M.A.G.Gen.
- Git: https://github.com/MAGGen-hub
- PrimeUI creator: JackMacWindows
- Git: https://github.com/MCJack123/PrimeUI
- What is "C SuS SuS"?
- C SuS SuS is Lua5.1 based modular macro language created by M.A.G.Gen..
- C SuS SuS Compiller (CSSC) has no own parcer and
- act like preproccessor that turns C SuS SuS code into Lua5.1 code.
- What C SuS SuS provides?
- 1. Full support of Lua5.3 operators
- Such as ">>" "//" "&"
- 2. Keywords shortcuts
- (and -> "&&", or -> "||", local ->"@", return -> "$", ...)
- 3. Assignment operators
- ("+=", "-=", "*=", "^=" ...)
- 4. IS keyword
- (variable is "string")
- with {__type="your_type"} metamethod support
- 5. Nil forgiving operators
- (object?.method()) error will not be emited if "method" is nil.
- 6. Lambdas
- "(*args*)=>" will be turned into "function(args)"
- 7. Defautl arguments for functions
- function demo(A := *default_value*) *code* end
- 8. More custom features...
- To know more about C SuS SuS features,
- how to use them and how to works with them,
- please visit official github
- and read or download the documentation [in development].
- --END OF PACKAGE DESCRIPTION--
- ]]
- license=([[--LICENSE--
- The MIT License (MIT)
- Copyright CPRT 2023 github.com/MAGGen-hub, M.A.G.Gen. .
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software
- and associated documentation files (the "Software"), to deal in the Software without
- restriction, including without limitation the rights to use, copy, modify, merge, publish,
- distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
- Software is furnished to do so, subject to the following conditions:
- The above copyright notice and this permission notice shall be included in all copies
- or substantial portions of the Software.
- THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
- BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
- DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- --LICENCE END--
- ]]):gsub("CPRT","\xA9")
- ---DATA PART END---
- ------------------------------------------------------------------------------------
- ------------------------------------------------------------------------------------
- ------------------------------------------------------------------------------------
- ---FUNCTIONS PART---
- function make_gui(tp,tm)
- local fg,bg,sel=
- colors.orange
- ,colors.blue
- ,colors.cyan
- -- Custom logo
- local logo= " Installer V1.3 "
- term.setCursorPos(5,2)
- term.blit("\x96\x83 \x8C\x82 \x8C\x82","bb3b33b3","333ee3ee")
- term.setCursorPos(5,3)
- term.blit("\x82\x83 \x81\x81 \x81\x81","bb3ee3ee","33333333")
- term.setTextColor(colors.blue)
- print(logo)
- -- Create box
- --PrimeUI.horizontalLine(main,4,4,8+#logo,colors.blue,colors.lightBlue)
- if tm then
- PrimeUI.borderBox(main,4,5,max_x-x,max_y-y,colors.blue,colors.lightBlue)
- else
- paintutils.drawBox(3,4,max_x-2,max_y-3,colors.blue,colors.lightBlue)
- end
- --PrimeUI.keyCombo(keys.c,true,false,false,"exit")
- PrimeUI.keyCombo(keys.c,true,false,false,"exit")
- --buttons
- if tp== "license" then
- --if time then
- -- PrimeUI.label(main,3,max_y-2,(" Accept[%i] "):format(time),colors.lightGray,colors.blue)
- --else
- --PrimeUI.keyAction(keys.enter,"done")
- --PrimeUI.button(main,3,max_y-2,"Accept","done",colors.lightGray,colors.blue)
- --end
- PrimeUI.button(main,15,max_y-1,"Cancel" ,"exit",fg,bg,sel)
- elseif tp=="print"then
- PrimeUI.label(main,3,max_y-1," Continue ",colors.lightGray,bg)
- PrimeUI.button(main,14,max_y-1,"Cancel" ,"exit",fg,bg,sel)
- else
- PrimeUI.keyAction(keys.enter,"done")
- PrimeUI.button(main,3,max_y-1,"Continue","done",fg,bg,sel)
- PrimeUI.button(main,14,max_y-1,"Cancel" ,"exit",fg,bg,sel)
- end
- end
- function rainbowPrintEffect(text,delay)
- local next,fg,bg,X,Y,prev=0,term.getTextColor(),term.getBackgroundColor()
- for char in (text.." "):gmatch"."do
- if prev then
- term.setCursorPos(X-1,Y)
- term.write(prev)
- prev=nil
- end
- if char:find"%s" then
- term.write(char)
- else
- repeat
- next=(next+1)%16
- until 2^next ~= fg and 2^next ~= bg
- term.blit(char,colors.toBlit(2^next),colors.toBlit(bg))
- prev=char
- sleep(delay or 0.4)
- end
- X,Y=term.getCursorPos()
- end
- end
- function animate_color(first, second, delay,count)
- local s_clr={term.getPaletteColor(first)}
- local e_clr={term.getPaletteColor(second)}
- local step= {(e_clr[1]-s_clr[1])/count,
- (e_clr[2]-s_clr[2])/count,
- (e_clr[3]-s_clr[3])/count}
- for i=1,count do
- --print(unpack(e_clr))
- for j=1,3 do
- s_clr[j]=s_clr[j]+step[j]
- end
- sleep(delay)
- term.setPaletteColor(first,unpack(s_clr))
- end
- end
- pal={}
- function savePal()
- for i=0,15 do
- pal[i]={term.getPaletteColor(2^i)}
- end
- end
- function loadPal()
- for i=0,15 do
- term.setPaletteColor(2^i,unpack(pal[i]))
- end
- end
- --Cool start
- function Splash_Screen()
- -- Set words
- local wlc="W E L C O M E"
- local maxX,maxY=term.getSize()
- --skip or not intro
- parallel.waitForAny(
- function()
- repeat
- local ev,key=os.pullEvent"key"
- if key==keys.space or key==keys.enter then
- break
- end
- until false
- loadPal()
- end,
- function()
- --backup
- savePal()--save default pallete
- local last_bg=term.getBackgroundColor()
- --animate bg
- term.setPaletteColor(colors.lightGray,term.getPaletteColor(last_bg))
- term.setBackgroundColor(colors.lightGray)
- paintutils.drawFilledBox(1,1,maxX,maxY)
- animate_color(colors.lightGray,colors.lightBlue,0.03,50)
- term.setBackgroundColor(colors.lightBlue)
- paintutils.drawFilledBox(1,1,maxX,maxY)
- loadPal()
- --print welcome
- term.setCursorPos((maxX-#wlc)/2,maxY/2-4)
- term.setPaletteColor(colors.orange,term.getPaletteColor(colors.red))
- term.setTextColor(colors.orange)
- rainbowPrintEffect(wlc,0.3)
- sleep(0.3)
- --print to
- term.setCursorPos((maxX-3)/2,maxY/2-2)
- term.setPaletteColor(colors.green,term.getPaletteColor(colors.blue))
- term.setTextColor(colors.green)
- textutils.slowWrite("t o",5)
- --images
- local s_up= {t="\x98\x8C\x9B ",f="ee3e",b="33e3"}
- local s_mid={t="\x89\x8C\x9B ",f="ee3e",b="33e3"}
- local s_dwn={t="\x89\x8C\x86 ",f="eeee",b="3333"}
- local u_up= {t=" "--[["\x90 \x9F "]], f="eeee",b="3333"}
- local u_mid={t="\x95 \x95 ",f="ee3e",b="33e3"}
- --set new pal colors
- --pink / lightGray
- term.setPaletteColor(colors.lightGray,term.getPaletteColor(colors.blue))
- term.setPaletteColor(colors.pink,term.getPaletteColor(colors.red))
- term.setPaletteColor(colors.red,term.getPaletteColor(colors.lightBlue))
- term.setPaletteColor(colors.blue,term.getPaletteColor(colors.lightBlue))
- --blit images
- term.setTextColor(colors.lightGray)
- term.setCursorPos((maxX-28.5)/2,maxY/2)
- 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))
- term.setCursorPos((maxX-28.5)/2,maxY/2+1)
- 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))
- term.setCursorPos((maxX-28.5)/2,maxY/2+2)
- 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))
- animate_color(colors.blue,colors.lightGray,0.02,50)
- animate_color(colors.red,colors.pink,0.02,50)
- d=colors.lightBlue
- --hide text
- parallel.waitForAll(
- function()animate_color(colors.blue,d,0.03,40)end,
- function()animate_color(colors.red,d,0.03,40)end,
- function()animate_color(colors.orange,d,0.03,40)end,
- function()animate_color(colors.green,d,0.03,40)end)
- --reload pallete
- sleep(0.5)
- loadPal()
- end)
- end
- ------------------------------------------------------------------------------------
- ------------------------------------------------------------------------------------
- ------------------------------------------------------------------------------------
- --PrimeUI INIT SECTION (This part of code was created by JackMacWindows)
- local expect = require "cc.expect".expect
- -- Initialization code
- PrimeUI = {}
- do
- local coros = {}
- local restoreCursor
- --- Adds a task to run in the main loop.
- ---@param func function The function to run, usually an `os.pullEvent` loop
- function PrimeUI.addTask(func)
- expect(1, func, "function")
- local t = {coro = coroutine.create(func)}
- coros[#coros+1] = t
- _, t.filter = coroutine.resume(t.coro)
- end
- --- Sends the provided arguments to the run loop, where they will be returned.
- ---@param ... any The parameters to send
- function PrimeUI.resolve(...)
- coroutine.yield(coros, ...)
- end
- --- Clears the screen and resets all components. Do not use any previously
- --- created components after calling this function.
- function PrimeUI.clear()
- -- Reset the screen.
- term.setCursorPos(1, 1)
- term.setCursorBlink(false)
- term.setBackgroundColor(colors.lightBlue)
- term.setTextColor(colors.white)
- term.clear()
- -- Reset the task list and cursor restore function.
- coros = {}
- restoreCursor = nil
- end
- --- Sets or clears the window that holds where the cursor should be.
- ---@param win window|nil The window to set as the active window
- function PrimeUI.setCursorWindow(win)
- expect(1, win, "table", "nil")
- restoreCursor = win and win.restoreCursor
- end
- --- Gets the absolute position of a coordinate relative to a window.
- ---@param win window The window to check
- ---@param x number The relative X position of the point
- ---@param y number The relative Y position of the point
- ---@return number x The absolute X position of the window
- ---@return number y The absolute Y position of the window
- function PrimeUI.getWindowPos(win, x, y)
- if win == term then return x, y end
- while win ~= term.native() and win ~= term.current() do
- if not win.getPosition then return x, y end
- local wx, wy = win.getPosition()
- x, y = x + wx - 1, y + wy - 1
- _, win = debug.getupvalue(select(2, debug.getupvalue(win.isColor, 1)), 1) -- gets the parent window through an upvalue
- end
- return x, y
- end
- --- Runs the main loop, returning information on an action.
- ---@return any ... The result of the coroutine that exited
- function PrimeUI.run()
- while true do
- -- Restore the cursor and wait for the next event.
- if restoreCursor then restoreCursor() end
- local ev = table.pack(os.pullEvent())
- -- Run all coroutines.
- for _, v in ipairs(coros) do
- if v.filter == nil or v.filter == ev[1] then
- -- Resume the coroutine, passing the current event.
- local res = table.pack(coroutine.resume(v.coro, table.unpack(ev, 1, ev.n)))
- -- If the call failed, bail out. Coroutines should never exit.
- if not res[1] then error(res[2], 2) end
- -- If the coroutine resolved, return its values.
- if res[2] == coros then return table.unpack(res, 3, res.n) end
- -- Set the next event filter.
- v.filter = res[2]
- end
- end
- end
- end
- end
- --- Draws a line of text at a position.
- ---@param win window The window to draw on
- ---@param x number The X position of the left side of the text
- ---@param y number The Y position of the text
- ---@param text string The text to draw
- ---@param fgColor color|nil The color of the text (defaults to white)
- ---@param bgColor color|nil The color of the background (defaults to black)
- function PrimeUI.label(win, x, y, text, fgColor, bgColor)
- expect(1, win, "table")
- expect(2, x, "number")
- expect(3, y, "number")
- expect(4, text, "string")
- fgColor = expect(5, fgColor, "number", "nil") or colors.white
- bgColor = expect(6, bgColor, "number", "nil") or colors.black
- win.setCursorPos(x, y)
- win.setTextColor(fgColor)
- win.setBackgroundColor(bgColor)
- win.write(text)
- end
- --- Draws a horizontal line at a position with the specified width.
- ---@param win window The window to draw on
- ---@param x number The X position of the left side of the line
- ---@param y number The Y position of the line
- ---@param width number The width/length of the line
- ---@param fgColor color|nil The color of the line (defaults to white)
- ---@param bgColor color|nil The color of the background (defaults to black)
- function PrimeUI.horizontalLine(win, x, y, width, fgColor, bgColor)
- expect(1, win, "table")
- expect(2, x, "number")
- expect(3, y, "number")
- expect(4, width, "number")
- fgColor = expect(5, fgColor, "number", "nil") or colors.white
- bgColor = expect(6, bgColor, "number", "nil") or colors.black
- -- Use drawing characters to draw a thin line.
- win.setCursorPos(x, y)
- win.setTextColor(fgColor)
- win.setBackgroundColor(bgColor)
- win.write(("\x8C"):rep(width))
- end
- --- Creates a clickable button on screen with text.
- ---@param win window The window to draw on
- ---@param x number The X position of the button
- ---@param y number The Y position of the button
- ---@param text string The text to draw on the button
- ---@param action function|string A function to call when clicked, or a string to send with a `run` event
- ---@param fgColor color|nil The color of the button text (defaults to white)
- ---@param bgColor color|nil The color of the button (defaults to light gray)
- ---@param clickedColor color|nil The color of the button when clicked (defaults to gray)
- function PrimeUI.button(win, x, y, text, action, fgColor, bgColor, clickedColor,is_active)
- expect(1, win, "table")
- expect(2, x, "number")
- expect(3, y, "number")
- expect(4, text, "string")
- expect(5, action, "function", "string")
- fgColor = expect(6, fgColor, "number", "nil") or colors.white
- bgColor = expect(7, bgColor, "number", "nil") or colors.gray
- clickedColor = expect(8, clickedColor, "number", "nil") or colors.lightGray
- -- Draw the initial button.
- win.setCursorPos(x, y)
- win.setBackgroundColor(bgColor)
- win.setTextColor(fgColor)
- win.write(" " .. text .. " ")
- -- Get the screen position and add a click handler.
- PrimeUI.addTask(function()
- local buttonDown = false
- while true do
- local event, button, clickX, clickY = os.pullEvent()
- local screenX, screenY = PrimeUI.getWindowPos(win, x, y)
- local work=not is_active and true or is_active.active
- if work then
- if event == "mouse_click" and button == 1 and clickX >= screenX and clickX < screenX + #text + 2 and clickY == screenY then
- -- Initiate a click action (but don't trigger until mouse up).
- buttonDown = true
- -- Redraw the button with the clicked background color.
- win.setCursorPos(x, y)
- win.setBackgroundColor(clickedColor)
- win.setTextColor(fgColor)
- win.write(" " .. text .. " ")
- elseif event == "mouse_up" and button == 1 and buttonDown then
- -- Finish a click event.
- if clickX >= screenX and clickX < screenX + #text + 2 and clickY == screenY then
- -- Trigger the action.
- if type(action) == "string" then PrimeUI.resolve("button", action)
- else action() end
- end
- -- Redraw the original button state.
- win.setCursorPos(x, y)
- win.setBackgroundColor(bgColor)
- win.setTextColor(fgColor)
- win.write(" " .. text .. " ")
- end
- end
- end
- end)
- end
- --- Adds an action to trigger when a key is pressed.
- ---@param key key The key to trigger on, from `keys.*`
- ---@param action function|string A function to call when clicked, or a string to use as a key for a `run` return event
- function PrimeUI.keyAction(key, action)
- expect(1, key, "number")
- expect(2, action, "function", "string")
- PrimeUI.addTask(function()
- while true do
- local _, param1 = os.pullEvent("key") -- wait for key
- if param1 == key then
- if type(action) == "string" then PrimeUI.resolve("keyAction", action)
- else action() end
- end
- end
- end)
- end
- --- Adds an action to trigger when a key is pressed with modifier keys.
- ---@param key key The key to trigger on, from `keys.*`
- ---@param withCtrl boolean Whether Ctrl is required
- ---@param withAlt boolean Whether Alt is required
- ---@param withShift boolean Whether Shift is required
- ---@param action function|string A function to call when clicked, or a string to use as a key for a `run` return event
- function PrimeUI.keyCombo(key, withCtrl, withAlt, withShift, action)
- expect(1, key, "number")
- expect(2, withCtrl, "boolean")
- expect(3, withAlt, "boolean")
- expect(4, withShift, "boolean")
- expect(5, action, "function", "string")
- PrimeUI.addTask(function()
- local heldCtrl, heldAlt, heldShift = false, false, false
- while true do
- local event, param1, param2 = os.pullEvent() -- wait for key
- if event == "key" then
- -- check if key is down, all modifiers are correct, and that it's not held
- if param1 == key and heldCtrl == withCtrl and heldAlt == withAlt and heldShift == withShift and not param2 then
- if type(action) == "string" then PrimeUI.resolve("keyCombo", action)
- else action() end
- -- activate modifier keys
- elseif param1 == keys.leftCtrl or param1 == keys.rightCtrl then heldCtrl = true
- elseif param1 == keys.leftAlt or param1 == keys.rightAlt then heldAlt = true
- elseif param1 == keys.leftShift or param1 == keys.rightShift then heldShift = true end
- elseif event == "key_up" then
- -- deactivate modifier keys
- if param1 == keys.leftCtrl or param1 == keys.rightCtrl then heldCtrl = false
- elseif param1 == keys.leftAlt or param1 == keys.rightAlt then heldAlt = false
- elseif param1 == keys.leftShift or param1 == keys.rightShift then heldShift = false end
- end
- end
- end)
- end
- --- Creates a scrollable window, which allows drawing large content in a small area.
- ---@param win window The parent window of the scroll box
- ---@param x number The X position of the box
- ---@param y number The Y position of the box
- ---@param width number The width of the box
- ---@param height number The height of the outer box
- ---@param innerHeight number The height of the inner scroll area
- ---@param allowArrowKeys boolean|nil Whether to allow arrow keys to scroll the box (defaults to true)
- ---@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)
- ---@param fgColor number|nil The color of scroll indicators (defaults to white)
- ---@param bgColor color|nil The color of the background (defaults to black)
- ---@return window inner The inner window to draw inside
- function PrimeUI.scrollBox(win, x, y, width, height, innerHeight, allowArrowKeys, showScrollIndicators, fgColor, bgColor)
- expect(1, win, "table")
- expect(2, x, "number")
- expect(3, y, "number")
- expect(4, width, "number")
- expect(5, height, "number")
- expect(6, innerHeight, "number")
- expect(7, allowArrowKeys, "boolean", "nil")
- expect(8, showScrollIndicators, "boolean", "nil")
- fgColor = expect(9, fgColor, "number", "nil") or colors.white
- bgColor = expect(10, bgColor, "number", "nil") or colors.black
- if allowArrowKeys == nil then allowArrowKeys = true end
- -- Create the outer container box.
- local outer = window.create(win == term and term.current() or win, x, y, width, height)
- outer.setBackgroundColor(bgColor)
- outer.clear()
- -- Create the inner scrolling box.
- local inner = window.create(outer, 1, 1, width - (showScrollIndicators and 1 or 0), innerHeight)
- inner.setBackgroundColor(bgColor)
- inner.clear()
- -- Draw scroll indicators if desired.
- if showScrollIndicators then
- outer.setBackgroundColor(bgColor)
- outer.setTextColor(fgColor)
- outer.setCursorPos(width, height)
- outer.write(innerHeight > height and "\31" or " ")
- end
- -- Get the absolute position of the window.
- x, y = PrimeUI.getWindowPos(win, x, y)
- -- Add the scroll handler.
- PrimeUI.addTask(function()
- local scrollPos = 1
- while true do
- -- Wait for next event.
- local ev = table.pack(os.pullEvent())
- -- Update inner height in case it changed.
- innerHeight = select(2, inner.getSize())
- -- Check for scroll events and set direction.
- local dir
- if ev[1] == "key" and allowArrowKeys then
- if ev[2] == keys.up then dir = -1
- elseif ev[2] == keys.down then dir = 1 end
- elseif ev[1] == "mouse_scroll" and ev[3] >= x and ev[3] < x + width and ev[4] >= y and ev[4] < y + height then
- dir = ev[2]
- end
- -- If there's a scroll event, move the window vertically.
- if dir and (scrollPos + dir >= 1 and scrollPos + dir <= innerHeight - height) then
- scrollPos = scrollPos + dir
- inner.reposition(1, 2 - scrollPos)
- end
- -- Redraw scroll indicators if desired.
- if showScrollIndicators then
- outer.setBackgroundColor(bgColor)
- outer.setTextColor(fgColor)
- outer.setCursorPos(width, 1)
- outer.write(scrollPos > 1 and "\30" or " ")
- outer.setCursorPos(width, height)
- outer.write(scrollPos < innerHeight - height and "\31" or " ")
- end
- end
- end)
- return inner
- end
- --- Creates a text input box.
- ---@param win window The window to draw on
- ---@param x number The X position of the left side of the box
- ---@param y number The Y position of the box
- ---@param width number The width/length of the box
- ---@param action function|string A function or `run` event to call when the enter key is pressed
- ---@param fgColor color|nil The color of the text (defaults to white)
- ---@param bgColor color|nil The color of the background (defaults to black)
- ---@param replacement string|nil A character to replace typed characters with
- ---@param history string[]|nil A list of previous entries to provide
- ---@param completion function|nil A function to call to provide completion
- ---@param default string|nil A string to return if the box is empty
- function PrimeUI.inputBox(win, x, y, width, action, fgColor, bgColor, replacement, history, completion, default)
- expect(1, win, "table")
- expect(2, x, "number")
- expect(3, y, "number")
- expect(4, width, "number")
- expect(5, action, "function", "string")
- fgColor = expect(6, fgColor, "number", "nil") or colors.white
- bgColor = expect(7, bgColor, "number", "nil") or colors.black
- expect(8, replacement, "string", "nil")
- expect(9, history, "table", "nil")
- expect(10, completion, "function", "nil")
- expect(11, default, "string", "nil")
- -- Create a window to draw the input in.
- local box = window.create(win, x, y, width, 1)
- box.setTextColor(fgColor)
- box.setBackgroundColor(bgColor)
- box.clear()
- -- Call read() in a new coroutine.
- PrimeUI.addTask(function()
- -- We need a child coroutine to be able to redirect back to the window.
- local coro = coroutine.create(read)
- -- Run the function for the first time, redirecting to the window.
- local old = term.redirect(box)
- local ok, res = coroutine.resume(coro, replacement, history, completion, default)
- term.redirect(old)
- -- Run the coroutine until it finishes.
- while coroutine.status(coro) ~= "dead" do
- -- Get the next event.
- local ev = table.pack(os.pullEvent())
- -- Redirect and resume.
- old = term.redirect(box)
- ok, res = coroutine.resume(coro, table.unpack(ev, 1, ev.n))
- term.redirect(old)
- -- Pass any errors along.
- if not ok then error(res) end
- end
- -- Send the result to the receiver.
- if type(action) == "string" then PrimeUI.resolve("inputBox", action, res)
- else action(res) end
- -- Spin forever, because tasks cannot exit.
- while true do os.pullEvent() end
- end)
- end
- --- Creates a list of entries with toggleable check boxes.
- ---@param win window The window to draw on
- ---@param x number The X coordinate of the inside of the box
- ---@param y number The Y coordinate of the inside of the box
- ---@param width number The width of the inner box
- ---@param height number The height of the inner box
- ---@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)
- ---@param action function|string|nil A function or `run` event that's called when a selection is made
- ---@param fgColor color|nil The color of the text (defaults to white)
- ---@param bgColor color|nil The color of the background (defaults to black)
- function PrimeUI.checkSelectionBox(win, x, y, width, height, selections, action, fgColor, bgColor)
- expect(1, win, "table")
- expect(2, x, "number")
- expect(3, y, "number")
- expect(4, width, "number")
- expect(5, height, "number")
- expect(6, selections, "table")
- expect(7, action, "function", "string", "nil")
- fgColor = expect(8, fgColor, "number", "nil") or colors.white
- bgColor = expect(9, bgColor, "number", "nil") or colors.black
- -- Calculate how many selections there are.
- local nsel = 0
- for _ in pairs(selections) do nsel = nsel + 1 end
- -- Create the outer display box.
- local outer = window.create(win, x, y, width, height)
- outer.setBackgroundColor(bgColor)
- outer.clear()
- -- Create the inner scroll box.
- local inner = window.create(outer, 1, 1, width - 1, nsel)
- inner.setBackgroundColor(bgColor)
- inner.setTextColor(fgColor)
- inner.clear()
- -- Draw each line in the window.
- local lines = {}
- local nl, selected = 1, 1
- local bebra = 0
- for k, v in pairs(selections) do
- bebra=bebra+1
- inner.setCursorPos(1, nl)
- if bebra > 4 then inner.setTextColor(scnd_clr) end
- inner.write((v and (v == "R" and "[-] " or "[\xD7] ") or "[ ] ") .. k)
- lines[nl] = {k, not not v}
- nl = nl + 1
- end
- -- Draw a scroll arrow if there is scrolling.
- if nsel > height then
- outer.setCursorPos(width, height)
- outer.setBackgroundColor(bgColor)
- outer.setTextColor(fgColor)
- outer.write("\31")
- end
- -- Set cursor blink status.
- inner.setCursorPos(2, selected)
- inner.setCursorBlink(true)
- PrimeUI.setCursorWindow(inner)
- -- Get screen coordinates & add run task.
- local screenX, screenY = PrimeUI.getWindowPos(win, x, y)
- PrimeUI.addTask(function()
- local scrollPos = 1
- while true do
- inner.setTextColor(fgColor)
- -- Wait for an event.
- local ev = table.pack(os.pullEvent())
- -- Look for a scroll event or a selection event.
- local dir
- if ev[1] == "key" then
- if ev[2] == keys.up then dir = -1
- elseif ev[2] == keys.down then dir = 1
- elseif ev[2] == keys.space and selections[lines[selected][1]] ~= "R" then
- -- (Un)select the item.
- lines[selected][2] = not lines[selected][2]
- inner.setCursorPos(2, selected)
- if selected > 4 then inner.setTextColor(scnd_clr) end
- inner.write(lines[selected][2] and "\xD7" or " ")
- -- Call the action if passed; otherwise, set the original table.
- if type(action) == "string" then PrimeUI.resolve("checkSelectionBox", action, lines[selected][1], lines[selected][2])
- elseif action then action(lines[selected][1], lines[selected][2])
- else selections[lines[selected][1]] = lines[selected][2] end
- -- Redraw all lines in case of changes.
- for i, v in ipairs(lines) do
- local vv = selections[v[1]] == "R" and "R" or v[2]
- inner.setCursorPos(2, i)
- if i > 4 then inner.setTextColor(scnd_clr) end
- inner.write((vv and (vv == "R" and "-" or "\xD7") or " "))
- end
- inner.setCursorPos(2, selected)
- end
- elseif ev[1] == "mouse_scroll" and ev[3] >= screenX and ev[3] < screenX + width and ev[4] >= screenY and ev[4] < screenY + height then
- dir = ev[2]
- end
- -- Scroll the screen if required.
- if dir and (selected + dir >= 1 and selected + dir <= nsel) then
- selected = selected + dir
- if selected - scrollPos < 0 or selected - scrollPos >= height then
- scrollPos = scrollPos + dir
- inner.reposition(1, 2 - scrollPos)
- end
- inner.setCursorPos(2, selected)
- end
- -- Redraw scroll arrows and reset cursor.
- outer.setCursorPos(width, 1)
- outer.write(scrollPos > 1 and "\30" or " ")
- outer.setCursorPos(width, height)
- outer.write(scrollPos < nsel - height + 1 and "\31" or " ")
- inner.restoreCursor()
- end
- end)
- end
- --- Creates a text box that wraps text and can have its text modified later.
- ---@param win window The parent window of the text box
- ---@param x number The X position of the box
- ---@param y number The Y position of the box
- ---@param width number The width of the box
- ---@param height number The height of the box
- ---@param text string The initial text to draw
- ---@param fgColor color|nil The color of the text (defaults to white)
- ---@param bgColor color|nil The color of the background (defaults to black)
- ---@return function redraw A function to redraw the window with new contents
- function PrimeUI.textBox(win, x, y, width, height, text, fgColor, bgColor)
- expect(1, win, "table")
- expect(2, x, "number")
- expect(3, y, "number")
- expect(4, width, "number")
- expect(5, height, "number")
- expect(6, text, "string")
- fgColor = expect(7, fgColor, "number", "nil") or colors.white
- bgColor = expect(8, bgColor, "number", "nil") or colors.black
- -- Create the box window.
- local box = window.create(win, x, y, width, height)
- -- Override box.getSize to make print not scroll.
- function box.getSize()
- return width, math.huge
- end
- -- Define a function to redraw with.
- local function redraw(_text)
- expect(1, _text, "string")
- -- Set window parameters.
- box.setBackgroundColor(bgColor)
- box.setTextColor(fgColor)
- box.clear()
- box.setCursorPos(1, 1)
- -- Redirect and draw with `print`.
- local old = term.redirect(box)
- print(_text)
- term.redirect(old)
- end
- redraw(text)
- return redraw
- end
- --- Draws a thin border around a screen region.
- ---@param win window The window to draw on
- ---@param x number The X coordinate of the inside of the box
- ---@param y number The Y coordinate of the inside of the box
- ---@param width number The width of the inner box
- ---@param height number The height of the inner box
- ---@param fgColor color|nil The color of the border (defaults to white)
- ---@param bgColor color|nil The color of the background (defaults to black)
- function PrimeUI.borderBox(win, x, y, width, height, fgColor, bgColor)
- expect(1, win, "table")
- expect(2, x, "number")
- expect(3, y, "number")
- expect(4, width, "number")
- expect(5, height, "number")
- fgColor = expect(6, fgColor, "number", "nil") or colors.white
- bgColor = expect(7, bgColor, "number", "nil") or colors.black
- -- Draw the top-left corner & top border.
- win.setBackgroundColor(bgColor)
- win.setTextColor(fgColor)
- win.setCursorPos(x - 1, y - 1)
- win.write("\x9C" .. ("\x8C"):rep(width))
- -- Draw the top-right corner.
- win.setBackgroundColor(fgColor)
- win.setTextColor(bgColor)
- win.write("\x93")
- -- Draw the right border.
- for i = 1, height do
- win.setCursorPos(win.getCursorPos() - 1, y + i - 1)
- win.write("\x95")
- end
- -- Draw the left border.
- win.setBackgroundColor(bgColor)
- win.setTextColor(fgColor)
- for i = 1, height do
- win.setCursorPos(x - 1, y + i - 1)
- win.write("\x95")
- end
- -- Draw the bottom border and corners.
- win.setCursorPos(x - 1, y + height)
- win.write("\x8D" .. ("\x8C"):rep(width) .. "\x8E")
- end
- --- Draws a block of text inside a window with word wrapping, optionally resizing the window to fit.
- ---@param win window The window to draw in
- ---@param text string The text to draw
- ---@param resizeToFit boolean|nil Whether to resize the window to fit the text (defaults to false). This is useful for scroll boxes.
- ---@param fgColor color|nil The color of the text (defaults to white)
- ---@param bgColor color|nil The color of the background (defaults to black)
- ---@return number lines The total number of lines drawn
- function PrimeUI.drawText(win, text, resizeToFit, fgColor, bgColor)
- expect(1, win, "table")
- expect(2, text, "string")
- expect(3, resizeToFit, "boolean", "nil")
- fgColor = expect(4, fgColor, "number", "nil") or colors.white
- bgColor = expect(5, bgColor, "number", "nil") or colors.black
- -- Set colors.
- win.setBackgroundColor(bgColor)
- win.setTextColor(fgColor)
- -- Redirect to the window to use print on it.
- local old = term.redirect(win)
- -- Draw the text using print().
- local lines = print(text)
- -- Redirect back to the original terminal.
- term.redirect(old)
- -- Resize the window if desired.
- if resizeToFit then
- -- Get original parameters.
- local x, y = win.getPosition()
- local w = win.getSize()
- -- Resize the window.
- win.reposition(x, y, w, lines)
- end
- return lines
- end
- --- Runs a function or action after the specified time period, with optional canceling.
- ---@param time number The amount of time to wait for, in seconds
- ---@param action function|string The function to call when the timer completes, or a `run` event to send
- ---@return function cancel A function to cancel the timer
- function PrimeUI.timeout(time, action)
- expect(1, time, "number")
- expect(2, action, "function", "string")
- -- Start the timer.
- local timer = os.startTimer(time)
- -- Add a task to wait for the timer.
- PrimeUI.addTask(function()
- while true do
- -- Wait for a timer event.
- local _, tm = os.pullEvent("timer")
- if tm == timer then
- -- Fire the timer action.
- if type(action) == "string" then PrimeUI.resolve("timeout", action)
- else action() end
- end
- end
- end)
- -- Return a function to cancel the timer.
- return function() os.cancelTimer(timer) end
- end
- --PrimeUI INIT END
- ------------------------------------------------------------------------------------
- ------------------------------------------------------------------------------------
- ------------------------------------------------------------------------------------
- Main() --execute main prog
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement