MCPcopy Create free account
hub / github.com/EmmyLua/EmmyLuaDebugger / packint

Function packint

third-party/lua-5.5.0/src/lstrlib.c:1578–1592  ·  view source on GitHub ↗

** Pack integer 'n' with 'size' bytes and 'islittle' endianness. ** The final 'if' handles the case when 'size' is larger than ** the size of a Lua integer, correcting the extra sign-extension ** bytes if necessary (by default they would be zeros). */

Source from the content-addressed store, hash-verified

1576** bytes if necessary (by default they would be zeros).
1577*/
1578static void packint (luaL_Buffer *b, lua_Unsigned n,
1579 int islittle, unsigned size, int neg) {
1580 char *buff = luaL_prepbuffsize(b, size);
1581 unsigned i;
1582 buff[islittle ? 0 : size - 1] = (char)(n & MC); /* first byte */
1583 for (i = 1; i < size; i++) {
1584 n >>= NB;
1585 buff[islittle ? i : size - 1 - i] = (char)(n & MC);
1586 }
1587 if (neg && size > SZINT) { /* negative number need sign extension? */
1588 for (i = SZINT; i < size; i++) /* correct extra bytes */
1589 buff[islittle ? i : size - 1 - i] = (char)MC;
1590 }
1591 luaL_addsize(b, size); /* add result to buffer */
1592}
1593
1594
1595/*

Callers 1

str_packFunction · 0.70

Calls 1

luaL_prepbuffsizeFunction · 0.70

Tested by

no test coverage detected