| 1715 | |
| 1716 | |
| 1717 | static int str_packsize (lua_State *L) { |
| 1718 | Header h; |
| 1719 | const char *fmt = luaL_checkstring(L, 1); /* format string */ |
| 1720 | size_t totalsize = 0; /* accumulate total size of result */ |
| 1721 | initheader(L, &h); |
| 1722 | while (*fmt != '\0') { |
| 1723 | unsigned ntoalign; |
| 1724 | size_t size; |
| 1725 | KOption opt = getdetails(&h, totalsize, &fmt, &size, &ntoalign); |
| 1726 | luaL_argcheck(L, opt != Kstring && opt != Kzstr, 1, |
| 1727 | "variable-length format"); |
| 1728 | size += ntoalign; /* total space used by option */ |
| 1729 | luaL_argcheck(L, totalsize <= LUA_MAXINTEGER - size, |
| 1730 | 1, "format result too large"); |
| 1731 | totalsize += size; |
| 1732 | } |
| 1733 | lua_pushinteger(L, cast_st2S(totalsize)); |
| 1734 | return 1; |
| 1735 | } |
| 1736 | |
| 1737 | |
| 1738 | /* |
nothing calls this directly
no test coverage detected