| 1698 | |
| 1699 | |
| 1700 | static int str_packsize (lua_State *L) { |
| 1701 | Header h; |
| 1702 | const char *fmt = luaL_checkstring(L, 1); /* format string */ |
| 1703 | size_t totalsize = 0; /* accumulate total size of result */ |
| 1704 | initheader(L, &h); |
| 1705 | while (*fmt != '\0') { |
| 1706 | int size, ntoalign; |
| 1707 | KOption opt = getdetails(&h, totalsize, &fmt, &size, &ntoalign); |
| 1708 | luaL_argcheck(L, opt != Kstring && opt != Kzstr, 1, |
| 1709 | "variable-length format"); |
| 1710 | size += ntoalign; /* total space used by option */ |
| 1711 | luaL_argcheck(L, totalsize <= MAXSIZE - size, 1, |
| 1712 | "format result too large"); |
| 1713 | totalsize += size; |
| 1714 | } |
| 1715 | lua_pushinteger(L, (lua_Integer)totalsize); |
| 1716 | return 1; |
| 1717 | } |
| 1718 | |
| 1719 | |
| 1720 | /* |
nothing calls this directly
no test coverage detected