Skip to content

Commit 0a199db

Browse files
committed
Upgrade gopher-lua to v1.1.1
1 parent 24c07ac commit 0a199db

File tree

21 files changed

+1277
-244
lines changed

21 files changed

+1277
-244
lines changed

internal/gopher-lua/README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,7 @@ Libraries for GopherLua
869869
- `gluasql <https://github.com/tengattack/gluasql>`_ : A native Go implementation of SQL client for the GopherLua VM.
870870
- `purr <https://github.com/leyafo/purr>`_ : A http mock testing tool.
871871
- `vadv/gopher-lua-libs <https://github.com/vadv/gopher-lua-libs>`_ : Some usefull libraries for GopherLua VM.
872-
- `gluaperiphery <https://github.com/BixData/gluaperiphery>`_ : A periphery library for the GopherLua VM (GPIO, SPI, I2C, MMIO, and Serial peripheral I/O for Linux).
872+
- `gluasocket <https://gitlab.com/megalithic-llc/gluasocket>`_ : A native Go implementation of LuaSocket for the GopherLua VM.
873873
- `glua-async <https://github.com/CuberL/glua-async>`_ : An async/await implement for gopher-lua.
874874
- `gopherlua-debugger <https://github.com/edolphin-ydf/gopherlua-debugger>`_ : A debugger for gopher-lua
875875
- `gluamahonia <https://github.com/super1207/gluamahonia>`_ : An encoding converter for gopher-lua

