Unverified Commit cef994f2 authored by Simon Esposito's avatar Simon Esposito Committed by GitHub
Browse files

Update gopher-lua (#862)

parent 9b5caf38
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -870,6 +870,7 @@ Libraries for GopherLua
- `gluaperiphery <https://github.com/BixData/gluaperiphery>`_ : A periphery library for the GopherLua VM (GPIO, SPI, I2C, MMIO, and Serial peripheral I/O for Linux).
- `glua-async <https://github.com/CuberL/glua-async>`_ : An async/await implement for gopher-lua.
- `gopherlua-debugger <https://github.com/edolphin-ydf/gopherlua-debugger>`_ : A debugger for gopher-lua
- `gluamahonia <https://github.com/super1207/gluamahonia>`_ : An encoding converter for gopher-lua
----------------------------------------------------------------
Donation
----------------------------------------------------------------
+62 −6
Original line number Diff line number Diff line
@@ -331,3 +331,59 @@ function test()
	assert(os.time(t1) == os.time(t6))
end
test()

--issue #331
function test()
	local select_a = function()
		return select(3, "1")
	end
	assert(true == pcall(select_a))
	local select_b = function()
		return select(0)
	end
	assert(false == pcall(select_b))
	local select_c = function()
		return select(1/9)
	end
	assert(false == pcall(select_c))
	local select_d = function()
		return select(1, "a")
	end
	assert("a" == select_d())
	local select_e = function()
		return select(3, "a", "b", "c")
	end
	assert("c" == select_e())
	local select_f = function()
		return select(0)(select(1/9))
	end
	assert(false == pcall(select_f))
end
test()

-- issue #363
-- Any expression enclosed in parentheses always results in only one value.
function test()
    function ret2(a, b)
        return a, b
    end
    function enclosed_ret()
        return (ret2(1, 2))
    end
    local a,b = enclosed_ret()
    assert(a == 1 and b == nil)

    function enclosed_vararg_ret(...)
        return (...)
    end
    local a,b,c=enclosed_vararg_ret(1, 2, 3)
    assert(a == 1 and b == nil and c == nil)

    function enclosed_vararg_assign(...)
        local a,b,c = (...)
        return a,b,c
    end
    local a,b,c=enclosed_vararg_assign(1, 2, 3)
    assert(a == 1 and b == nil and c == nil)
end
test()
+1 −1
Original line number Diff line number Diff line
@@ -415,7 +415,7 @@ func init() {
					if ret.Type() == LTNumber {
						reg.SetNumber(RA, ret.(LNumber))
					} else {
						reg.SetNumber(RA, LNumber(0))
						reg.Set(RA, ret)
					}
				} else if lv.Type() == LTTable {
					reg.SetNumber(RA, LNumber(lv.(*LTable).Len()))
+1 −0
Original line number Diff line number Diff line
@@ -52,6 +52,7 @@ type StringExpr struct {

type Comma3Expr struct {
	ExprBase
	AdjustRet bool
}

type IdentExpr struct {
+7 −3
Original line number Diff line number Diff line
@@ -115,7 +115,7 @@ func isVarArgReturnExpr(expr ast.Expr) bool {
	case *ast.FuncCallExpr:
		return !ex.AdjustRet
	case *ast.Comma3Expr:
		return true
		return !ex.AdjustRet
	}
	return false
}
@@ -724,8 +724,12 @@ func compileReturnStmt(context *funcContext, stmt *ast.ReturnStmt) { // {{{
				return
			}
		case *ast.FuncCallExpr:
			if ex.AdjustRet { // return (func())
				reg += compileExpr(context, reg, ex, ecnone(0))
			} else {
				reg += compileExpr(context, reg, ex, ecnone(-2))
				code.SetOpCode(code.LastPC(), OP_TAILCALL)
			}
			code.AddABC(OP_RETURN, a, 0, 0, sline(stmt))
			return
		}
Loading