MCPcopy Create free account
hub / github.com/CppCXY/EmmyLuaCodeStyle / str_packsize

Function str_packsize

3rd/lua-5.4.3/src/lstrlib.c:1643–1660  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1641
1642
1643static int str_packsize (lua_State *L) {
1644 Header h;
1645 const char *fmt = luaL_checkstring(L, 1); /* format string */
1646 size_t totalsize = 0; /* accumulate total size of result */
1647 initheader(L, &h);
1648 while (*fmt != '\0') {
1649 int size, ntoalign;
1650 KOption opt = getdetails(&h, totalsize, &fmt, &size, &ntoalign);
1651 luaL_argcheck(L, opt != Kstring && opt != Kzstr, 1,
1652 "variable-length format");
1653 size += ntoalign; /* total space used by option */
1654 luaL_argcheck(L, totalsize <= MAXSIZE - size, 1,
1655 "format result too large");
1656 totalsize += size;
1657 }
1658 lua_pushinteger(L, (lua_Integer)totalsize);
1659 return 1;
1660}
1661
1662
1663/*

Callers

nothing calls this directly

Calls 3

initheaderFunction · 0.85
getdetailsFunction · 0.85
lua_pushintegerFunction · 0.85

Tested by

no test coverage detected