internal/gopher-lua/_glua-tests/goto.lua

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ local function foo ()
101101
::l4:: a[#a + 1] = 4; goto l6;
102102
::l5:: a[#a + 1] = 5; goto l4;
103103
::l6:: assert(a[1] == 3 and a[2] == 1 and a[3] == 2 and
104-
a[4] == 5 and a[5] == 4)
104+
a[4] == 5 and a[5] == 4)
105105
if not a[6] then a[6] = true; goto l3a end -- do it twice
106106
end
107107

@@ -115,10 +115,10 @@ end
115115
local function foo ()
116116
local a = {}
117117
do
118-
local i = 1
119-
local k = 0
120-
a[0] = function (y) k = y end
121-
::l1:: do
118+
local i = 1
119+
local k = 0
120+
a[0] = function (y) k = y end
121+
::l1:: do
122122
local x
123123
if i > 2 then goto l2 end
124124
a[i] = function (y) if y then x = y else return x + k end end

internal/gopher-lua/_glua-tests/issues.lua

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ local x = util.fn(
177177

178178
local s = [=[["a"]['b'][9] - ["a"]['b'][8] > ]=]
179179
local result = {}
180-
for i in s:gmatch([=[[[][^%s,]*[]]]=]) do
180+
for i in s:gmatch([=[[[][^%s,]*[]]]=]) do
181181
table.insert(result, i)
182182
end
183183
assert(result[1] == [=[["a"]['b'][9]]=])
@@ -231,7 +231,7 @@ end
231231
assert(test(nil) == nil)
232232

233233
-- issue 220
234-
function test()
234+
function test()
235235
function f(v)
236236
return v
237237
end
@@ -245,22 +245,22 @@ test()
245245
-- issue 222
246246
function test()
247247
local m = {n=2}
248-
248+
249249
function m:f1()
250250
return self:f3() >= self.n
251251
end
252-
252+
253253
function m:f2()
254254
local v1, v2, v3 = m:f1()
255255
assert(v1 == true)
256256
assert(v2 == nil)
257257
assert(v3 == nil)
258258
end
259-
259+
260260
function m:f3()
261261
return 3
262262
end
263-
263+
264264
m:f2()
265265
end
266266
test()
@@ -333,7 +333,6 @@ end
333333
test()
334334

335335
--issue #331
336-
--[[
337336
function test()
338337
local select_a = function()
339338
return select(3, "1")
@@ -361,7 +360,6 @@ function test()
361360
assert(false == pcall(select_f))
362361
end
363362
test()
364-
--]]
365363

366364
-- issue #363
367365
-- Any expression enclosed in parentheses always results in only one value.
@@ -459,3 +457,36 @@ function test()
459457
assert(c == 1)
460458
assert(type(c) == "number")
461459
end
460+
test()
461+
462+
-- issue #452
463+
function test()
464+
local ok, msg = pcall(function()
465+
local ok, msg = xpcall(function() error("fn") end, function(err) error("handler") end)
466+
assert(not ok and msg)
467+
error("expected to reach this.")
468+
end)
469+
assert(not ok)
470+
end
471+
test()
472+
473+
-- issue #455
474+
function test()
475+
local path = "."
476+
local fd, _, code = io.open(path, "r")
477+
assert(fd ~= nil)
478+
local _, _, ecode = fd:read(1)
479+
assert(ecode == 1)
480+
end
481+
test()
482+
483+
-- issue #459
484+
function test()
485+
local a, b = io.popen("ls", nil)
486+
assert(a)
487+
assert(b == nil)
488+
local a, b = io.popen("ls", nil, nil)
489+
assert(a)
490+
assert(b == nil)
491+
end
492+
test()

internal/gopher-lua/_glua-tests/os.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,3 @@ assert(os.getenv("PATH") ~= "")
1616
assert(os.getenv("_____GLUATEST______") == nil)
1717
assert(os.setenv("_____GLUATEST______", "1"))
1818
assert(os.getenv("_____GLUATEST______") == "1")
19-
assert(os.setenv("_____GLUATEST______", ""))

internal/gopher-lua/_state.go

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ func freeCallFrameStackSegment(seg *callFrameStackSegment) {
240240
segmentPool.Put(seg)
241241
}
242242

243-
// newAutoGrowingCallFrameStack allocates a new stack for a lua state, which will auto grow up to a max size of at least maxSize.
243+
// newCallFrameStack allocates a new stack for a lua state, which will auto grow up to a max size of at least maxSize.
244244
// it will actually grow up to the next segment size multiple after maxSize, where the segment size is dictated by
245245
// FramesPerSegment.
246246
func newAutoGrowingCallFrameStack(maxSize int) callFrameStack {
@@ -398,25 +398,26 @@ func (rg *registry) forceResize(newSize int) {
398398
copy(newSlice, rg.array[:rg.top]) // should we copy the area beyond top? there shouldn't be any valid values there so it shouldn't be necessary.
399399
rg.array = newSlice
400400
}
401-
func (rg *registry) SetTop(top int) {
402-
// +inline-call rg.checkSize top
403-
oldtop := rg.top
404-
rg.top = top
405-
for i := oldtop; i < rg.top; i++ {
401+
402+
func (rg *registry) SetTop(topi int) { // +inline-start
403+
// +inline-call rg.checkSize topi
404+
oldtopi := rg.top
405+
rg.top = topi
406+
for i := oldtopi; i < rg.top; i++ {
406407
rg.array[i] = LNil
407408
}
408409
// values beyond top don't need to be valid LValues, so setting them to nil is fine
409410
// setting them to nil rather than LNil lets us invoke the golang memclr opto
410-
if rg.top < oldtop {
411-
nilRange := rg.array[rg.top:oldtop]
411+
if rg.top < oldtopi {
412+
nilRange := rg.array[rg.top:oldtopi]
412413
for i := range nilRange {
413414
nilRange[i] = nil
414415
}
415416
}
416417
//for i := rg.top; i < oldtop; i++ {
417418
// rg.array[i] = LNil
418419
//}
419-
}
420+
} // +inline-end
420421

421422
func (rg *registry) Top() int {
422423
return rg.top
@@ -498,34 +499,34 @@ func (rg *registry) FillNil(regm, n int) { // +inline-start
498499
func (rg *registry) Insert(value LValue, reg int) {
499500
top := rg.Top()
500501
if reg >= top {
501-
rg.Set(reg, value)
502+
// +inline-call rg.Set reg value
502503
return
503504
}
504505
top--
505506
for ; top >= reg; top-- {
506507
// FIXME consider using copy() here if Insert() is called enough
507-
rg.Set(top+1, rg.Get(top))
508+
// +inline-call rg.Set top+1 rg.Get(top)
508509
}
509-
rg.Set(reg, value)
510+
// +inline-call rg.Set reg value
510511
}
511512

512-
func (rg *registry) Set(reg int, val LValue) {
513-
newSize := reg + 1
513+
func (rg *registry) Set(regi int, vali LValue) { // +inline-start
514+
newSize := regi + 1
514515
// +inline-call rg.checkSize newSize
515-
rg.array[reg] = val
516-
if reg >= rg.top {
517-
rg.top = reg + 1
516+
rg.array[regi] = vali
517+
if regi >= rg.top {
518+
rg.top = regi + 1
518519
}
519-
}
520+
} // +inline-end
520521

521-
func (rg *registry) SetNumber(reg int, val LNumber) {
522-
newSize := reg + 1
522+
func (rg *registry) SetNumber(regi int, vali LNumber) { // +inline-start
523+
newSize := regi + 1
523524
// +inline-call rg.checkSize newSize
524-
rg.array[reg] = rg.alloc.LNumber2I(val)
525-
if reg >= rg.top {
526-
rg.top = reg + 1
525+
rg.array[regi] = rg.alloc.LNumber2I(vali)
526+
if regi >= rg.top {
527+
rg.top = regi + 1
527528
}
528-
}
529+
} // +inline-end
529530

530531
func (rg *registry) IsFull() bool {
531532
return rg.top >= cap(rg.array)
@@ -769,6 +770,9 @@ func (ls *LState) isStarted() bool {
769770

770771
func (ls *LState) kill() {
771772
ls.Dead = true
773+
if ls.ctxCancelFn != nil {
774+
ls.ctxCancelFn()
775+
}
772776
}
773777

774778
func (ls *LState) indexToReg(idx int) int {
@@ -1406,6 +1410,7 @@ func (ls *LState) NewThread() (*LState, context.CancelFunc) {
14061410
if ls.ctx != nil {
14071411
thread.mainLoop = mainLoopWithContext
14081412
thread.ctx, f = context.WithCancel(ls.ctx)
1413+
thread.ctxCancelFn = f
14091414
}
14101415
return thread, f
14111416
}
@@ -1855,6 +1860,9 @@ func (ls *LState) PCall(nargs, nret int, errfunc *LFunction) (err error) {
18551860
err = rcv.(*ApiError)
18561861
err.(*ApiError).StackTrace = ls.stackTrace(0)
18571862
}
1863+
ls.stack.SetSp(sp)
1864+
ls.currentFrame = ls.stack.Last()
1865+
ls.reg.SetTop(base)
18581866
}
18591867
}()
18601868
ls.Call(1, 1)

0 commit comments

Comments
 (0)