I've been writing up a bios for my drone with one major snag: text output will be a nightmare. I can't think of a "clean" way to implement a way of searching for a new line, since every space on the monitor technically has the observed text value of "" (when I added an if function to see if gpu.get returned "", it pulled through and outputted gpu.set(1,2). the previously non-occupied line had a value of "" rather than nil. also, type() is saying the type of the unoccupied space was a string).
First I took a peek at the term API, since I couldn't figure out where print was defined in openOS.
function term.write(value,wrap)
local stdout = io.output()
local stream = stdout and stdout.stream
local previous_wrap = stream.wrap
stream.wrap = wrap == nil and true or wrap
stdout:write(value)
stdout:flush()
stream.wrap = previous_wrap
end
Surprise surprise, it relies on the IO library, which is a part of the filesystem library. Naturally, I took a look at the IO library's output function.
function io.input(file)
return io.stream(0, file, 'r')
end
function io.output(file)
return io.stream(1, file,'w')
end
function io.error(file)
return io.stream(2, file,'w')
end
It simply returns io.stream, so that's where I look next.
function io.stream(fd,file,mode)
checkArg(1,fd,'number')
assert(fd>=0,'fd must be >= 0. 0 is input, 1 is stdout, 2 is stderr')
if file then
if type(file) == "string" then
local result, reason = io.open(file, mode)
if not result then
error(reason, 2)
end
file = result
elseif not io.type(file) then
error("bad argument #1 (string or file expected, got " .. type(file) .. ")", 2)
end
require("process").info().data.io[fd] = file
end
return require("process").info().data.io[fd]
end
This is what confuses me. io.output is passing file. Not a string, not a file path, not anything. Just file. What is this 'file' and what does it have to do with text output? Why are so many basic lua functionalities missing without openOS?