mirror of
https://git.shadowkat.net/izaya/OC-PsychOS2.git
synced 2024-11-21 19:44:21 -05:00
implement component.get for convenience
This commit is contained in:
parent
7fa61e115e
commit
36a73b892a
@ -1,3 +1,7 @@
|
|||||||
local preproc = require "preproc"
|
local preproc = require "preproc"
|
||||||
--local tA = {...}
|
--local tA = {...}
|
||||||
|
function preproc.directives.includelib(file,name)
|
||||||
|
return string.format("package.loaded.%s = (function()\n%s\nend)()", name, preproc.preproc(file))
|
||||||
|
end
|
||||||
|
|
||||||
preproc(...)
|
preproc(...)
|
||||||
|
@ -1 +1 @@
|
|||||||
{enabled={"getty","minitel"}}
|
{enabled={"getty","minitel","fsmanager","rtfsman","partman"}}
|
||||||
|
8
module/component-get.lua
Normal file
8
module/component-get.lua
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
function component.get(addr, ctype)
|
||||||
|
for c in component.list(ctype, true) do
|
||||||
|
if c:sub(1, addr:len()) == addr then
|
||||||
|
return c
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return nil, "no such component"
|
||||||
|
end
|
@ -6,6 +6,7 @@
|
|||||||
--#include "module/io.lua"
|
--#include "module/io.lua"
|
||||||
--#include "module/devfs.lua"
|
--#include "module/devfs.lua"
|
||||||
--#include "module/devfs/syslog.lua"
|
--#include "module/devfs/syslog.lua"
|
||||||
|
--#include "module/component-get.lua"
|
||||||
--#include "module/loadfile.lua"
|
--#include "module/loadfile.lua"
|
||||||
|
|
||||||
_OSVERSION=_OSVERSION or "PsychOS 2"
|
_OSVERSION=_OSVERSION or "PsychOS 2"
|
||||||
|
@ -32,8 +32,9 @@ function io.write(...) -- Writes its arguments to the default output stream.
|
|||||||
io.output():write(...)
|
io.output():write(...)
|
||||||
end
|
end
|
||||||
|
|
||||||
function print(...) -- Writes each argument to the default output stream, separated by newlines.
|
function print(...) -- Writes each argument to the default output stream, separated by space.
|
||||||
for k,v in ipairs({...}) do
|
for k,v in ipairs({...}) do
|
||||||
io.write(tostring(v).."\n")
|
io.write(tostring(v).." ")
|
||||||
end
|
end
|
||||||
|
io.write("\n")
|
||||||
end
|
end
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
do
|
do
|
||||||
local tTasks,nPid,nTimeout,cPid = {},1,0.25,0 -- table of tasks, next process ID, event timeout, current PID
|
local tTasks,nPid,nTimeout,cPid = {},1,0.25,0 -- table of tasks, next process ID, default event timeout, current PID
|
||||||
function os.spawn(f,n) -- function string -- number -- creates a process from function *f* with name *n*
|
function os.spawn(f,n) -- function string -- number -- creates a process from function *f* with name *n*
|
||||||
tTasks[nPid] = {
|
tTasks[nPid] = {
|
||||||
c=coroutine.create(function()
|
c=coroutine.create(function()
|
||||||
@ -14,6 +14,7 @@ function os.spawn(f,n) -- function string -- number -- creates a process from fu
|
|||||||
P=cPid, -- parent PID
|
P=cPid, -- parent PID
|
||||||
t=0, -- CPU time
|
t=0, -- CPU time
|
||||||
T=0, -- total uptime
|
T=0, -- total uptime
|
||||||
|
E=nTimeout, -- event timeout
|
||||||
e={} -- environment variables
|
e={} -- environment variables
|
||||||
}
|
}
|
||||||
if tTasks[cPid] then
|
if tTasks[cPid] then
|
||||||
@ -44,18 +45,22 @@ function os.taskInfo(pid) -- number -- table -- returns info on process *pid* as
|
|||||||
end
|
end
|
||||||
function os.sched() -- the actual scheduler function
|
function os.sched() -- the actual scheduler function
|
||||||
os.sched = nil
|
os.sched = nil
|
||||||
|
local sTimeout = nTimeout
|
||||||
while #tTasks > 0 do
|
while #tTasks > 0 do
|
||||||
local tEv = {computer.pullSignal(nTimeout)}
|
local tEv = {computer.pullSignal(sTimeout)}
|
||||||
|
sTimeout = nTimeout
|
||||||
for k,v in pairs(tTasks) do
|
for k,v in pairs(tTasks) do
|
||||||
if coroutine.status(v.c) ~= "dead" then
|
if coroutine.status(v.c) ~= "dead" then
|
||||||
cPid = k
|
cPid = k
|
||||||
local sT, sC = os.clock(), computer.uptime()
|
local sT, sC = os.clock(), computer.uptime()
|
||||||
coroutine.resume(v.c,table.unpack(tEv))
|
coroutine.resume(v.c,table.unpack(tEv))
|
||||||
v.t, v.T = v.t + os.clock() - sT, v.T + computer.uptime() - sC
|
v.t, v.T = v.t + os.clock() - sT, v.T + computer.uptime() - sC
|
||||||
|
sTimeout=math.min(sTimeout, v.E)
|
||||||
else
|
else
|
||||||
tTasks[k] = nil
|
tTasks[k] = nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
sTimeout = nTimeout
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
function os.setenv(k,v) -- set's the current process' environment variable *k* to *v*, which is passed to children
|
function os.setenv(k,v) -- set's the current process' environment variable *k* to *v*, which is passed to children
|
||||||
@ -69,13 +74,11 @@ function os.getenv(k) -- gets a process' *k* environment variable
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
function os.getTimeout()
|
function os.getTimeout()
|
||||||
return nTimeout
|
return tTasks[cPid].E
|
||||||
end
|
end
|
||||||
function os.setTimeout(n)
|
function os.setTimeout(n,pid)
|
||||||
if type(n) == "number" and n >= 0 then
|
assert(type(n) == "number" and n >= 0)
|
||||||
nTimeout = n
|
tTasks[pid or cPid].E = n
|
||||||
return true
|
return true
|
||||||
end
|
|
||||||
return false
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
--#include "module/ocelot-debug.lua"
|
||||||
do
|
do
|
||||||
syslog = {}
|
syslog = {}
|
||||||
syslog.emergency = 0
|
syslog.emergency = 0
|
||||||
|
@ -8,16 +8,17 @@ local function mount(addr)
|
|||||||
local w,r = fs.mount(dest,component.proxy(addr))
|
local w,r = fs.mount(dest,component.proxy(addr))
|
||||||
if not w then
|
if not w then
|
||||||
syslog("Failed to mount: "..r)
|
syslog("Failed to mount: "..r)
|
||||||
|
return false
|
||||||
end
|
end
|
||||||
fsmanager.filesystems[addr] = dest
|
fsmanager.filesystems[addr] = dest
|
||||||
end
|
end
|
||||||
for addr, _ in component.list("filesystem") do
|
|
||||||
mount(addr)
|
|
||||||
end
|
|
||||||
|
|
||||||
function fsmanager.start()
|
function fsmanager.start()
|
||||||
run = true
|
run = true
|
||||||
return os.spawn(function()
|
return os.spawn(function()
|
||||||
|
for addr, _ in component.list("filesystem") do
|
||||||
|
mount(addr)
|
||||||
|
end
|
||||||
while run do
|
while run do
|
||||||
local tE = {coroutine.yield()}
|
local tE = {coroutine.yield()}
|
||||||
if tE[1] == "component_added" and tE[3] == "filesystem" then
|
if tE[1] == "component_added" and tE[3] == "filesystem" then
|
||||||
@ -25,6 +26,7 @@ function fsmanager.start()
|
|||||||
elseif tE[1] == "component_removed" and fsmanager.filesystems[tE[2]] and tE[3] == "filesystem" then
|
elseif tE[1] == "component_removed" and fsmanager.filesystems[tE[2]] and tE[3] == "filesystem" then
|
||||||
syslog("Unmounting "..tE[2].." from "..fsmanager.filesystems[tE[2]])
|
syslog("Unmounting "..tE[2].." from "..fsmanager.filesystems[tE[2]])
|
||||||
fs.umount(fsmanager.filesystems[tE[2]])
|
fs.umount(fsmanager.filesystems[tE[2]])
|
||||||
|
fsmanager.filesystems[tE[2]] = nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end,"fsmanager")
|
end,"fsmanager")
|
||||||
|
Loading…
Reference in New Issue
Block a user