Repository: yuin/gopher-lua (go)

Issue:
different behavior in io.popen function
In the C implementation of the Lua interpreter, in the io.popen function the second argument can be nil:

Lua 5.1.5  Copyright (C) 1994-2012 Lua.org, PUC-Rio:
```
> x,y = io.popen("ls", nil)
> assert(x)
> assert(y == nil)
> 
```

Gopher lua throws an exception.
gopher-lua (current master):
```
bad argument #2 to popen (string expected, got nil)
```
[affected public project](https://github.com/luarocks/luarocks/blob/bb9d7ed38a092dde2b27e2adc7b386272f2890ee/src/luarocks/fs.lua#L33)


Pull request description:
popen: support nil in second argument
In the C implementation of the Lua interpreter,
in the io.popen function the second argument can be nil:

Lua 5.1.5 Copyright (C) 1994-2012 Lua.org, PUC-Rio:

> x,y = io.popen("ls", nil)
> assert(x)
> assert(y == nil)
>

Gopher lua throws an exception:
bad argument #2 to popen (string expected, got nil)

Closes #459

Patch:
diff --git a/iolib.go b/iolib.go
index b59e82b..3f5f295 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


Test patch:
diff --git a/_glua-tests/issues.lua b/_glua-tests/issues.lua
index 514d0b7..aafb5d7 100644
--- a/_glua-tests/issues.lua
+++ b/_glua-tests/issues.lua
@@ -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()