MCPcopy Create free account
hub / github.com/DFHack/dfhack / packint

Function packint

depends/lua/src/lstrlib.c:1295–1309  ·  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

1293** bytes if necessary (by default they would be zeros).
1294*/
1295static void packint (luaL_Buffer *b, lua_Unsigned n,
1296 int islittle, int size, int neg) {
1297 char *buff = luaL_prepbuffsize(b, size);
1298 int i;
1299 buff[islittle ? 0 : size - 1] = (char)(n & MC); /* first byte */
1300 for (i = 1; i < size; i++) {
1301 n >>= NB;
1302 buff[islittle ? i : size - 1 - i] = (char)(n & MC);
1303 }
1304 if (neg && size > SZINT) { /* negative number need sign extension? */
1305 for (i = SZINT; i < size; i++) /* correct extra bytes */
1306 buff[islittle ? i : size - 1 - i] = (char)MC;
1307 }
1308 luaL_addsize(b, size); /* add result to buffer */
1309}
1310
1311
1312/*

Callers 1

str_packFunction · 0.85

Calls 1

luaL_prepbuffsizeFunction · 0.85

Tested by

no test coverage detected