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