| 852 | |
| 853 | |
| 854 | static int gmatch (lua_State *L) { |
| 855 | size_t ls, lp; |
| 856 | const char *s = luaL_checklstring(L, 1, &ls); |
| 857 | const char *p = luaL_checklstring(L, 2, &lp); |
| 858 | size_t init = posrelatI(luaL_optinteger(L, 3, 1), ls) - 1; |
| 859 | GMatchState *gm; |
| 860 | lua_settop(L, 2); /* keep strings on closure to avoid being collected */ |
| 861 | gm = (GMatchState *)lua_newuserdatauv(L, sizeof(GMatchState), 0); |
| 862 | if (init > ls) /* start after string's end? */ |
| 863 | init = ls + 1; /* avoid overflows in 's + init' */ |
| 864 | prepstate(&gm->ms, L, s, ls, p, lp); |
| 865 | gm->src = s + init; gm->p = p; gm->lastmatch = NULL; |
| 866 | lua_pushcclosure(L, gmatch_aux, 3); |
| 867 | return 1; |
| 868 | } |
| 869 | |
| 870 | |
| 871 | static void add_s (MatchState *ms, luaL_Buffer *b, const char *s, |
nothing calls this directly
no test coverage detected