11.12. Handling 64-bit Integers

Lua uses one single number representation which can be chosen at compile time and since it is often set to IEEE 754 double precision floating point, one cannot store a 64 bit integer with full precision.

For details, see https://wiki.wireshark.org/LuaAPI/Int64.

11.12.1. Int64

Int64 represents a 64 bit signed integer.

For details, see https://wiki.wireshark.org/LuaAPI/Int64.

11.12.1.1. Int64.decode(string, [endian])

Decodes an 8-byte Lua string, using given endianness, into a new Int64 object.

Since: 1.11.3

Arguments
string
The Lua string containing a binary 64-bit integer.
endian (optional)
If set to true then little-endian is used, if false then big-endian; if missing/nil, native host endian.
Returns

The Int64 object created, or nil on failure.

11.12.1.2. Int64.new([value], [highvalue])

Creates a Int64 Object.

Since: 1.11.3

Arguments
value (optional)
A number, UInt64, Int64, or string of ASCII digits to assign the value of the new Int64 (default=0).
highvalue (optional)
If this is a number and the first argument was a number, then the first will be treated as a lower 32-bits, and this is the high-order 32 bit number.
Returns

The new Int64 object.

11.12.1.3. Int64.max()

Gets the max possible value.

Since: 1.11.3

Returns

The new Int64 object of the max value.

11.12.1.4. Int64.min()

Gets the min possible value.

Since: 1.11.3

Returns

The new Int64 object of the min value.

11.12.1.5. Int64.fromhex(hex)

Creates an Int64 object from the given hex string.

Since: 1.11.3

Arguments
hex
The hex-ascii Lua string.
Returns

The new Int64 object.

11.12.1.6. int64:encode([endian])

Encodes the Int64 number into an 8-byte Lua string, using given endianness.

Since: 1.11.3

Arguments
endian (optional)
If set to true then little-endian is used, if false then big-endian; if missing/nil, native host endian.
Returns

The Lua string.

11.12.1.7. int64:__call()

Creates a Int64 Object.

Since: 1.11.3

Returns

The new Int64 object.

11.12.1.8. int64:tonumber()

Returns a Lua number of the Int64 value - this may lose precision.

Since: 1.11.3

Returns

The Lua number.

11.12.1.9. int64:tohex([numbytes])

Returns a hex string of the Int64 value.

Since: 1.11.3

Arguments
numbytes (optional)
The number of hex-chars/nibbles to generate, negative means uppercase (default=16).
Returns

The string hex.

11.12.1.10. int64:higher()

Returns a Lua number of the higher 32-bits of the Int64 value. (negative Int64 will return a negative Lua number).

Since: 1.11.3

Returns

The Lua number.

11.12.1.11. int64:lower()

Returns a Lua number of the lower 32-bits of the Int64 value. (always positive).

Since: 1.11.3

Returns

The Lua number.

11.12.1.12. int64:__tostring()

Converts the Int64 into a string of decimal digits.

Returns

The Lua string.

11.12.1.13. int64:__unm()

Returns the negative of the Int64, in a new Int64.

Since: 1.11.3

Returns

The new Int64.

11.12.1.14. int64:__add()

Adds two Int64 together and returns a new one (this may wrap the value).

Since: 1.11.3

11.12.1.15. int64:__sub()

Subtracts two Int64 and returns a new one (this may wrap the value).

Since: 1.11.3

11.12.1.16. int64:__mul()

Multiplies two Int64 and returns a new one (this may truncate the value).

Since: 1.11.3

11.12.1.17. int64:__div()

Divides two Int64 and returns a new one (integer divide, no remainder). Trying to divide by zero results in a Lua error.

Since: 1.11.3

Returns

The Int64 object.

11.12.1.18. int64:__mod()

Divides two Int64 and returns a new one of the remainder. Trying to modulo by zero results in a Lua error.

Since: 1.11.3

Returns

The Int64 object.

11.12.1.19. int64:__pow()

The first Int64 is taken to the power of the second Int64, returning a new one (this may truncate the value).

Since: 1.11.3

Returns

The Int64 object.

11.12.1.20. int64:__eq()

Returns true if both Int64 are equal.

Since: 1.11.3

11.12.1.21. int64:__lt()

Returns true if first Int64 < second.

Since: 1.11.3

11.12.1.22. int64:__le()

Returns true if first Int64 ⇐ second.

