Difference between revisions of "Buffer luau"

From GiderosMobile
(wip)
(wip)
Line 34: Line 34:
 
| style="width: 50%; vertical-align:top;"|
 
| style="width: 50%; vertical-align:top;"|
 
=== Methods ===
 
=== Methods ===
 +
[[buffer.copy]] ''copies bytes between buffers''<br/><!--GIDEROSMTD:buffer.copy(targetbuffer,targetoffset,sourcebuffer,sourceoffset,count) copies bytes between buffers-->
 
[[buffer.create]] ''creates a buffer''<br/><!--GIDEROSMTD:buffer.create(size) creates a buffer-->
 
[[buffer.create]] ''creates a buffer''<br/><!--GIDEROSMTD:buffer.create(size) creates a buffer-->
 +
[[buffer.fill]] ''sets a region of the buffer memory to some 8-bit unsigned integer value''<br/><!--GIDEROSMTD:buffer.fill(buffer,offset,value,count) sets a region of the buffer memory to some 8-bit unsigned integer value-->
 
[[buffer.fromstring]] ''creates a buffer from a string''<br/><!--GIDEROSMTD:buffer.fromstring(string) creates a buffer from a string-->
 
[[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.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.read]] ''reads from the buffer''<br/><!--reads from the buffer-->
 +
[[buffer.readstring]] ''reads a string from the buffer''<br/><!--GIDEROSMTD:buffer.readstring(buffer,offset,count) reads a string from the buffer-->
 +
[[buffer.tostring]] ''converts a buffer to a string''<br/><!--GIDEROSMTD:buffer.tostring(buffer) converts a buffer to a string-->
 
[[buffer.write]] ''writes to the buffer''<br/><!--writes to the buffer-->
 
[[buffer.write]] ''writes to the buffer''<br/><!--writes to the buffer-->
 +
[[buffer.writestring]] ''writes a string to the buffer''<br/><!--GIDEROSMTD:buffer.writestring(buffer,offset,value,count) writes a string to the buffer-->
  
 
| style="width: 50%; vertical-align:top;"|
 
| style="width: 50%; vertical-align:top;"|

Revision as of 02:10, 6 February 2025

Supported platforms: Platform android.pngPlatform ios.pngPlatform mac.pngPlatform pc.pngPlatform linux.png
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

Methods

buffer.copy copies bytes between buffers
buffer.create creates a buffer
buffer.fill sets a region of the buffer memory to some 8-bit unsigned integer value
buffer.fromstring creates a buffer from a string
buffer.len returns the size of the buffer in bytes
buffer.read reads from the buffer
buffer.readstring reads a string from the buffer
buffer.tostring converts a buffer to a string
buffer.write writes to the buffer
buffer.writestring writes a string to the buffer

Events

Constants