Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -869,7 +869,7 @@ Libraries for GopherLua
- `gluasql <https://github.com/tengattack/gluasql>`_ : A native Go implementation of SQL client for the GopherLua VM.
- `purr <https://github.com/leyafo/purr>`_ : A http mock testing tool.
- `vadv/gopher-lua-libs <https://github.com/vadv/gopher-lua-libs>`_ : Some usefull libraries for GopherLua VM.
- `gluaperiphery <https://github.com/BixData/gluaperiphery>`_ : A periphery library for the GopherLua VM (GPIO, SPI, I2C, MMIO, and Serial peripheral I/O for Linux).
- `gluasocket <https://gitlab.com/megalithic-llc/gluasocket>`_ : A native Go implementation of LuaSocket for the GopherLua VM.
- `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
Expand Down
33 changes: 33 additions & 0 deletions _glua-tests/issues.lua
Original file line number Diff line number Diff line change
Expand Up @@ -457,3 +457,36 @@ function test()
assert(c == 1)
assert(type(c) == "number")
end
test()

-- issue #452
function test()
local ok, msg = pcall(function()
local ok, msg = xpcall(function() error("fn") end, function(err) error("handler") end)
assert(not ok and msg)
error("expected to reach this.")
end)
assert(not ok)
end
test()

-- issue #455
function test()
local path = "."
local fd, _, code = io.open(path, "r")
assert(fd ~= nil)
local _, _, ecode = fd:read(1)
assert(ecode == 1)
end
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()
50 changes: 27 additions & 23 deletions _state.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,25 +398,26 @@ func (rg *registry) forceResize(newSize int) {
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.
rg.array = newSlice
}
func (rg *registry) SetTop(top int) {
// +inline-call rg.checkSize top
oldtop := rg.top
rg.top = top
for i := oldtop; i < rg.top; i++ {

func (rg *registry) SetTop(topi int) { // +inline-start
// +inline-call rg.checkSize topi
oldtopi := rg.top
rg.top = topi
for i := oldtopi; i < rg.top; i++ {
rg.array[i] = LNil
}
// values beyond top don't need to be valid LValues, so setting them to nil is fine
// setting them to nil rather than LNil lets us invoke the golang memclr opto
if rg.top < oldtop {
nilRange := rg.array[rg.top:oldtop]
if rg.top < oldtopi {
nilRange := rg.array[rg.top:oldtopi]
for i := range nilRange {
nilRange[i] = nil
}
}
//for i := rg.top; i < oldtop; i++ {
// rg.array[i] = LNil
//}
}
} // +inline-end

func (rg *registry) Top() int {
return rg.top
Expand Down Expand Up @@ -498,34 +499,34 @@ func (rg *registry) FillNil(regm, n int) { // +inline-start
func (rg *registry) Insert(value LValue, reg int) {
top := rg.Top()
if reg >= top {
rg.Set(reg, value)
// +inline-call rg.Set reg value
return
}
top--
for ; top >= reg; top-- {
// FIXME consider using copy() here if Insert() is called enough
rg.Set(top+1, rg.Get(top))
// +inline-call rg.Set top+1 rg.Get(top)
}
rg.Set(reg, value)
// +inline-call rg.Set reg value
}

func (rg *registry) Set(reg int, val LValue) {
newSize := reg + 1
func (rg *registry) Set(regi int, vali LValue) { // +inline-start
newSize := regi + 1
// +inline-call rg.checkSize newSize
rg.array[reg] = val
if reg >= rg.top {
rg.top = reg + 1
rg.array[regi] = vali
if regi >= rg.top {
rg.top = regi + 1
}
}
} // +inline-end

func (rg *registry) SetNumber(reg int, val LNumber) {
newSize := reg + 1
func (rg *registry) SetNumber(regi int, vali LNumber) { // +inline-start
newSize := regi + 1
// +inline-call rg.checkSize newSize
rg.array[reg] = rg.alloc.LNumber2I(val)
if reg >= rg.top {
rg.top = reg + 1
rg.array[regi] = rg.alloc.LNumber2I(vali)
if regi >= rg.top {
rg.top = regi + 1
}
}
} // +inline-end

func (rg *registry) IsFull() bool {
return rg.top >= cap(rg.array)
Expand Down Expand Up @@ -1855,6 +1856,9 @@ func (ls *LState) PCall(nargs, nret int, errfunc *LFunction) (err error) {
err = rcv.(*ApiError)
err.(*ApiError).StackTrace = ls.stackTrace(0)
}
ls.stack.SetSp(sp)
ls.currentFrame = ls.stack.Last()
ls.reg.SetTop(base)
}
}()
ls.Call(1, 1)
Expand Down
Loading