Since: 1.11.3

11.12.1.23. int64:bnot()

Returns a Int64 of the bitwise not operation.

Since: 1.11.3

Returns

The Int64 object.

11.12.1.24. int64:band()

Returns a Int64 of the bitwise and operation, with the given number/Int64/UInt64. Note that multiple arguments are allowed.

Since: 1.11.3

Returns

The Int64 object.

11.12.1.25. int64:bor()

Returns a Int64 of the bitwise or operation, with the given number/Int64/UInt64. Note that multiple arguments are allowed.

Since: 1.11.3

Returns

The Int64 object.

11.12.1.26. int64:bxor()

Returns a Int64 of the bitwise xor operation, with the given number/Int64/UInt64. Note that multiple arguments are allowed.

Since: 1.11.3

Returns

The Int64 object.

11.12.1.27. int64:lshift(numbits)

Returns a Int64 of the bitwise logical left-shift operation, by the given number of bits.

Since: 1.11.3

Arguments
numbits
The number of bits to left-shift by.
Returns

The Int64 object.

11.12.1.28. int64:rshift(numbits)

Returns a Int64 of the bitwise logical right-shift operation, by the given number of bits.

Since: 1.11.3

Arguments
numbits
The number of bits to right-shift by.
Returns

The Int64 object.

11.12.1.29. int64:arshift(numbits)

Returns a Int64 of the bitwise arithmetic right-shift operation, by the given number of bits.

Since: 1.11.3

Arguments
numbits
The number of bits to right-shift by.
Returns

The Int64 object.

11.12.1.30. int64:rol(numbits)

Returns a Int64 of the bitwise left rotation operation, by the given number of bits (up to 63).

Since: 1.11.3

Arguments
numbits
The number of bits to roll left by.
Returns

The Int64 object.

11.12.1.31. int64:ror(numbits)

Returns a Int64 of the bitwise right rotation operation, by the given number of bits (up to 63).

Since: 1.11.3

Arguments
numbits
The number of bits to roll right by.
Returns

The Int64 object.

11.12.1.32. int64:bswap()

Returns a Int64 of the bytes swapped. This can be used to convert little-endian 64-bit numbers to big-endian 64 bit numbers or vice versa.

Since: 1.11.3

Returns

The Int64 object.

11.12.2. UInt64

UInt64 represents a 64 bit unsigned integer, similar to Int64.

For details, see: https://wiki.wireshark.org/LuaAPI/Int64.

11.12.2.1. UInt64.decode(string, [endian])

Decodes an 8-byte Lua binary string, using given endianness, into a new UInt64 object.

Since: 1.11.3

Arguments
string
The Lua string containing a binary 64-bit integer.
endian (optional)
If set to true then little-endian is used, if false then big-endian; if missing/nil, native host endian.
Returns

The UInt64 object created, or nil on failure.

11.12.2.2. UInt64.new([value], [highvalue])

Creates a UInt64 Object.

Since: 1.11.3

Arguments
value (optional)
A number, UInt64, Int64, or string of digits to assign the value of the new UInt64 (default=0).
highvalue (optional)
If this is a number and the first argument was a number, then the first will be treated as a lower 32-bits, and this is the high-order 32-bit number.
Returns

The new UInt64 object.

11.12.2.3. UInt64.max()

Gets the max possible value.

Since: 1.11.3

Returns

The max value.

11.12.2.4. UInt64.min()

Gets the min possible value (i.e., 0).

Since: 1.11.3

Returns

The min value.

11.12.2.5. UInt64.fromhex(hex)

Creates a UInt64 object from the given hex string.

Since: 1.11.3

Arguments
hex
The hex-ascii Lua string.
Returns

The new UInt64 object.

11.12.2.6. uint64:encode([endian])

Encodes the UInt64 number into an 8-byte Lua binary string, using given endianness.

Since: 1.11.3

Arguments
endian (optional)
If set to true then little-endian is used, if false then big-endian; if missing/nil, native host endian.
Returns

The Lua binary string.

11.12.2.7. uint64:__call()

Creates a UInt64 Object.

Since: 1.11.3

Returns

The new UInt64 object.

11.12.2.8. uint64:tonumber()

Returns a Lua number of the UInt64 value - this may lose precision.

Since: 1.11.3

Returns

The Lua number.

11.12.2.9. uint64:__tostring()

Converts the UInt64 into a string.

Returns

