1
1
mirror of https://git.shadowkat.net/izaya/OC-PsychOS2.git synced 2024-11-22 12:04:20 -05:00

Compare commits

...

4 Commits

Author SHA1 Message Date
XeonSquared
dcf0cb75ae made spawnfile queue an event on a process ending, changed the shell to use it 2019-12-16 14:37:29 +11:00
XeonSquared
8404946eba removed chatbox-dprint from the default modules 2019-12-16 14:35:26 +11:00
XeonSquared
560cd4e0c7 made serialization have an extra param for display 2019-12-16 14:35:11 +11:00
XeonSquared
b370a90618 commented some scheduler functions 2019-12-16 14:30:27 +11:00
5 changed files with 18 additions and 22 deletions

View File

@ -1,4 +1,5 @@
local serial = require "serialization"
local event = require "event"
print(pcall(function()
local shenv = {}
function shenv.quit()
@ -21,21 +22,14 @@ setmetatable(shenv,{__index=function(_,k)
if _G[k] then
return _G[k]
elseif fp then
local rqid = string.format("shell-%d",math.random(1,99999))
return function(...)
local tA = {...}
local pid = os.spawn(function() computer.pushSignal(rqid,pcall(loadfile(fp),table.unpack(tA))) end,fp)
local tE = {}
repeat
tE = {coroutine.yield()}
if tE[1] == rqid then
table.remove(tE,1)
if tE[1] == true then
table.remove(tE,1)
end
return table.unpack(tE)
end
until not os.taskInfo(pid)
local pid = os.spawnfile(fp,fp,table.unpack(tA))
local tE = event.pull("process_finished",pid)
if tE[1] == true then
table.remove(tE,1)
end
return table.unpack(tE)
end
end
end})
@ -51,7 +45,7 @@ while os.getenv("run") do
if tResult[1] == true then table.remove(tResult,1) end
for k,v in pairs(tResult) do
if type(v) == "table" then
print(serial.serialize(v))
print(serial.serialize(v,true))
else
print(v)
end

View File

@ -3,7 +3,7 @@ local local_pairs=function(tbl)
local mt=getmetatable(tbl)
return (mt and mt.__pairs or pairs)(tbl)
end
function serial.serialize(value)
function serial.serialize(value,af) -- serialize *value* into a string. If *af* is true, allow functions. This breaks unserialization.
local kw={["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 id="^[%a_][%w_]*$"
local ts={}
@ -35,10 +35,12 @@ function serial.serialize(value)
r=r.."="..s(v,l+1) end end
ts[v]=nil
return (r or "{").."}"
elseif t=="function" and af then
return tostring(v)
else error("ut "..t) end end
return s(value, 1)
end
function serial.unserialize(data)
function serial.unserialize(data) -- return *data*, but unserialized
checkArg(1, data, "string")
local result, reason = load("return " .. data, "=data", _, {math={huge=math.huge}})
if not result then return nil, reason end

View File

@ -1,4 +1,3 @@
--#include "module/chatbox-dprint.lua"
--#include "module/syslog.lua"
--#include "module/sched.lua"
--#include "module/osutil.lua"

View File

@ -7,8 +7,9 @@ end
function runfile(p,...) -- runs file *p* with arbitrary arguments in the current thread
return loadfile(p)(...)
end
function os.spawnfile(p,n) -- spawns a new process from file *p* with name *n*
return os.spawn(function() xpcall(loadfile(p),function(e) dprint(e.."\n"..debug.traceback()) end) end,n or p)
function os.spawnfile(p,n,...) -- spawns a new process from file *p* with name *n*, with arguments following *n*.
local tA = {...}
return os.spawn(function() computer.pushSignal("process_finished", os.pid(), pcall(loadfile(p), table.unpack(tA))) end,n or p)
end
function require(f) -- searches for a library with name *f* and returns what the library returns, if possible
local lib = os.getenv("LIB") or "/boot/lib"

View File

@ -19,17 +19,17 @@ end
function os.kill(pid) -- removes process *pid* from the task list
tTasks[pid] = nil
end
function os.pid()
function os.pid() -- returns the current process' PID
return cPid
end
function os.tasks()
function os.tasks() -- returns a table of process IDs
local rt = {}
for k,v in pairs(tTasks) do
rt[#rt+1] = k
end
return rt
end
function os.taskInfo(pid)
function os.taskInfo(pid) -- returns info on process *pid* as a table with name and parent values
pid = pid or os.pid()
if not tTasks[pid] then return false end
return {name=tTasks[pid].n,parent=tTasks[pid].P}