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

Function packint

third-party/lua-5.4.6/src/lstrlib.c:1568–1582  ·  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

1566** bytes if necessary (by default they would be zeros).
1567*/
1568static void packint (luaL_Buffer *b, lua_Unsigned n,
1569 int islittle, int size, int neg) {
1570 char *buff = luaL_prepbuffsize(b, size);
1571 int i;
1572 buff[islittle ? 0 : size - 1] = (char)(n & MC); /* first byte */
1573 for (i = 1; i < size; i++) {
1574 n >>= NB;
1575 buff[islittle ? i : size - 1 - i] = (char)(n & MC);
1576 }
1577 if (neg && size > SZINT) { /* negative number need sign extension? */
1578 for (i = SZINT; i < size; i++) /* correct extra bytes */
1579 buff[islittle ? i : size - 1 - i] = (char)MC;
1580 }
1581 luaL_addsize(b, size); /* add result to buffer */
1582}
1583
1584
1585/*

Callers 1

str_packFunction · 0.70

Calls 1

luaL_prepbuffsizeFunction · 0.70

Tested by

no test coverage detected