Skip to content
Open
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
15 changes: 15 additions & 0 deletions _glua-tests/issues.lua
Original file line number Diff line number Diff line change
Expand Up @@ -490,3 +490,18 @@ function test()
assert(b == nil)
end
test()

-- issue #462
function test()
local x = string.gmatch("asdf", "a")
assert(x() == "a", "check gmatch callback")

local expected = {
"a",
"c",
}
for i in string.gmatch("abc", "[ac]") do
assert(i == table.remove(expected, 1), "check gmatch inside loop")
end
end
test()
10 changes: 5 additions & 5 deletions stringlib.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func OpenString(L *LState) int {
//_, ok := L.G.builtinMts[int(LTString)]
//if !ok {
mod = L.RegisterModule(StringLibName, strFuncs).(*LTable)
gmatch := L.NewClosure(strGmatch, L.NewFunction(strGmatchIter))
gmatch := L.NewFunction(strGmatch)
mod.RawSetString("gmatch", gmatch)
mod.RawSetString("gfind", gmatch)
mod.RawSetString("__index", mod)
Expand Down Expand Up @@ -299,7 +299,7 @@ type strMatchData struct {
}

func strGmatchIter(L *LState) int {
md := L.CheckUserData(1).Value.(*strMatchData)
md := L.CheckUserData(UpvalueIndex(1)).Value.(*strMatchData)
str := md.str
matches := md.matches
idx := md.pos
Expand Down Expand Up @@ -331,11 +331,11 @@ func strGmatch(L *LState) int {
if err != nil {
L.RaiseError(err.Error())
}
L.Push(L.Get(UpvalueIndex(1)))
ud := L.NewUserData()
ud.Value = &strMatchData{str, 0, mds}
L.Push(ud)
return 2
f := L.NewClosure(strGmatchIter, ud)
L.Push(f)
return 1
}

func strLen(L *LState) int {
Expand Down