MCPcopy Create free account
hub / github.com/DFHack/dfhack / str_packsize

Function str_packsize

depends/lua/src/lstrlib.c:1417–1439  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1415
1416
1417static int str_packsize (lua_State *L) {
1418 Header h;
1419 const char *fmt = luaL_checkstring(L, 1); /* format string */
1420 size_t totalsize = 0; /* accumulate total size of result */
1421 initheader(L, &h);
1422 while (*fmt != '\0') {
1423 int size, ntoalign;
1424 KOption opt = getdetails(&h, totalsize, &fmt, &size, &ntoalign);
1425 size += ntoalign; /* total space used by option */
1426 luaL_argcheck(L, totalsize <= MAXSIZE - size, 1,
1427 "format result too large");
1428 totalsize += size;
1429 switch (opt) {
1430 case Kstring: /* strings with length count */
1431 case Kzstr: /* zero-terminated string */
1432 luaL_argerror(L, 1, "variable-length format");
1433 /* call never return, but to avoid warnings: *//* FALLTHROUGH */
1434 default: break;
1435 }
1436 }
1437 lua_pushinteger(L, (lua_Integer)totalsize);
1438 return 1;
1439}
1440
1441
1442/*

Callers

nothing calls this directly

Calls 4

initheaderFunction · 0.85
getdetailsFunction · 0.85
luaL_argerrorFunction · 0.85
lua_pushintegerFunction · 0.85

Tested by

no test coverage detected