Skip to content

Commit

Permalink
Merge pull request #460 from 0x501D/fix-gh-459
Browse files Browse the repository at this point in the history
popen: support nil in second argument
  • Loading branch information
yuin committed Oct 14, 2023
2 parents 2b3f02d + 1543e9d commit 018eaa0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
11 changes: 11 additions & 0 deletions _glua-tests/issues.lua
Expand Up @@ -457,3 +457,14 @@ function test()
assert(c == 1)
assert(type(c) == "number")
end

-- issue #459
function test()
local a, b = io.popen("ls", nil)
assert(a)
assert(b == nil)
local a, b = io.popen("ls", nil, nil)
assert(a)
assert(b == nil)
end
test()
3 changes: 3 additions & 0 deletions iolib.go
Expand Up @@ -658,6 +658,9 @@ func ioPopen(L *LState) int {
cmd := L.CheckString(1)
if L.GetTop() == 1 {
L.Push(LString("r"))
} else if L.GetTop() > 1 && (L.Get(2)).Type() == LTNil {
L.SetTop(1)
L.Push(LString("r"))
}
var file *LUserData
var err error
Expand Down

0 comments on commit 018eaa0

Please sign in to comment.