The bytes
module
The bytes
module provides functions for working with byte arrays (bytes objects). It also functions as the common metatable for bytes objects.
Free functions
allocate(size: number): bytes
Allocate a new bytes object with the given size.
concat(objs: list[bytes]): bytes
Concatenate a list of bytes objects into a single bytes object.
Member functions
decode(self, encoding: string = “UTF−8”): string
Decode the bytes object into a string using the given encoding. If no encoding is given, UTF−8 is used.
size(self): number
Get the length of the bytes object.
slice(self, start: number, length: number): bytes
Create a new bytes object from a slice of the current bytes object. The slice starts at the given index and has the given length.
Metamethods
__band__(self, other: bytes): bytes
Bitwise AND the bytes objects.
__bor__(self, other: bytes): bytes
Bitwise OR the bytes objects.
__bxor__(self, other: bytes): bytes
Bitwise XOR the bytes objects.
__contains__(self, needle: number): boolean
Check if the given byte is contained in the bytes object.
__eq__(self, other: bytes): boolean
Check if the bytes object is equal to the given bytes object.
__index__(self, index: number): number
Get the byte at the given index.
__iter__(self): any
Get an iterator for the bytes object.
__set__(self, index: number, value: number)
Set the byte at the given index to the given value.