Skip to content

Commit 2348fd0

Browse files
authored
Merge pull request #456 from 0x501D/gh-455-fix-read
iolib: fix different behavior in read function
2 parents da9f439 + 5b5b27f commit 2348fd0

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

_glua-tests/issues.lua

+10
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,16 @@ function test()
470470
end
471471
test()
472472

473+
-- issue #455
474+
function test()
475+
local path = "."
476+
local fd, _, code = io.open(path, "r")
477+
assert(fd ~= nil)
478+
local _, _, ecode = fd:read(1)
479+
assert(ecode == 1)
480+
end
481+
test()
482+
473483
-- issue #459
474484
function test()
475485
local a, b = io.popen("ls", nil)

iolib.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -404,10 +404,10 @@ normalreturn:
404404
return L.GetTop() - top
405405

406406
errreturn:
407-
L.RaiseError(err.Error())
408-
//L.Push(LNil)
409-
//L.Push(LString(err.Error()))
410-
return 2
407+
L.Push(LNil)
408+
L.Push(LString(err.Error()))
409+
L.Push(LNumber(1)) // C-Lua compatibility: Original Lua pushes errno to the stack
410+
return 3
411411
}
412412

413413
var fileSeekOptions = []string{"set", "cur", "end"}

0 commit comments

Comments
 (0)