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