Difference between revisions of "Buffer luau"
(wip) |
(wip) |
||
Line 6: | Line 6: | ||
=== Description === | === Description === | ||
This is the Luau buffer library implemented in Gideros. | This is the Luau buffer library implemented in Gideros. | ||
+ | |||
+ | A buffer is an object that represents a fixed-size mutable block of memory. The buffer library provides functions for creation and manipulation of buffer objects, providing all its functions inside the global buffer variable. | ||
+ | |||
+ | Buffer is intended to be used as a low-level binary data storage structure, replacing the uses of string.pack() and string.unpack(). Use cases include reading and writing existing binary formats, working with data in a more compact form, serialization to custom binary formats, and general work with native memory types like fixed-length integers and floats. | ||
+ | |||
+ | Many of the functions accept an offset in bytes from the start of the buffer. Offset of 0 from the start of the buffer memory block accesses the first byte. All offsets, counts and sizes should be non-negative integer numbers. If the bytes that are accessed by any read or write operation are outside the buffer memory, an error is thrown. | ||
+ | |||
+ | The read and write methods that work with integers and floats use little-endian encoding. | ||
=== Example === | === Example === | ||
Line 17: | Line 25: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | === | + | === Disclaimer === |
+ | Documentation is based on '''create.roblox.com''' documentation. | ||
+ | |||
https://luau.org/library#buffer-library</br> | https://luau.org/library#buffer-library</br> | ||
https://create.roblox.com/docs/reference/engine/libraries/buffer | https://create.roblox.com/docs/reference/engine/libraries/buffer | ||
Line 24: | Line 34: | ||
| style="width: 50%; vertical-align:top;"| | | style="width: 50%; vertical-align:top;"| | ||
=== Methods === | === Methods === | ||
− | [[buffer.create]] ''creates a buffer | + | [[buffer.create]] ''creates a buffer''<br/><!--GIDEROSMTD:buffer.create(size) creates a buffer--> |
− | [[ | + | [[buffer.fromstring]] ''creates a buffer from a string''<br/><!--GIDEROSMTD:buffer.fromstring(string) creates a buffer from a string--> |
− | [[ | + | [[buffer.tostring]] ''converts a buffer to a string''<br/><!--GIDEROSMTD:buffer.tostring(buffer) converts a buffer to a string--> |
− | [[ | + | [[buffer.len]] ''returns the size of the buffer in bytes''<br/><!--GIDEROSMTD:buffer.len(buffer) returns the size of the buffer in bytes--> |
− | [[ | + | [[buffer.read]] ''reads from the buffer''<br/><!--reads from the buffer--> |
− | [[ | + | [[buffer.write]] ''writes to the buffer''<br/><!--writes to the buffer--> |
| style="width: 50%; vertical-align:top;"| | | style="width: 50%; vertical-align:top;"| | ||
Line 35: | Line 45: | ||
=== Constants === | === Constants === | ||
|} | |} | ||
+ | |||
+ | <!--GIDEROSMTD:buffer.readi8(buffer,offset) reads an 8-bit signed integer from the buffer--> | ||
+ | <!--GIDEROSMTD:buffer.readu8(buffer,offset) reads an 8-bit unsigned integer from the buffer--> | ||
+ | <!--GIDEROSMTD:buffer.readi16(buffer,offset) reads a 16-bit signed integer from the buffer--> | ||
+ | <!--GIDEROSMTD:buffer.readu16(buffer,offset) reads a 16-bit unsigned integer from the buffer--> | ||
+ | <!--GIDEROSMTD:buffer.readi32(buffer,offset) reads a 32-bit signed integer from the buffer--> | ||
+ | <!--GIDEROSMTD:buffer.readu32(buffer,offset) reads a 32-bit unsigned integer from the buffer--> | ||
+ | <!--GIDEROSMTD:buffer.readf32(buffer,offset) reads a 32-bit floating-point value from the buffer--> | ||
+ | <!--GIDEROSMTD:buffer.readf64(buffer,offset) reads a 64-bit floating-point value from the buffer--> | ||
+ | <!--GIDEROSMTD:buffer.writei8(buffer,offset,value) writes an 8-bit signed integer to the buffer--> | ||
+ | <!--GIDEROSMTD:buffer.writeu8(buffer,offset,value) writes an 8-bit unsigned integer to the buffer--> | ||
+ | <!--GIDEROSMTD:buffer.writei16(buffer,offset,value) writes a 16-bit signed integer to the buffer--> | ||
+ | <!--GIDEROSMTD:buffer.writeu16(buffer,offset,value) writes a 16-bit unsigned integer to the buffer--> | ||
+ | <!--GIDEROSMTD:buffer.writei32(buffer,offset,value) writes a 32-bit signed integer to the buffer--> | ||
+ | <!--GIDEROSMTD:buffer.writeu32(buffer,offset,value) writes a 32-bit unsigned integer to the buffer--> | ||
+ | <!--GIDEROSMTD:buffer.writef32(buffer,offset,value) writes a 32-bit floating-point value to the buffer--> | ||
+ | <!--GIDEROSMTD:buffer.writef64(buffer,offset,value) writes a 64-bit floating-point value to the buffer--> | ||
{{GIDEROS IMPORTANT LINKS}} | {{GIDEROS IMPORTANT LINKS}} |
Revision as of 01:55, 6 February 2025
Supported platforms:
Available since: Gideros 2025.1
Description
This is the Luau buffer library implemented in Gideros.
A buffer is an object that represents a fixed-size mutable block of memory. The buffer library provides functions for creation and manipulation of buffer objects, providing all its functions inside the global buffer variable.
Buffer is intended to be used as a low-level binary data storage structure, replacing the uses of string.pack() and string.unpack(). Use cases include reading and writing existing binary formats, working with data in a more compact form, serialization to custom binary formats, and general work with native memory types like fixed-length integers and floats.
Many of the functions accept an offset in bytes from the start of the buffer. Offset of 0 from the start of the buffer memory block accesses the first byte. All offsets, counts and sizes should be non-negative integer numbers. If the bytes that are accessed by any read or write operation are outside the buffer memory, an error is thrown.
The read and write methods that work with integers and floats use little-endian encoding.
Example
-- creates a buffer initialized to the contents of the string
local str = "Hello Gideros!"
b = buffer.fromstring(str)
print(buffer.len(b))
-- returns the buffer data as a string
print(buffer.tostring(b))
Disclaimer
Documentation is based on create.roblox.com documentation.
https://luau.org/library#buffer-library
https://create.roblox.com/docs/reference/engine/libraries/buffer
Methodsbuffer.create creates a buffer |
EventsConstants |