|
|
|
@ -9,7 +9,7 @@ given <https://ocdoc.cil.li/tutorial:custom_oses#what_s_available>:
|
|
|
|
|
]]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
envBase._OSVERSION = 'kitn 0.2.0-beta.1' --prefer [openloader, openos] "$name $ver" over plan9k "$name/$ver"
|
|
|
|
|
envBase._OSVERSION = 'kitn 0.2.0-beta.2' --prefer [openloader, openos] "$name $ver" over plan9k "$name/$ver"
|
|
|
|
|
envBase.kitn = {}
|
|
|
|
|
envBase._G, envBase.load = nil
|
|
|
|
|
|
|
|
|
@ -100,7 +100,11 @@ function fillEnv(proc, uenv)
|
|
|
|
|
checkArg(1, filename, 'string', 'nil')
|
|
|
|
|
error('TODO io.lines') --iff we open a file, we need to close it
|
|
|
|
|
end,
|
|
|
|
|
open = function(filename, mode) return openPath(mode, bootfs, filename) end,
|
|
|
|
|
open = function(filename, mode)
|
|
|
|
|
checkArg(1, filename, 'string')
|
|
|
|
|
checkArg(2, filename, 'string', 'nil')
|
|
|
|
|
return openPath(mode, bootfs, filename)
|
|
|
|
|
end,
|
|
|
|
|
output = function(file)
|
|
|
|
|
local t = checkArgEx(1, file, 'string', 'table', 'nil')
|
|
|
|
|
if t ~= nil then
|
|
|
|
@ -111,8 +115,14 @@ function fillEnv(proc, uenv)
|
|
|
|
|
--popen is unimplemented because we don't have a notion of a shell
|
|
|
|
|
read = function(...) return uio.stdin:read(...) end,
|
|
|
|
|
tmpfile = function()
|
|
|
|
|
--use math.random() to pick a filename on computer.tmpAddress() that doesn't exist yet and create it
|
|
|
|
|
error('TODO io.tmpfile') --file is deleted on process exit, requires atExit mechanism
|
|
|
|
|
local deadline = uptime() + 1 --give up after 1s instead of potentially infinitely looping
|
|
|
|
|
local filename
|
|
|
|
|
repeat
|
|
|
|
|
filename = format('tmp.%08x', random(0, 0x7fffffff))
|
|
|
|
|
if invoke(tmpfs, 'exists', filename) then filename = nil end
|
|
|
|
|
until filename or uptime() >= deadline
|
|
|
|
|
assert(filename, 'failed to allocate tmpfile')
|
|
|
|
|
return openPath('w+', tmpfs, filename) --TODO close at exit
|
|
|
|
|
end,
|
|
|
|
|
type = function(obj)
|
|
|
|
|
local file, opened = isFile(obj)
|
|
|
|
@ -128,6 +138,14 @@ function fillEnv(proc, uenv)
|
|
|
|
|
}
|
|
|
|
|
uenv.io = uio
|
|
|
|
|
|
|
|
|
|
function uenv.print(...)
|
|
|
|
|
local parts = pack(...)
|
|
|
|
|
for i = 1, parts.n do
|
|
|
|
|
parts[i] = tostring(parts[i])
|
|
|
|
|
end
|
|
|
|
|
assert(uenv.io.write(concat(parts, '\t', 1, parts.n), '\n'))
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
--env will automatically mirror envBase.kitn here
|
|
|
|
|
local ukitn = uenv.kitn
|
|
|
|
@ -154,6 +172,18 @@ function fillEnv(proc, uenv)
|
|
|
|
|
--TODO return information for the current thread within the process too
|
|
|
|
|
return proc, nil
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--TODO map all filesystems into a single tree, then remove this method
|
|
|
|
|
function ukitn.openOn(address, path, mode)
|
|
|
|
|
checkArg(1, address, 'string')
|
|
|
|
|
checkArg(2, path, 'string')
|
|
|
|
|
checkArg(3, mode, 'string', 'nil')
|
|
|
|
|
local t, err = component_type(address)
|
|
|
|
|
if t ~= 'filesystem' then
|
|
|
|
|
return nil, err or 'component is not a filesystem'
|
|
|
|
|
end
|
|
|
|
|
return openPath(mode, address, path)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- vi: set ts=2:
|
|
|
|
|