Add k.lua

This commit is contained in:
Astronand committed 2026-03-26 13:49:04 -04:00
1 parent 9318ce7ce3
commit 540facad72
1 file changed
+1
+1
View File
@@ -0,0 +1 @@
if _ENV~=_G then error("Phoenix must be run in the global environment, with a bootloader such as pxboot or UnBIOS. It cannot be run as a normal program.")end;PHOENIX_VERSION="0.0.9"PHOENIX_BUILD="PRERELEASE NONFREE Mon Sep 15 23:39:00 2025"systemStartTime=os.epoch"utc"args={init="/sbin/init.lua",root="/root",rootfstype="craftos",preemptive=true,quantum=20000,splitkernpath="/boot/kernel.lua.d",loglevel=1,console="tty1",traceback=true}syscalls={}processes={[0]={name="kernel",id=0,user="root",dir="/",root="/",env=_G,vars={},dependents={}}}KERNEL=processes[0]modules={}eventHooks={}shutdownHooks={}debugHooks=setmetatable({},{__mode="k"})kSyscallYield={}kSyscallComplete={}process={}filesystem={}terminal={}syslog={}hardware={}if discord then discord("Phoenix","Booting Phoenix "..PHOENIX_VERSION)end;expect={}local a={["nil"]=true,boolean=true,number=true,string=true,table=true,["function"]=true,userdata=true,thread=true}local function b(c)return type(c)=="table"and(getmetatable(c)or{}).__call or type(c)=="function"end;local function d(e,g,...)local h=type(g)local i;if h=="table"then local j=getmetatable(g)if j then i=j.__name end end;local args=table.pack(...)for k,l in ipairs(args)do if a[l]then if h==l then return g end elseif i==l then return g elseif b(l)and l(g)then return g end end;local info=debug.getinfo(2,"n")if info and info.name and info.name~=""then e=e.." to '"..info.name.."'"end;local m;if#args==1 and b(args[1])then local k,n=args[1](g)error(e.." ("..n..")",3)else for o,c in ipairs(args)do args[o]=tostring(c)end;if args.n==1 then m=args[1]elseif args.n==2 then m=args[1].." or "..args[2]else m=table.concat(args,", ",1,args.n-1)..", or "..args[args.n]end;error(e.." (expected "..m..", got "..h..")",3)end end;function expect.expect(p,g,...)return d("bad argument #"..p,g,...)end;function expect.field(q,r,...)local s,t=pcall(string.format,"%q",r)if not s then t=tostring(r)end;return d("bad field "..t,q[r],...)end;function expect.range(u,v,w)expect.expect(1,u,"number")expect.expect(2,v,"number","nil")expect.expect(3,w,"number","nil")if w and v and w<v then error("bad argument #3 (min must be less than or equal to max)",2)end;if u~=u or u<(v or-math.huge)or u>(w or math.huge)then error(("number outside of range (expected %s to be within %s and %s)"):format(u,v or-math.huge,w or math.huge),3)end;return u end;setmetatable(expect,{__call=function(self,...)return expect.expect(...)end})local x={["and"]=true,["break"]=true,["do"]=true,["else"]=true,["elseif"]=true,["end"]=true,["false"]=true,["for"]=true,["function"]=true,["goto"]=true,["if"]=true,["in"]=true,["local"]=true,["nil"]=true,["not"]=true,["or"]=true,["repeat"]=true,["return"]=true,["then"]=true,["true"]=true,["until"]=true,["while"]=true}local function y(z,A,B,C)if A[z]then error("Cannot serialize recursive value",0)end;local D=type(z)if D=="table"then if not next(z)then return"{}"end;A[z]=true;local E=B.minified and"{"or"{\n"local u={}for o,c in ipairs(z)do if not B.minified then E=E..(" "):rep(C)end;u[o]=true;E=E..y(c,A,B,C+1)..(B.minified and","or",\n")end;for F,c in pairs(z)do if not u[F]then if not B.minified then E=E..(" "):rep(C)end;if type(F)=="string"and F:match"^[A-Za-z_][A-Za-z0-9_]*$"and not x[F]then E=E..F else E=E.."["..y(F,A,B,C+1).."]"end;E=E..(B.minified and"="or" = ")..y(c,A,B,C+1)..(B.minified and","or",\n")end end;if B.minified then E=E:gsub(",$","")else E=E..(" "):rep(C-1)end;A[z]=nil;return E.."}"elseif D=="nil"or D=="number"or D=="boolean"or D=="string"then return("%q"):format(z):gsub("\\\n","\\n"):gsub("\\?[%z\1-\31\127-\255]",function(G)return("\\%03d"):format(string.byte(G))end)else error("Cannot serialize type "..D,0)end end;function serialize(z,B)expect(2,B,"table","nil")return y(z,{},B or{},1)end;function unserialize(t)expect(1,t,"string")return assert(load("return "..t,"=unserialize","t",{}))()end;do local H=fs.open("/rom/apis/keys.lua","r")local I=setmetatable({dofile=function()return expect end},{__index=_G})if _VERSION<"Lua 5.2"then I._ENV=I end;local J;if loadstring and setfenv then J=loadstring(H.readAll(),"@/rom/apis/keys.lua")setfenv(J,I)else J=load(H.readAll(),"@/rom/apis/keys.lua","t",I)end;H.close()J()keys={}for F,c in pairs(I)do keys[F]=c end end;local K=load;if not pcall(load,"return","=test","t",{})then local L,M,expect,setfenv=load,loadstring,expect,setfenv;function load(N,O,P,I)expect(1,N,"string","function")expect(2,O,"string","nil")expect(3,P,"string","nil")expect(4,I,"table","nil")if type(N)=="string"then if N:sub(1,4)=="\27Lua"then if P==nil or P:find"b"then local J,n=M(N,O)if J and I then setfenv(J,I)end;return J,n else return nil,"attempt to load a binary chunk (mode is '"..(P or"bt").."')"end else if P==nil or P:find"t"then local J,n=M(N,O)if J and I then setfenv(J,I)end;return J,n else return nil,"attempt to load a text chunk (mode is '"..(P or"bt").."')"end end else local J,n=L(N,O)if J then setfenv(J,I)end;return J,n end end end;loadstring=nil;if bit then if not bit32 then local bit=bit;bLine truncated