Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

popen: support nil in second argument #460

Merged
merged 1 commit into from
Oct 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions _glua-tests/issues.lua
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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