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

Function getpatt

other_src/lua/src/lpeg.cpp:1251–1312  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1249
1250
1251static Instruction *getpatt (lua_State *L, int idx, int *size) {
1252 Instruction *p;
1253 switch (lua_type(L, idx)) {
1254 case LUA_TSTRING: {
1255 size_t i, len;
1256 const char *s = lua_tolstring(L, idx, &len);
1257 p = newpatt(L, len);
1258 for (i = 0; i < len; i++)
1259 setinstaux(p + i, IChar, 0, (byte)s[i]);
1260 lua_replace(L, idx);
1261 break;
1262 }
1263 case LUA_TNUMBER: {
1264 int n = lua_tointeger(L, idx);
1265 if (n == 0) /* empty pattern? */
1266 p = newpatt(L, 0);
1267 else if (n > 0)
1268 p = any(L, n, 0, NULL);
1269 else if (-n <= UCHAR_MAX) {
1270 p = newpatt(L, 2);
1271 setinstaux(p, IAny, 2, -n);
1272 setinst(p + 1, IFail, 0);
1273 }
1274 else {
1275 int offset = 2; /* space for ITestAny & IChoice */
1276 p = any(L, -n - UCHAR_MAX, 3, &offset);
1277 setinstaux(p, IAny, offset + 1, UCHAR_MAX);
1278 setinstaux(p + 1, IChoice, offset, UCHAR_MAX);
1279 setinst(p + offset, IFailTwice, 0);
1280 }
1281 lua_replace(L, idx);
1282 break;
1283 }
1284 case LUA_TBOOLEAN: {
1285 if (lua_toboolean(L, idx)) /* true? */
1286 p = newpatt(L, 0); /* empty pattern (always succeeds) */
1287 else {
1288 p = newpatt(L, 1);
1289 setinst(p, IFail, 0);
1290 }
1291 lua_replace(L, idx);
1292 break;
1293 }
1294 case LUA_TTABLE: {
1295 p = fix_l(L, idx);
1296 break;
1297 }
1298 case LUA_TFUNCTION: {
1299 p = newpatt(L, 2);
1300 setinstcap(p, IOpenCapture, value2fenv(L, idx), Cruntime, 0);
1301 setinstcap(p + 1, ICloseRunTime, 0, Cclose, 0);
1302 lua_replace(L, idx);
1303 break;
1304 }
1305 default: {
1306 p = checkpattern(L, idx);
1307 break;
1308 }

Callers 13

set_lFunction · 0.85
getpattlFunction · 0.85
pattern_lFunction · 0.85
concat_lFunction · 0.85
diff_lFunction · 0.85
unm_lFunction · 0.85
pattand_lFunction · 0.85
pattbehindFunction · 0.85
union_lFunction · 0.85
star_lFunction · 0.85
capture_auxFunction · 0.85
printpat_lFunction · 0.85

Calls 10

newpattFunction · 0.85
setinstauxFunction · 0.85
lua_tointegerFunction · 0.85
anyFunction · 0.85
fix_lFunction · 0.85
value2fenvFunction · 0.85
lua_typeFunction · 0.70
lua_tolstringFunction · 0.70
lua_replaceFunction · 0.70
lua_tobooleanFunction · 0.70

Tested by

no test coverage detected