lualua-5.4

Why string.pack pack integer with 4 bytes?


As we all known, in standard Lua 5.4, a integer has 64 bits (8 bytes).

But string.packsize('i') == 4, that is to say a integer will be pack into 4 * 8 = 32 bits. It's strange, isn't it?


Solution

  • Sorry for noise, it's because the "int" here refering is a native-sized int, as reference mentioned.

    And in the standard C, the size of int is 32 bits (4 bytes).