Buffer
Internal FFI interoperability helpers for the Sodium package.
Wraps stdPolyfills.ffi into named operations so higher-level modules never interact with it directly.
Summary
Functions
Buffer.alloc(size: number) → FFIPointerBuffer.dupe(buf: buffer) → FFIPointerBuffer.free(pointer: FFIPointer)Buffer.read(pointer: FFIPointer, length: number) → bufferBuffer.getNull() → FFIPointerBuffer.allocSlot() → FFIPointerBuffer.readRawU64(value: any) → numberBuffer.readSizeT(slot: FFIPointer) → numberBuffer.toCString(s: string) → FFIPointerBuffer.fromCString(pointer: FFIPointer, maxLength: number) → stringFunctions
Section titled “Functions”Buffer . alloc ( size ) -> FFIPointer
Parameters
| size: number |
Returns
| FFIPointer |
Buffer . dupe ( buf ) -> FFIPointer
Parameters
| buf: buffer |
Returns
| FFIPointer |
Buffer . free ( pointer ) -> ()
Parameters
| pointer: FFIPointer |
Buffer . read ( pointer , length ) -> buffer
Reads length bytes from pointer into a freshly created Luau buffer.
Parameters
| pointer: FFIPointer | |
| length: number |
Returns
| buffer |
getNull
Section titled “getNull”Buffer . getNull ( ) -> FFIPointer
Returns a null FFI pointer for optional pointer arguments.
Returns
| FFIPointer |
allocSlot
Section titled “allocSlot”Buffer . allocSlot ( ) -> FFIPointer
Allocates an 8-byte, 8-aligned slot for size_t * output parameters.
Returns
| FFIPointer |
readRawU64
Section titled “readRawU64”Buffer . readRawU64 ( value ) -> number
Reads a u64 return that may come back as a plain Luau number or a two-word buffer.
Parameters
| value: any |
Returns
| number |
readSizeT
Section titled “readSizeT”Buffer . readSizeT ( slot ) -> number
Reads a size_t value written into an 8-byte slot by a libsodium function.
Parameters
| slot: FFIPointer |
Returns
| number |
toCString
Section titled “toCString”Buffer . toCString ( s ) -> FFIPointer
Copies s into a null-terminated C string in FFI memory; caller must free the result.
Parameters
| s: string |
Returns
| FFIPointer |
fromCString
Section titled “fromCString”Buffer . fromCString ( pointer , maxLength ) -> string
Reads a null-terminated C string from an FFI pointer into a Luau string, up to maxLength bytes.