MCPcopy Create free account
hub / github.com/BZFlag-Dev/bzflag / pushcapture

Function pushcapture

other_src/lua/src/lpeg.cpp:2165–2229  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2163
2164
2165static int pushcapture (CapState *cs) {
2166 luaL_checkstack(cs->L, 4, "too many captures");
2167 switch (captype(cs->cap)) {
2168 case Cposition: {
2169 lua_pushinteger(cs->L, cs->cap->s - cs->s + 1);
2170 cs->cap++;
2171 return 1;
2172 }
2173 case Cconst: {
2174 pushluaval(cs);
2175 cs->cap++;
2176 return 1;
2177 }
2178 case Carg: {
2179 int arg = (cs->cap++)->idx;
2180 if (arg + FIXEDARGS > cs->ptop)
2181 return luaL_error(cs->L, "reference to absent argument #%d", arg);
2182 lua_pushvalue(cs->L, arg + FIXEDARGS);
2183 return 1;
2184 }
2185 case Csimple: {
2186 int k = pushallvalues(cs, 1);
2187 if (k > 1)
2188 lua_insert(cs->L, -k); /* whole match is first result */
2189 return k;
2190 }
2191 case Cruntime: {
2192 int n = 0;
2193 while (!isclosecap(cs->cap++)) {
2194 luaL_checkstack(cs->L, 4, "too many captures");
2195 lua_pushvalue(cs->L, (cs->cap - 1)->idx);
2196 n++;
2197 }
2198 return n;
2199 }
2200 case Cstring: {
2201 luaL_Buffer b;
2202 luaL_buffinit(cs->L, &b);
2203 stringcap(&b, cs);
2204 luaL_pushresult(&b);
2205 return 1;
2206 }
2207 case Csubst: {
2208 luaL_Buffer b;
2209 luaL_buffinit(cs->L, &b);
2210 substcap(&b, cs);
2211 luaL_pushresult(&b);
2212 return 1;
2213 }
2214 case Cgroup: {
2215 if (cs->cap->idx == 0) /* anonymous group? */
2216 return pushallvalues(cs, 0); /* add all nested values */
2217 else { /* named group: add no values */
2218 cs->cap = nextcap(cs->cap); /* skip capture */
2219 return 0;
2220 }
2221 }
2222 case Cbackref: return backrefcap(cs);

Callers 5

pushallvaluesFunction · 0.85
tablecapFunction · 0.85
foldcapFunction · 0.85
addonestringFunction · 0.85
getcapturesFunction · 0.85

Calls 15

pushallvaluesFunction · 0.85
stringcapFunction · 0.85
substcapFunction · 0.85
nextcapFunction · 0.85
backrefcapFunction · 0.85
tablecapFunction · 0.85
functioncapFunction · 0.85
querycapFunction · 0.85
foldcapFunction · 0.85
luaL_checkstackFunction · 0.70
lua_pushintegerFunction · 0.70
luaL_errorFunction · 0.70

Tested by

no test coverage detected