Skip to content

Commit bdf6294

Browse files
committed
Fix io.read not working
Also fix LuaRocks repoistory URL.
1 parent 79d6d54 commit bdf6294

File tree

2 files changed

+20
-15
lines changed

2 files changed

+20
-15
lines changed

bsrocks/env/io.lua

+19-14
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,20 @@ local fileMeta = {
4949
for i = 1, n do
5050
local format = data[i] or "l"
5151
format = checkType(format, "string"):gsub("%*", ""):sub(1, 1) -- "*" is not needed after Lua 5.1 - lets be friendly
52+
53+
local res, msg
5254
if format == "l" then
53-
returns[#returns + 1] = handle.readLine()
55+
res, msg = handle.readLine()
5456
elseif format == "a" then
55-
returns[#returns + 1] = handle.readAll()
57+
res, msg = handle.readAll()
5658
elseif format == "r" then
57-
returns[#returns + 1] = handle.read() -- Binary only
59+
res, msg = handle.read() -- Binary only
5860
else
5961
error("(invalid format", 2)
6062
end
63+
64+
if not res then return res, msg end
65+
returns[#returns + 1] = res
6166
end
6267

6368
return unpack(returns)
@@ -109,24 +114,24 @@ return function(env)
109114
end
110115

111116
do -- Setup standard outputs
112-
local function void() end
113-
local function close() return nil, "cannot close standard file" end
114-
local function read() return nil, "bad file descriptor" end
117+
local function voidStub() end
118+
local function closeStub() return nil, "cannot close standard file" end
119+
local function readStub() return nil, "bad file descriptor" end
115120

116121
env.stdout = setmetatable({
117122
__handle = {
118-
close = close,
119-
flush = void,
120-
read = read, readLine = read, readAll = read,
123+
close = closeStub,
124+
flush = voidStub,
125+
read = readStub, readLine = readStub, readAll = readStub,
121126
write = function(arg) ansi.write(arg) end,
122127
}
123128
}, fileMeta)
124129

125130
env.stderr = setmetatable({
126131
__handle = {
127-
close = close,
128-
flush = void,
129-
read = read, readLine = read, readAll = read,
132+
close = closeStub,
133+
flush = voidStub,
134+
read = readStub, readLine = readStub, readAll = readStub,
130135
write = function(arg)
131136
local c = term.isColor()
132137
if c then term.setTextColor(colors.red) end
@@ -138,8 +143,8 @@ return function(env)
138143

139144
env.stdin = setmetatable({
140145
__handle = {
141-
close = close,
142-
flush = void,
146+
close = closeStub,
147+
flush = voidStub,
143148
read = function() return string.byte(os.pullEvent("char")) end,
144149
readLine = read, readAll = read,
145150
write = function() error("cannot write to input", 3) end,

bsrocks/lib/settings.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ local currentSettings = {
33
installDirectory = "/rocks",
44
servers = {
55
'https://raw.githubusercontent.com/SquidDev-CC/Blue-Shiny-Rocks/rocks/',
6-
'http://luarocks.org/repositories/rocks/',
6+
'http://luarocks.org/',
77
},
88
tries = 3,
99
existing = {

0 commit comments

Comments
 (0)