diff --git a/_glua-tests/issues.lua b/_glua-tests/issues.lua index 0bb77bcd..65a2c7f4 100644 --- a/_glua-tests/issues.lua +++ b/_glua-tests/issues.lua @@ -468,4 +468,15 @@ function test() end) assert(not ok) end -test() \ No newline at end of file +test() + +-- 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() diff --git a/iolib.go b/iolib.go index b59e82b2..3f5f295c 100644 --- a/iolib.go +++ b/iolib.go @@ -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