bugfixes in coroutines, io.{in,out}put, and checkArgEx

coroutine.resume: the `false` that distinguishes os yields from coroutine.yield() was unintentionally passed back to the caller, and the status of the coroutine wasn't
io.input, io.output: incorrectly testing if the argument is nil caused `io.output()` to set stdout to nil instead of returning it unchanged
checkArgEx: incorrectly bailed early after the first instance of 'integer', 'float', or 'file' that didn't match
main
cinder 6 months ago
parent f0ed0822b8
commit 2fad8db849

@ -8,7 +8,7 @@ local tmpfs = computer.tmpAddress()
--prefix 'k' (for kernel) on any functions userspace will also have a version of to ensure kernelspace
--function usage is intentional (ie prevent accidentally using the kernel's `load` in a userspace `loadfile`)
local envBase = _G --used for creating process environments
local assert, checkArg, error, kload, ipairs, next, pairs, rawequal, rawset, setmetatable, tostring, type = assert, checkArg, error, load, ipairs, next, pairs, rawequal, rawset, setmetatable, tostring, type
local assert, checkArg, error, kload, ipairs, next, pairs, rawequal, rawset, select, setmetatable, tostring, type = assert, checkArg, error, load, ipairs, next, pairs, rawequal, rawset, select, setmetatable, tostring, type
local invoke, component_type = component.invoke, component.type
local kpullSignal, shutdown, uptime = computer.pullSignal, computer.shutdown, computer.uptime
local co_create, co_status, kresume, kyield = coroutine.create, coroutine.status, coroutine.resume, coroutine.yield
@ -38,7 +38,7 @@ local checkArgEx
do
-- tail-recursive varargs part of checkArgEx
local function check(val, t, want, ...)
if t == want then
if want == t then
return want
elseif want == 'integer' or want == 'float' then
if math_type(val) == want then
@ -50,9 +50,8 @@ do
end
elseif not want then
return nil
else
return check(val, t, ...)
end
return check(val, t, ...)
end
function checkArgEx(i, val, ...)

@ -9,7 +9,7 @@ given <https://ocdoc.cil.li/tutorial:custom_oses#what_s_available>:
]]
envBase._OSVERSION = 'kitn 0.2.0-beta.2' --prefer [openloader, openos] "$name $ver" over plan9k "$name/$ver"
envBase._OSVERSION = 'kitn 0.2.0-beta.3' --prefer [openloader, openos] "$name $ver" over plan9k "$name/$ver"
envBase.kitn = {}
envBase._G, envBase.load = nil
@ -36,7 +36,7 @@ do
--yield to the scheduler, pass the results (ie signal) back to `co`, then repeat for `co`'s next yield
return forwardYield(co, kresume(co, kyield(...)))
else --`co` called coroutine.yield(), so return its values to the waiting coroutine.resume()
return ...
return ok, select(2, ...)
end
end
end
@ -91,7 +91,7 @@ function fillEnv(proc, uenv)
flush = function() return uio.stdout:flush() end,
input = function(file)
local t = checkArgEx(1, file, 'string', 'table', 'nil')
if t ~= 'nil' then
if file then
uio.stdin = (t == 'string' and assert(uio.open(file, 'r')) or file)
end
return uio.stdin
@ -107,7 +107,7 @@ function fillEnv(proc, uenv)
end,
output = function(file)
local t = checkArgEx(1, file, 'string', 'table', 'nil')
if t ~= nil then
if file then
uio.stdout = (t == 'string' and assert(uio.open(file, 'w')) or file)
end
return uio.stdout

Loading…
Cancel
Save