mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-01-21 22:46:57 +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({
|
local function make_file(handle)
|
||||||
_handle = { readLine = _G.read },
|
return setmetatable({ _handle = handle }, handleMetatable)
|
||||||
}, handleMetatable)
|
end
|
||||||
|
|
||||||
local defaultOutput = setmetatable({
|
local defaultInput = make_file({ readLine = _G.read })
|
||||||
_handle = { write = _G.write },
|
|
||||||
}, handleMetatable)
|
|
||||||
|
|
||||||
local defaultError = setmetatable({
|
local defaultOutput = make_file({ write = _G.write })
|
||||||
_handle = {
|
|
||||||
write = function(...)
|
local defaultError = make_file({
|
||||||
local oldColour
|
write = function(...)
|
||||||
if term.isColour() then
|
local oldColour
|
||||||
oldColour = term.getTextColour()
|
if term.isColour() then
|
||||||
term.setTextColour(colors.red)
|
oldColour = term.getTextColour()
|
||||||
end
|
term.setTextColour(colors.red)
|
||||||
_G.write(...)
|
end
|
||||||
if term.isColour() then term.setTextColour(oldColour) end
|
_G.write(...)
|
||||||
end,
|
if term.isColour() then term.setTextColour(oldColour) end
|
||||||
},
|
end,
|
||||||
}, handleMetatable)
|
})
|
||||||
|
|
||||||
local currentInput = defaultInput
|
local currentInput = defaultInput
|
||||||
local currentOutput = defaultOutput
|
local currentOutput = defaultOutput
|
||||||
@ -316,7 +314,7 @@ function open(filename, mode)
|
|||||||
local file, err = fs.open(filename, sMode)
|
local file, err = fs.open(filename, sMode)
|
||||||
if not file then return nil, err end
|
if not file then return nil, err end
|
||||||
|
|
||||||
return setmetatable({ _handle = file }, handleMetatable)
|
return make_file(file)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Get or set the current output file.
|
--- Get or set the current output file.
|
||||||
|
Loading…
Reference in New Issue
Block a user