local a=0xFFFF00;local b=0xDBDBDB;local c=0x00FFFF;local d=0xFF0000;local e=0x00FF00;local f=0x00FF88;local g=0x24FFFF;local h=0xFF6D00;local i=0x6D6D6D;local j=0xDBDBDB;local function k(l)syscall.devctl(1,"sfgc",l)end;local function m(n)syscall.write(1,tostring(n))end;local o=6;local p=64;local function q(r,s,t)s=s or 0;t=t or{}local u=type(r)if u=="nil"then k(i)m("nil")elseif u=="boolean"then k(h)m(tostring(r))elseif u=="number"then k(g)if r~=r then m("nan")elseif r==math.huge then m("inf")elseif r==-math.huge then m("-inf")elseif r==math.floor(r)and math.abs(r)<1e15 then m(tostring(math.floor(r)))else m(tostring(r))end elseif u=="string"then k(f)local n=string.format("%q",r)m(n)elseif u=="function"then k(j)m(tostring(r))elseif u=="table"then if t[r]then k(j)m("<circular "..tostring(r)..">")return end;if s>=o then k(j)m("<table "..tostring(r)..">")return end;t[r]=true;local v=string.rep("  ",s)local w=string.rep("  ",s+1)local x={}local y={}local z=#r;for A in pairs(r)do if type(A)=="number"and A>=1 and A<=z and A==math.floor(A)then x[#x+1]=A else y[#y+1]=A end end;table.sort(x)table.sort(y,function(B,C)local D,E=type(B),type(C)if D==E then if D=="string"then return B<C end;if D=="number"then return B<C end;return tostring(B)<tostring(C)end;return D<E end)local F=#x+#y;if F==0 then k(j)m("{}")t[r]=nil;return end;k(j)m("{\n")local G=0;local function H(A,I,J)G=G+1;if G>p then return true end;m(w)if type(A)=="number"and x[A]then else if type(A)=="string"and A:match("^[a-zA-Z_][a-zA-Z0-9_]*$")then k(e)m(A)else k(j)m("[")q(A,s+1,t)k(j)m("]")end;k(j)m(" = ")end;q(I,s+1,t)k(j)if not J then m(",")end;m("\n")end;for K,A in ipairs(x)do m(w)q(r[A],s+1,t)k(j)if K<F then m(",")end;m("\n")G=G+1;if G>=p then k(i)m(w.."-- ..."..F-G.." more entries\n")break end end;if G<p then for K,A in ipairs(y)do local J=G+1>=F;m(w)if type(A)=="string"and A:match("^[a-zA-Z_][a-zA-Z0-9_]*$")then k(e)m(A)else k(j)m("[")q(A,s+1,t)k(j)m("]")end;k(j)m(" = ")q(r[A],s+1,t)k(j)G=G+1;if G<F then m(",")end;m("\n")if G>=p then local L=F-G;if L>0 then k(i)m(w.."-- ..."..L.." more entries\n")end;break end end end;k(j)m(v.."}")t[r]=nil else k(j)m(tostring(r))end;k(1)end;local function M(...)local N=select("#",...)if N==0 then return end;for K=1,N do if K>1 then k(j)m("\t")end;q(select(K,...),0,{})end;m("\n")k(1)end;local O=setmetatable({},{__index=_ENV})O._G=O;O.print=function(...)local N=select("#",...)for K=1,N do if K>1 then m("\t")end;q(select(K,...),0,{})end;m("\n")k(1)end;O.pp=function(r)q(r,0,{})m("\n")k(1)end;O.exit=setmetatable({},{__tostring=function()return"function: exit()"end,__call=function()syscall.exit()end})local function P(Q)local R=load("return "..Q,"@lua","t",O)if R then return R,true end;local S,T=load(Q,"@lua","t",O)return S,false,T end;local function U(Q)local V,T=load(Q,"@lua","t",O)return T and(T:find("<eof>")~=nil or T:find("'end'")~=nil or T:find("'then'")~=nil or T:find("'until'")~=nil)end;local function W(X)return tostring(X):gsub("^%[string .-%]:",""):gsub("^@lua:",""):gsub("stack traceback:.*",""):match("^%s*(.-)%s*$")end;local function Y(Q)local Z,_,T=P(Q)if not Z then k(d)m("[error] ")k(1)m(W(T).."\n")return end;local a0=table.pack(xpcall(Z,debug.traceback))local a1=table.remove(a0,1)a0.n=a0.n-1;if not a1 then k(d)m("[error] ")k(1)m(W(a0[1]).."\n")elseif _ and a0.n>0 then k(c)m("= ")M(table.unpack(a0,1,a0.n))end end;local function a2(a3,a4)k(a)m(a3)k(1)local a5=syscall.devctl(1,"gpos")local a6=tonumber(a5:sub(1,a5:find(";")-1))local a7=tonumber(a5:sub(a5:find(";")+1))local a8=""local a9=1;local aa=0;local ab=false;local ac=true;local function ad()syscall.devctl(1,"spos",a6,a7)m(a8:sub(1,a9-1))if ab then syscall.devctl(1,"sfgc",0x000000)syscall.devctl(1,"sbgc",1)end;m(a9>#a8 and" "or a8:sub(a9,a9))syscall.devctl(1,"sfgc",0xFFFFFF)syscall.devctl(1,"sbgc",16)m(a8:sub(a9+1).." ")ac=false end;while true do local ae=syscall.read(0)if ae and ae~=""then if ae=="[C"then if a9>1 then a9=a9-1;ac=true end elseif ae=="[D"then if a9<=#a8 then a9=a9+1;ac=true end elseif ae=="[A"then if a4 and aa<#a4 then aa=aa+1;a8=a4[#a4-aa+1]a9=#a8+1;ac=true end elseif ae=="[B"then if aa>1 then aa=aa-1;a8=a4[#a4-aa+1]a9=#a8+1;ac=true elseif aa==1 then aa=0;a8=""a9=1;ac=true end elseif ae=="\b"then if a9>1 then a8=a8:sub(1,a9-2)..a8:sub(a9)a9=a9-1;ac=true end elseif ae=="\n"then syscall.devctl(1,"sfgc",0xFFFFFF)syscall.devctl(1,"sbgc",16)syscall.devctl(1,"spos",a6,a7)m(a8 .." \n")return a8 elseif#ae==1 and ae:byte(1)>=32 and ae:byte(1)<127 then a8=string.sub(a8,1,a9-1)..ae..string.sub(a8,a9)a9=a9+1;ac=true end end;local af=math.floor(syscall.getUptime()/500)%2==0;if af~=ab then ab=af;ac=true end;if ac then ad()end end end;k(a)m("HyperionOS ".._VERSION.."\n")k(i)m("Interactive Lua REPL. exit() to quit.\n\n")k(1)local a4={}while true do local Q=a2("lua> ",a4)if Q~=""then while U(Q)do Q=Q.."\n"..a2("...  ",nil)end;if Q~=a4[#a4]then a4[#a4+1]=Q end;Y(Q)end end
