/* 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).  */
static void packint(luaL_Buffer *b, lua_Unsigned n, int islittle, int size, int neg)
/* 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).  */
static void packint(luaL_Buffer *b, lua_Unsigned n, int islittle, int size, int neg)
{
  char *buff = luaL_prepbuffsize(b, size);
  int i;
  buff[islittle ? 0 : size - 1] = (char)(n & MC);
  for (i = 1; i < size; i++) {
    n >>= NB;
    buff[islittle ? i : size - 1 - i] = (char)(n & MC);
  }
  if (neg && size > SZINT) {
    for (i = SZINT; i < size; i++)
      buff[islittle ? i : size - 1 - i] = (char)MC;
  }
  luaL_addsize(b, size);
}