fixed a bug where for whatever reason io.read would return 0x0D (CR)

Former-commit-id: 769e2d3931472d14ce66cfef3a496a3913dc51be
This commit is contained in:
Song Minjae
2017-03-31 17:25:31 +09:00
parent 315713efe1
commit 2e94490905

View File

@@ -88,21 +88,25 @@ end
io.read = function(option)
if io.__openfile__ == "stdin" then
local input = ""
local inkey = null -- local variable init REQUIRED!
local input = {}
-- RETURN not hit
while inkey ~= 13 do
inkey = machine.__readFromStdin()
if inkey > 0 then
while true do
local inkey = machine.__readFromStdin()
if inkey == 13 or inkey == 10 then
break
elseif inkey == 8 or inkey == 127 then
io.write(string.char(inkey))
input = input..string.char(inkey)
table.remove(input)
elseif inkey > 0 then
io.write(string.char(inkey))
table.insert(input, string.char(inkey))
end
end
-- RETURN finally hit
io.write("\n")
return input
return table.concat(input)
end
function _readAll()