Add a string.gmatch call to strlib.lua test case and fix the bug it exposed.
This commit is contained in:
@@ -275,18 +275,17 @@ public class StringLib extends LFunction {
|
|||||||
* as this would prevent the iteration.
|
* as this would prevent the iteration.
|
||||||
*/
|
*/
|
||||||
static void gmatch( LuaState vm ) {
|
static void gmatch( LuaState vm ) {
|
||||||
|
LString src = vm.tolstring( 2 );
|
||||||
|
LString pat = vm.tolstring( 3 );
|
||||||
vm.resettop();
|
vm.resettop();
|
||||||
vm.pushlvalue( new GMatchAux(vm) );
|
vm.pushlvalue( new GMatchAux(vm, src, pat) );
|
||||||
}
|
}
|
||||||
|
|
||||||
static class GMatchAux extends LFunction {
|
static class GMatchAux extends LFunction {
|
||||||
private final LString src,pat;
|
|
||||||
private final int srclen;
|
private final int srclen;
|
||||||
private final MatchState ms;
|
private final MatchState ms;
|
||||||
private int soffset;
|
private int soffset;
|
||||||
public GMatchAux(LuaState vm) {
|
public GMatchAux(LuaState vm, LString src, LString pat) {
|
||||||
this.src = vm.tolstring(2);
|
|
||||||
this.pat = vm.tolstring(3);
|
|
||||||
this.srclen = src.length();
|
this.srclen = src.length();
|
||||||
this.ms = new MatchState(vm, src, pat);
|
this.ms = new MatchState(vm, src, pat);
|
||||||
this.soffset = 0;
|
this.soffset = 0;
|
||||||
@@ -294,6 +293,7 @@ public class StringLib extends LFunction {
|
|||||||
public boolean luaStackCall(LuaState vm) {
|
public boolean luaStackCall(LuaState vm) {
|
||||||
vm.resettop();
|
vm.resettop();
|
||||||
for ( ; soffset<srclen; soffset++ ) {
|
for ( ; soffset<srclen; soffset++ ) {
|
||||||
|
ms.reset();
|
||||||
int res = ms.match(soffset, 0);
|
int res = ms.match(soffset, 0);
|
||||||
if ( res >=0 ) {
|
if ( res >=0 ) {
|
||||||
int soff = soffset;
|
int soff = soffset;
|
||||||
|
|||||||
@@ -43,3 +43,7 @@ local function badpat()
|
|||||||
end
|
end
|
||||||
|
|
||||||
print( pcall( badpat ) )
|
print( pcall( badpat ) )
|
||||||
|
|
||||||
|
for k, v in string.gmatch("w=200&h=150", "(%w+)=(%w+)") do
|
||||||
|
print(k, v)
|
||||||
|
end
|
||||||
|
|||||||
Binary file not shown.
Reference in New Issue
Block a user