mirror of
https://github.com/luanti-org/luanti.git
synced 2025-08-16 18:01:40 +00:00
Add Lua binary network serialization functions
This commit is contained in:
parent
fde6384a09
commit
2f33926573
6 changed files with 563 additions and 59 deletions
|
@ -5971,6 +5971,9 @@ Utilities
|
|||
form. If the ColorSpec is invalid, returns `nil`. You can use this to parse
|
||||
ColorStrings.
|
||||
* `colorspec`: The ColorSpec to convert
|
||||
* `core.colorspec_to_int(colorspec)`: Converts a ColorSpec to integer form.
|
||||
If the ColorSpec is invalid, returns `nil`.
|
||||
* `colorspec`: The ColorSpec to convert
|
||||
* `core.time_to_day_night_ratio(time_of_day)`: Returns a "day-night ratio" value
|
||||
(as accepted by `ObjectRef:override_day_night_ratio`) that is equivalent to
|
||||
the given "time of day" value (as returned by `core.get_timeofday`).
|
||||
|
@ -5979,8 +5982,8 @@ Utilities
|
|||
* `width`: Width of the image
|
||||
* `height`: Height of the image
|
||||
* `data`: Image data, one of:
|
||||
* array table of ColorSpec, length must be width*height
|
||||
* string with raw RGBA pixels, length must be width*height*4
|
||||
* array table of ColorSpec, length must be `width * height`
|
||||
* string with raw RGBA pixels, length must be `width * height * 4`
|
||||
* `compression`: Optional zlib compression level, number in range 0 to 9.
|
||||
The data is one-dimensional, starting in the upper left corner of the image
|
||||
and laid out in scanlines going from left to right, then top to bottom.
|
||||
|
@ -7660,6 +7663,49 @@ Misc.
|
|||
* Example: `deserialize('print("foo")')`, returns `nil`
|
||||
(function call fails), returns
|
||||
`error:[string "print("foo")"]:1: attempt to call global 'print' (a nil value)`
|
||||
* `core.encode_network(format, ...)`: Encodes numbers and strings in binary
|
||||
format suitable for network transfer according to a format string.
|
||||
* Each character in the format string corresponds to an argument to the
|
||||
function. Possible format characters:
|
||||
* `b`: Signed 8-bit integer
|
||||
* `h`: Signed 16-bit integer
|
||||
* `i`: Signed 32-bit integer
|
||||
* `l`: Signed 64-bit integer
|
||||
* `B`: Unsigned 8-bit integer
|
||||
* `H`: Unsigned 16-bit integer
|
||||
* `I`: Unsigned 32-bit integer
|
||||
* `L`: Unsigned 64-bit integer
|
||||
* `f`: Single-precision floating point number
|
||||
* `s`: 16-bit size-prefixed string. Max 64 KB in size
|
||||
* `S`: 32-bit size-prefixed string. Max 64 MB in size
|
||||
* `z`: Null-terminated string. Cannot have embedded null characters
|
||||
* `Z`: Verbatim string with no size or terminator
|
||||
* ` `: Spaces are ignored
|
||||
* Integers are encoded in big-endian format, and floating point numbers are
|
||||
encoded in IEEE-754 format. Note that the full range of 64-bit integers
|
||||
cannot be represented in Lua's doubles.
|
||||
* If integers outside of the range of the corresponding type are encoded,
|
||||
integer wraparound will occur.
|
||||
* If a string that is too long for a size-prefixed string is encoded, it
|
||||
will be truncated.
|
||||
* If a string with an embedded null character is encoded as a null
|
||||
terminated string, it is truncated to the first null character.
|
||||
* Verbatim strings are added directly to the output as-is and can therefore
|
||||
have any size or contents, but the code on the decoding end cannot
|
||||
automatically detect its length.
|
||||
* `core.decode_network(format, data, ...)`: Decodes numbers and strings from
|
||||
binary format made by `core.encode_network()` according to a format string.
|
||||
* The format string follows the same rules as `core.encode_network()`.
|
||||
The decoded values are returned as individual values from the function.
|
||||
* `Z` has special behavior; an extra argument has to be passed to the
|
||||
function for every `Z` specifier denoting how many characters to read.
|
||||
To read all remaining characters, use a size of `-1`.
|
||||
* If the end of the data is encountered while still reading values from the
|
||||
string, values of the correct type will still be returned, but strings of
|
||||
variable length will be truncated, and numbers and verbatim strings will
|
||||
use zeros for the missing bytes.
|
||||
* If a size-prefixed string has a size that is greater than the maximum, it
|
||||
will be truncated and the rest of the characters skipped.
|
||||
* `core.compress(data, method, ...)`: returns `compressed_data`
|
||||
* Compress a string of data.
|
||||
* `method` is a string identifying the compression method to be used.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue