string.pack (fmt, v1, v2, ...): Returns a binary string containing the values v1, v2, etc. packed (that is, serialized in binary form) according to the format string fmt.
string.packsize (fmt): Returns the size of a string resulting from string.pack with the given format. The format string cannot have the variable-length options 's' or 'z'.
string.unpack (fmt, s [, pos]): Returns the values packed in string s according to the format string fmt. An optional pos marks where to start reading in s (default is 1). After the read values, this function also returns the index of the first unread byte in s.
This passes the Lua 5.3.4 tests for the functions, with a few adjustments made regarding number sizes due to differences in Lua 5.1 & Java. I have included these tests in the PR as well.
The code is a bit messy right now and may need some refactoring to look decent, but it works.
This PR adds three new functions from Lua 5.3:
string.pack (fmt, v1, v2, ...)
: Returns a binary string containing the valuesv1
,v2
, etc. packed (that is, serialized in binary form) according to the format stringfmt
.string.packsize (fmt)
: Returns the size of a string resulting from string.pack with the given format. The format string cannot have the variable-length options 's' or 'z'.string.unpack (fmt, s [, pos])
: Returns the values packed in string s according to the format stringfmt
. An optionalpos
marks where to start reading ins
(default is 1). After the read values, this function also returns the index of the first unread byte ins
.This passes the Lua 5.3.4 tests for the functions, with a few adjustments made regarding number sizes due to differences in Lua 5.1 & Java. I have included these tests in the PR as well.
The code is a bit messy right now and may need some refactoring to look decent, but it works.