mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-01-21 06:26:55 +00:00
Make io handles opaque to the docs
Yep, this is kinda gross. But also a nice refactor
This commit is contained in:
parent
0b65d56ab0
commit
88f41314c7
@ -173,27 +173,25 @@ handleMetatable = {
|
||||
},
|
||||
}
|
||||
|
||||
local defaultInput = setmetatable({
|
||||
_handle = { readLine = _G.read },
|
||||
}, handleMetatable)
|
||||
local function make_file(handle)
|
||||
return setmetatable({ _handle = handle }, handleMetatable)
|
||||
end
|
||||
|
||||
local defaultOutput = setmetatable({
|
||||
_handle = { write = _G.write },
|
||||
}, handleMetatable)
|
||||
local defaultInput = make_file({ readLine = _G.read })
|
||||
|
||||
local defaultError = setmetatable({
|
||||
_handle = {
|
||||
write = function(...)
|
||||
local oldColour
|
||||
if term.isColour() then
|
||||
oldColour = term.getTextColour()
|
||||
term.setTextColour(colors.red)
|
||||
end
|
||||
_G.write(...)
|
||||
if term.isColour() then term.setTextColour(oldColour) end
|
||||
end,
|
||||
},
|
||||
}, handleMetatable)
|
||||
local defaultOutput = make_file({ write = _G.write })
|
||||
|
||||
local defaultError = make_file({
|
||||
write = function(...)
|
||||
local oldColour
|
||||
if term.isColour() then
|
||||
oldColour = term.getTextColour()
|
||||
term.setTextColour(colors.red)
|
||||
end
|
||||
_G.write(...)
|
||||
if term.isColour() then term.setTextColour(oldColour) end
|
||||
end,
|
||||
})
|
||||
|
||||
local currentInput = defaultInput
|
||||
local currentOutput = defaultOutput
|
||||
@ -316,7 +314,7 @@ function open(filename, mode)
|
||||
local file, err = fs.open(filename, sMode)
|
||||
if not file then return nil, err end
|
||||
|
||||
return setmetatable({ _handle = file }, handleMetatable)
|
||||
return make_file(file)
|
||||
end
|
||||
|
||||
--- Get or set the current output file.
|
||||
|
Loading…
Reference in New Issue
Block a user