Skip to content

Commit

Permalink
Merge pull request #456 from 0x501D/gh-455-fix-read
Browse files Browse the repository at this point in the history
iolib: fix different behavior in read function
  • Loading branch information
yuin authored Dec 12, 2023
2 parents da9f439 + 5b5b27f commit 2348fd0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
10 changes: 10 additions & 0 deletions _glua-tests/issues.lua
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,16 @@ function test()
end
test()

-- issue #455
function test()
local path = "."
local fd, _, code = io.open(path, "r")
assert(fd ~= nil)
local _, _, ecode = fd:read(1)
assert(ecode == 1)
end
test()

-- issue #459
function test()
local a, b = io.popen("ls", nil)
Expand Down
8 changes: 4 additions & 4 deletions iolib.go
Original file line number Diff line number Diff line change
Expand Up @@ -404,10 +404,10 @@ normalreturn:
return L.GetTop() - top

errreturn:
L.RaiseError(err.Error())
//L.Push(LNil)
//L.Push(LString(err.Error()))
return 2
L.Push(LNil)
L.Push(LString(err.Error()))
L.Push(LNumber(1)) // C-Lua compatibility: Original Lua pushes errno to the stack
return 3
}

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

0 comments on commit 2348fd0

Please sign in to comment.