MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / getoption

Function getoption

lib/lua/src/lstrlib.c:1488–1529  ·  view source on GitHub ↗

** Read and classify next option. 'size' is filled with option's size. */

Source from the content-addressed store, hash-verified

1486** Read and classify next option. 'size' is filled with option's size.
1487*/
1488static KOption getoption (Header *h, const char **fmt, int *size) {
1489 /* dummy structure to get native alignment requirements */
1490 struct cD { char c; union { LUAI_MAXALIGN; } u; };
1491 int opt = *((*fmt)++);
1492 *size = 0; /* default */
1493 switch (opt) {
1494 case 'b': *size = sizeof(char); return Kint;
1495 case 'B': *size = sizeof(char); return Kuint;
1496 case 'h': *size = sizeof(short); return Kint;
1497 case 'H': *size = sizeof(short); return Kuint;
1498 case 'l': *size = sizeof(long); return Kint;
1499 case 'L': *size = sizeof(long); return Kuint;
1500 case 'j': *size = sizeof(lua_Integer); return Kint;
1501 case 'J': *size = sizeof(lua_Integer); return Kuint;
1502 case 'T': *size = sizeof(size_t); return Kuint;
1503 case 'f': *size = sizeof(float); return Kfloat;
1504 case 'n': *size = sizeof(lua_Number); return Knumber;
1505 case 'd': *size = sizeof(double); return Kdouble;
1506 case 'i': *size = getnumlimit(h, fmt, sizeof(int)); return Kint;
1507 case 'I': *size = getnumlimit(h, fmt, sizeof(int)); return Kuint;
1508 case 's': *size = getnumlimit(h, fmt, sizeof(size_t)); return Kstring;
1509 case 'c':
1510 *size = getnum(fmt, -1);
1511 if (l_unlikely(*size == -1))
1512 luaL_error(h->L, "missing size for format option 'c'");
1513 return Kchar;
1514 case 'z': return Kzstr;
1515 case 'x': *size = 1; return Kpadding;
1516 case 'X': return Kpaddalign;
1517 case ' ': break;
1518 case '<': h->islittle = 1; break;
1519 case '>': h->islittle = 0; break;
1520 case '=': h->islittle = nativeendian.little; break;
1521 case '!': {
1522 const int maxalign = offsetof(struct cD, u);
1523 h->maxalign = getnumlimit(h, fmt, maxalign);
1524 break;
1525 }
1526 default: luaL_error(h->L, "invalid format option '%c'", opt);
1527 }
1528 return Knop;
1529}
1530
1531
1532/*

Callers 1

getdetailsFunction · 0.85

Calls 3

getnumlimitFunction · 0.85
getnumFunction · 0.85
luaL_errorFunction · 0.85

Tested by

no test coverage detected