The Lua string.

11.12.2.10. uint64:tohex([numbytes])

Returns a hex string of the UInt64 value.

Since: 1.11.3

Arguments
numbytes (optional)
The number of hex-chars/nibbles to generate, negative means uppercase (default=16).
Returns

The string hex.

11.12.2.11. uint64:higher()

Returns a Lua number of the higher 32-bits of the UInt64 value.

Returns

The Lua number.

11.12.2.12. uint64:lower()

Returns a Lua number of the lower 32-bits of the UInt64 value.

Returns

The Lua number.

11.12.2.13. uint64:__unm()

Returns the UInt64, in a new UInt64, since unsigned integers can’t be negated.

Since: 1.11.3

Returns

The UInt64 object.

11.12.2.14. uint64:__add()

Adds two UInt64 together and returns a new one (this may wrap the value).

Since: 1.11.3

11.12.2.15. uint64:__sub()

Subtracts two UInt64 and returns a new one (this may wrap the value).

Since: 1.11.3

11.12.2.16. uint64:__mul()

Multiplies two UInt64 and returns a new one (this may truncate the value).

Since: 1.11.3

11.12.2.17. uint64:__div()

Divides two UInt64 and returns a new one (integer divide, no remainder). Trying to divide by zero results in a Lua error.

Since: 1.11.3

Returns

The UInt64 result.

11.12.2.18. uint64:__mod()

Divides two UInt64 and returns a new one of the remainder. Trying to modulo by zero results in a Lua error.

Since: 1.11.3

Returns

The UInt64 result.

11.12.2.19. uint64:__pow()

The first UInt64 is taken to the power of the second UInt64/number, returning a new one (this may truncate the value).

Since: 1.11.3

Returns

The UInt64 object.

11.12.2.20. uint64:__eq()

Returns true if both UInt64 are equal.

Since: 1.11.3

11.12.2.21. uint64:__lt()

Returns true if first UInt64 < second.

Since: 1.11.3

11.12.2.22. uint64:__le()

Returns true if first UInt64 ⇐ second.

Since: 1.11.3

11.12.2.23. uint64:bnot()

Returns a UInt64 of the bitwise not operation.

Since: 1.11.3

Returns

The UInt64 object.

11.12.2.24. uint64:band()

Returns a UInt64 of the bitwise and operation, with the given number/Int64/UInt64. Note that multiple arguments are allowed.

Since: 1.11.3

Returns

The UInt64 object.

11.12.2.25. uint64:bor()

Returns a UInt64 of the bitwise or operation, with the given number/Int64/UInt64. Note that multiple arguments are allowed.

Since: 1.11.3

Returns

The UInt64 object.

11.12.2.26. uint64:bxor()

Returns a UInt64 of the bitwise xor operation, with the given number/Int64/UInt64. Note that multiple arguments are allowed.

Since: 1.11.3

Returns

The UInt64 object.

11.12.2.27. uint64:lshift(numbits)

Returns a UInt64 of the bitwise logical left-shift operation, by the given number of bits.

Since: 1.11.3

Arguments
numbits
The number of bits to left-shift by.
Returns

The UInt64 object.

11.12.2.28. uint64:rshift(numbits)

Returns a UInt64 of the bitwise logical right-shift operation, by the given number of bits.

Since: 1.11.3

Arguments
numbits
The number of bits to right-shift by.
Returns

The UInt64 object.

11.12.2.29. uint64:arshift(numbits)

Returns a UInt64 of the bitwise arithmetic right-shift operation, by the given number of bits.

Since: 1.11.3

Arguments
numbits
The number of bits to right-shift by.
Returns

The UInt64 object.

11.12.2.30. uint64:rol(numbits)

Returns a UInt64 of the bitwise left rotation operation, by the given number of bits (up to 63).

Since: 1.11.3

Arguments
numbits
The number of bits to roll left by.
Returns

The UInt64 object.

11.12.2.31. uint64:ror(numbits)

Returns a UInt64 of the bitwise right rotation operation, by the given number of bits (up to 63).

Since: 1.11.3

Arguments
numbits
The number of bits to roll right by.
Returns

The UInt64 object.

11.12.2.32. uint64:bswap()

Returns a UInt64 of the bytes swapped. This can be used to convert little-endian 64-bit numbers to big-endian 64 bit numbers or vice versa.

Since: 1.11.3

Returns

The UInt64 object.