Compare commits
No commits in common. "dcf0cb75ae288f95d6654eeefe30d4a6cf8dba20" and "f80a58ce1dd8c96df9e28d94597d33393f0f3f3e" have entirely different histories.
dcf0cb75ae
...
f80a58ce1d
@ -1,5 +1,4 @@
|
|||||||
local serial = require "serialization"
|
local serial = require "serialization"
|
||||||
local event = require "event"
|
|
||||||
print(pcall(function()
|
print(pcall(function()
|
||||||
local shenv = {}
|
local shenv = {}
|
||||||
function shenv.quit()
|
function shenv.quit()
|
||||||
@ -22,15 +21,22 @@ setmetatable(shenv,{__index=function(_,k)
|
|||||||
if _G[k] then
|
if _G[k] then
|
||||||
return _G[k]
|
return _G[k]
|
||||||
elseif fp then
|
elseif fp then
|
||||||
|
local rqid = string.format("shell-%d",math.random(1,99999))
|
||||||
return function(...)
|
return function(...)
|
||||||
local tA = {...}
|
local tA = {...}
|
||||||
local pid = os.spawnfile(fp,fp,table.unpack(tA))
|
local pid = os.spawn(function() computer.pushSignal(rqid,pcall(loadfile(fp),table.unpack(tA))) end,fp)
|
||||||
local tE = event.pull("process_finished",pid)
|
local tE = {}
|
||||||
|
repeat
|
||||||
|
tE = {coroutine.yield()}
|
||||||
|
if tE[1] == rqid then
|
||||||
|
table.remove(tE,1)
|
||||||
if tE[1] == true then
|
if tE[1] == true then
|
||||||
table.remove(tE,1)
|
table.remove(tE,1)
|
||||||
end
|
end
|
||||||
return table.unpack(tE)
|
return table.unpack(tE)
|
||||||
end
|
end
|
||||||
|
until not os.taskInfo(pid)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end})
|
end})
|
||||||
print(_VERSION)
|
print(_VERSION)
|
||||||
@ -45,7 +51,7 @@ while os.getenv("run") do
|
|||||||
if tResult[1] == true then table.remove(tResult,1) end
|
if tResult[1] == true then table.remove(tResult,1) end
|
||||||
for k,v in pairs(tResult) do
|
for k,v in pairs(tResult) do
|
||||||
if type(v) == "table" then
|
if type(v) == "table" then
|
||||||
print(serial.serialize(v,true))
|
print(serial.serialize(v))
|
||||||
else
|
else
|
||||||
print(v)
|
print(v)
|
||||||
end
|
end
|
||||||
|
@ -3,7 +3,7 @@ local local_pairs=function(tbl)
|
|||||||
local mt=getmetatable(tbl)
|
local mt=getmetatable(tbl)
|
||||||
return (mt and mt.__pairs or pairs)(tbl)
|
return (mt and mt.__pairs or pairs)(tbl)
|
||||||
end
|
end
|
||||||
function serial.serialize(value,af) -- serialize *value* into a string. If *af* is true, allow functions. This breaks unserialization.
|
function serial.serialize(value)
|
||||||
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 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 id="^[%a_][%w_]*$"
|
||||||
local ts={}
|
local ts={}
|
||||||
@ -35,12 +35,10 @@ function serial.serialize(value,af) -- serialize *value* into a string. If *af*
|
|||||||
r=r.."="..s(v,l+1) end end
|
r=r.."="..s(v,l+1) end end
|
||||||
ts[v]=nil
|
ts[v]=nil
|
||||||
return (r or "{").."}"
|
return (r or "{").."}"
|
||||||
elseif t=="function" and af then
|
|
||||||
return tostring(v)
|
|
||||||
else error("ut "..t) end end
|
else error("ut "..t) end end
|
||||||
return s(value, 1)
|
return s(value, 1)
|
||||||
end
|
end
|
||||||
function serial.unserialize(data) -- return *data*, but unserialized
|
function serial.unserialize(data)
|
||||||
checkArg(1, data, "string")
|
checkArg(1, data, "string")
|
||||||
local result, reason = load("return " .. data, "=data", _, {math={huge=math.huge}})
|
local result, reason = load("return " .. data, "=data", _, {math={huge=math.huge}})
|
||||||
if not result then return nil, reason end
|
if not result then return nil, reason end
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
--#include "module/chatbox-dprint.lua"
|
||||||
--#include "module/syslog.lua"
|
--#include "module/syslog.lua"
|
||||||
--#include "module/sched.lua"
|
--#include "module/sched.lua"
|
||||||
--#include "module/osutil.lua"
|
--#include "module/osutil.lua"
|
||||||
|
@ -7,9 +7,8 @@ end
|
|||||||
function runfile(p,...) -- runs file *p* with arbitrary arguments in the current thread
|
function runfile(p,...) -- runs file *p* with arbitrary arguments in the current thread
|
||||||
return loadfile(p)(...)
|
return loadfile(p)(...)
|
||||||
end
|
end
|
||||||
function os.spawnfile(p,n,...) -- spawns a new process from file *p* with name *n*, with arguments following *n*.
|
function os.spawnfile(p,n) -- spawns a new process from file *p* with name *n*
|
||||||
local tA = {...}
|
return os.spawn(function() xpcall(loadfile(p),function(e) dprint(e.."\n"..debug.traceback()) end) end,n or p)
|
||||||
return os.spawn(function() computer.pushSignal("process_finished", os.pid(), pcall(loadfile(p), table.unpack(tA))) end,n or p)
|
|
||||||
end
|
end
|
||||||
function require(f) -- searches for a library with name *f* and returns what the library returns, if possible
|
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"
|
local lib = os.getenv("LIB") or "/boot/lib"
|
||||||
|
@ -19,17 +19,17 @@ end
|
|||||||
function os.kill(pid) -- removes process *pid* from the task list
|
function os.kill(pid) -- removes process *pid* from the task list
|
||||||
tTasks[pid] = nil
|
tTasks[pid] = nil
|
||||||
end
|
end
|
||||||
function os.pid() -- returns the current process' PID
|
function os.pid()
|
||||||
return cPid
|
return cPid
|
||||||
end
|
end
|
||||||
function os.tasks() -- returns a table of process IDs
|
function os.tasks()
|
||||||
local rt = {}
|
local rt = {}
|
||||||
for k,v in pairs(tTasks) do
|
for k,v in pairs(tTasks) do
|
||||||
rt[#rt+1] = k
|
rt[#rt+1] = k
|
||||||
end
|
end
|
||||||
return rt
|
return rt
|
||||||
end
|
end
|
||||||
function os.taskInfo(pid) -- returns info on process *pid* as a table with name and parent values
|
function os.taskInfo(pid)
|
||||||
pid = pid or os.pid()
|
pid = pid or os.pid()
|
||||||
if not tTasks[pid] then return false end
|
if not tTasks[pid] then return false end
|
||||||
return {name=tTasks[pid].n,parent=tTasks[pid].P}
|
return {name=tTasks[pid].n,parent=tTasks[pid].P}
|
||||||
|
Loading…
Reference in New Issue
Block a user