stuff.mp4

This commit is contained in:
2025-12-17 11:53:54 -05:00
parent 6d9d02edf7
commit e63bb275a0
92 changed files with 1060 additions and 965 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,9 @@
local deflate=require("LibDeflate")
local lib={}
lib.compress=function(data)
return deflate:CompressDeflate(data)
end
lib.decompress=function(data)
return deflate:DecompressDeflate(data)
end
return lib

View File

@@ -0,0 +1,138 @@
local fs={}
-- 1 : open
-- 2 : read
-- 3 : write
-- 4 : close
function fs.open(path, mode)
local fd=cororoutine.yield(1,path,mode)
local ret={
close=function()
-- close file
return coroutine.yield(4,fd)
end,
flush=function()
-- close and reopen file to flush buffers
coroutine.yield(4,fd)
fd=coroutine.yield(1,path,mode)
end
}
if mode=="r" then
ret.read=function(count)
return coroutine.yield(2,fd,count)
end
ret.readAll=function()
local chunks={} -- to store read chunks
while true do
local chunk=coroutine.yield(2,fd,math.huge)
if chunk==nil or #chunk==0 then break end
table.insert(chunks,chunk)
end
return table.concat(chunks)
end
ret.readLine = function()
local buffer = {} -- stores leftover data
local buffer_str = "" -- concatenated buffer
local chunk_size = 4096 -- adjust chunk size for performance
local eof = false
while true do
-- Try to find a newline in the current buffer
local line_end = buffer_str:find("\n")
if line_end then
local line = buffer_str:sub(1, line_end - 1)
buffer_str = buffer_str:sub(line_end + 1)
return line
end
-- If EOF was reached previously and buffer is empty, stop
if eof then
if buffer_str ~= "" then
local last_line = buffer_str
buffer_str = ""
return last_line
else
return nil
end
end
-- Read the next chunk
local chunk = coroutine.yield(2, fd, chunk_size)
if not chunk or chunk == "" then
eof = true
else
buffer_str = buffer_str .. chunk
end
end
end
elseif mode=="w" then
ret.write=function(data)
-- write data to file
return coroutine.yield(3,fd,data)
end
elseif mode=="a" then
ret.write=function(data)
-- append data to file
return coroutine.yield(3,fd,data)
end
else
error("Invalid mode '"..mode.."'",2)
end
return ret
end
function fs.readAllText(path)
local file=fs.open(path,"r")
if not file then return false end
local content=file.readAll()
file.close()
return content
end
function fs.writeAllText(path, data)
local file=fs.open(path,"w")
file.write(data)
file.close()
end
function fs.appendAllText(path, data)
local file=fs.open(path,"a")
if not file then return false end
file.write(data)
file.close()
end
function fs.mkdir(path)
coroutine.yield(8,path)
end
function fs.remove(path)
coroutine.yield(9,path)
end
function fs.list(path)
return coroutine.yield(5,path)
end
function fs.type(path)
return coroutine.yield(6,path)
end
function fs.attributes(path)
return coroutine.yield(7,path)
end
function fs.exists(path)
return coroutine.yield(10, path)
end
function fs.getcwd()
return coroutine.yield(11)
end
function fs.setcwd(path)
return coroutine.yield(12, path)
end
return fs

View File

@@ -0,0 +1,74 @@
local sys = {}
local fs = require("fs")
function sys.spawn(func, name, envars, args)
return coroutine.yield(0x10, func, name, envars, args)
end
function sys.spawnFromFile(path, name, envars, args)
local data = fs.readAllText(path)
if not data then
error("File not found: "..path,2)
end
local func, err = load(data, "@"..path)
if not func then
error("Error loading file "..path..": "..tostring(err),2)
end
return coroutine.yield(0x10, func, name, envars, args)
end
function sys.spawnAndWait(func, name, envars, args)
local pid = coroutine.yield(0x10, func, name, envars, args)
local oldsignal = sys.getSignalHandler(17)
local exit = false
sys.setSignalHandler(17, function()
local tasks = sys.getChildrenTasks(pid)
if not tasks[pid] then
exit = true
end
end)
while not exit do
coroutine.yield()
end
sys.setSignalHandler(17, oldsignal)
return pid
end
function sys.spawnFromFileAndWait(path, name, envars, args)
local data = fs.readAllText(path)
if not data then
error("File not found: "..path,2)
end
local func, err = load(data, "@"..path)
if not func then
error("Error loading file "..path..": "..tostring(err),2)
end
return sys.spawnAndWait(func, name, envars, args)
end
function sys.exit(code)
return coroutine.yield(0x14, code)
end
function sys.setSignalHandler(signal, func)
return coroutine.yield(0x11, signal, func)
end
function sys.sendSignal(pid, signal)
return coroutine.yield(0x12, pid, signal)
end
function sys.getSignalHandler(signal)
return coroutine.yield(0x13, signal)
end
function sys.getChildrenTasks(PID)
PID = PID or sys.getCurrentTaskID()
return coroutine.yield(0x15, PID)
end
function sys.getCurrentTaskID()
return coroutine.yield(0x16)
end
return sys

View File

@@ -0,0 +1,11 @@
local userdata={}
userdata.policy={}
userdata.policy.readOnly=1
userdata.policy.readWrite=2
userdata.policy.WriteOnly=3
userdata.policy.hidden=4
userdata.policy.custom=5
function userdata.create()
return setmetatable()
end

View File

@@ -0,0 +1,7 @@
local args={...}
local kernel=args[1]
local os=require("os")
for i,v in pairs(kernel.drivers.processes) do
os.spawn(v, i, {}, {})
end
kernel.fs.load("/bin/bash")()