|
|
@ -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.kitn = {}
|
|
|
|
envBase._G, envBase.load = nil
|
|
|
|
envBase._G, envBase.load = nil
|
|
|
|
|
|
|
|
|
|
|
@ -100,7 +100,11 @@ function fillEnv(proc, uenv)
|
|
|
|
checkArg(1, filename, 'string', 'nil')
|
|
|
|
checkArg(1, filename, 'string', 'nil')
|
|
|
|
error('TODO io.lines') --iff we open a file, we need to close it
|
|
|
|
error('TODO io.lines') --iff we open a file, we need to close it
|
|
|
|
end,
|
|
|
|
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)
|
|
|
|
output = function(file)
|
|
|
|
local t = checkArgEx(1, file, 'string', 'table', 'nil')
|
|
|
|
local t = checkArgEx(1, file, 'string', 'table', 'nil')
|
|
|
|
if t ~= nil then
|
|
|
|
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
|
|
|
|
--popen is unimplemented because we don't have a notion of a shell
|
|
|
|
read = function(...) return uio.stdin:read(...) end,
|
|
|
|
read = function(...) return uio.stdin:read(...) end,
|
|
|
|
tmpfile = function()
|
|
|
|
tmpfile = function()
|
|
|
|
--use math.random() to pick a filename on computer.tmpAddress() that doesn't exist yet and create it
|
|
|
|
local deadline = uptime() + 1 --give up after 1s instead of potentially infinitely looping
|
|
|
|
error('TODO io.tmpfile') --file is deleted on process exit, requires atExit mechanism
|
|
|
|
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,
|
|
|
|
end,
|
|
|
|
type = function(obj)
|
|
|
|
type = function(obj)
|
|
|
|
local file, opened = isFile(obj)
|
|
|
|
local file, opened = isFile(obj)
|
|
|
@ -128,6 +138,14 @@ function fillEnv(proc, uenv)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
uenv.io = uio
|
|
|
|
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
|
|
|
|
--env will automatically mirror envBase.kitn here
|
|
|
|
local ukitn = uenv.kitn
|
|
|
|
local ukitn = uenv.kitn
|
|
|
@ -154,6 +172,18 @@ function fillEnv(proc, uenv)
|
|
|
|
--TODO return information for the current thread within the process too
|
|
|
|
--TODO return information for the current thread within the process too
|
|
|
|
return proc, nil
|
|
|
|
return proc, nil
|
|
|
|
end
|
|
|
|
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
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
-- vi: set ts=2:
|
|
|
|
-- vi: set ts=2:
|
|
|
|