| 546 | |
| 547 | |
| 548 | static int gmatch_aux (lua_State *L) { |
| 549 | MatchState ms; |
| 550 | size_t ls; |
| 551 | const char *s = lua_tolstring(L, lua_upvalueindex(1), &ls); |
| 552 | const char *p = lua_tostring(L, lua_upvalueindex(2)); |
| 553 | const char *src; |
| 554 | ms.L = L; |
| 555 | ms.src_init = s; |
| 556 | ms.src_end = s+ls; |
| 557 | for (src = s + (size_t)lua_tointeger(L, lua_upvalueindex(3)); |
| 558 | src <= ms.src_end; |
| 559 | src++) { |
| 560 | const char *e; |
| 561 | ms.level = 0; |
| 562 | if ((e = match(&ms, src, p)) != NULL) { |
| 563 | lua_Integer newstart = e-s; |
| 564 | if (e == src) newstart++; /* empty match? go at least one position */ |
| 565 | lua_pushinteger(L, newstart); |
| 566 | lua_replace(L, lua_upvalueindex(3)); |
| 567 | return push_captures(&ms, src, e); |
| 568 | } |
| 569 | } |
| 570 | return 0; /* not found */ |
| 571 | } |
| 572 | |
| 573 | |
| 574 | static int gmatch (lua_State *L) { |
nothing calls this directly
no test coverage detected