| 1641 | |
| 1642 | |
| 1643 | static 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 | /* |
nothing calls this directly
no test coverage detected