⌂ Modules nupp nupp.mem nupp.mem.sharedbytes nupp.mem.sharedbytes
Engine-owned immutable byte regions.
A region names an extent of one reference-counted engine block. It crosses worker boundaries by reference, slices without copying, and is read in place through a borrowed nupp.mem.span byte view; converting it to a Lua string is one explicit call.
const sharedbytes = nupp . mem . sharedbytes
const region = sharedbytes . copy ( "hello, region" )
const hello = region : slice ( 0 , 5 )
assert ( hello : length ( ) == 5 and hello : toString ( ) == "hello" )
A region is storage, so its positions are zero-based offsets and counts, as a nupp.io.Buffer 's are: slice(offset, count) and view(offset, count) name count bytes starting offset bytes in.
A producer that has bytes only behind a pointer writes into builder storage directly through a reserve-and-commit pair, with no intermediate chunk string:
const sharedbytes = nupp . mem . sharedbytes
local builder = sharedbytes . newBuilder ( )
with writer = builder : reserve ( 5 ) do
for index = 1 , 5 do
writer [ index ] = 64 + index
end
end
builder : commit ( 5 )
builder : append ( "!" )
assert ( builder : freeze ( ) : toString ( ) == "ABCDE!" )
Module contents Types Type Kind Description Builderrecord A growable engine allocation that becomes a region when frozen. BuilderTokeninterface An affine accumulator of engine storage. Regionrecord An immutable extent of an engine-owned block.
Functions Function Kind Description copyfunction Copies text once into an engine-owned region. newBuilderfunction Opens an empty builder. readFilefunction Reads a whole file directly into an engine-owned region, with no intermediate Lua string for the payload.
Types
Builderrecord
A growable engine allocation that becomes a region when frozen.
Members Name Kind Description appendmethod Appends the chunk's bytes to the builder's storage. reservemethod Grows the storage and lends a checked writer over exactly count uninitialized bytes past what is already committed. commitmethod Closes the open reservation, keeping its first written bytes as content; a short read commits what arrived, and the... freezemethod Consumes the builder and transfers its allocation into a region. dropmethod Releases an unfrozen builder's storage at scope exit.
appendmethod
Appends the chunk's bytes to the builder's storage.
Arguments Name Type Description ?sharedbytes . Builder ?string
Returns
Raises Type Condition string when a reservation is open or the engine cannot grow the storage
reservemethod
reserve : function ( exclusive self : sharedbytes . Builder , integer ) : span . Writable < uint8 > borrows ( self )
Grows the storage and lends a checked writer over exactly count uninitialized bytes past what is already committed. All growth happens here, before the writer exists, and the borrow keeps every other builder operation a compile error while the writer lives, so the lent pointer cannot be invalidated. One commit closes the reservation after the writer drops.
Arguments Name Type Description exclusive selfsharedbytes . Builder ?integer
Returns Type Description span . Writable < uint8 > borrows ( self )
Raises Type Condition string when count is not a nonnegative integer, a reservation is already open, or the engine cannot grow the storage
commitmethod
commit : @ nosuspend function ( sharedbytes . Builder , integer ) : nil
Closes the open reservation, keeping its first written bytes as content; a short read commits what arrived, and the surplus returns to capacity for the next reservation.
Arguments Name Type Description ?sharedbytes . Builder ?integer
Returns
Raises Type Condition string when written is not a nonnegative integer, no reservation is open, or written exceeds it
freezemethod
freeze : @ nosuspend function ( takes self : sharedbytes . Builder ) : sharedbytes . Region
Consumes the builder and transfers its allocation into a region.
Arguments Name Type Description takes selfsharedbytes . Builder
Returns Type Description sharedbytes . Region
Raises Type Condition string when the builder was already frozen or a reservation is open, because sealing would silently drop bytes a producer may have written
dropmethod
drop : @ nosuspend function ( takes self : sharedbytes . Builder ) : nil
Releases an unfrozen builder's storage at scope exit.
Arguments Name Type Description takes selfsharedbytes . Builder
Returns
BuilderTokeninterface
An affine accumulator of engine storage. Appending grows one private allocation, and freezing transfers it into a region without copying.
Members Name Kind Description dropmethod
dropmethod
drop : @ nosuspend function ( takes self : sharedbytes . BuilderToken ) : nil
Arguments
Returns
Regionrecord
An immutable extent of an engine-owned block. Crossing a worker boundary moves a reference, never the bytes; reading happens in place through a borrowed byte view, and toString is the one explicit copy into a Lua state.
Members Name Kind Description lengthmethod How many bytes the region holds. slicemethod A zero-copy region over count bytes starting offset bytes into this one. viewmethod A read-only borrowed view over count bytes starting offset bytes in, the whole region by default. viewAsmethod A checked zero-copy view of the complete region as physical elements. toStringmethod The region's bytes copied and interned as an ordinary string.
lengthmethod
length : @ nosuspend function ( sharedbytes . Region ) : integer
How many bytes the region holds.
Arguments Name Type Description ?sharedbytes . Region
Returns
slicemethod
slice : function ( sharedbytes . Region , integer , integer ) : sharedbytes . Region
A zero-copy region over count bytes starting offset bytes into this one.
Arguments Name Type Description ?sharedbytes . Region ?integer ?integer
Returns Type Description sharedbytes . Region
Raises Type Condition string when the extent falls outside the region
viewmethod
view : function ( borrows self : sharedbytes . Region , integer ? , integer ? ) : span . ByteSpan borrows ( self )
A read-only borrowed view over count bytes starting offset bytes in, the whole region by default.
Arguments Name Type Description borrows selfsharedbytes . Region ?integer ? ?integer ?
Returns Type Description span . ByteSpan borrows ( self )
Raises Type Condition string when the extent falls outside the region
viewAsmethod
viewAs : function < T > ( borrows self : sharedbytes . Region , ctype < T > ) : span . Span < T > borrows ( self )
A checked zero-copy view of the complete region as physical elements.
Arguments Name Type Description borrows selfsharedbytes . Region ?ctype < T >
Returns Type Description span . Span < T > borrows ( self )
Raises Type Condition string when the region is not aligned or is not a whole number of elements
toStringmethod
toString : @ nosuspend function ( sharedbytes . Region ) : string
The region's bytes copied and interned as an ordinary string.
Arguments Name Type Description ?sharedbytes . Region
Returns
Raises Type Condition string when the region's engine storage has been released
Functions
sharedbytes.copyfunction
Copies text once into an engine-owned region.
Arguments Name Type Description textstring
Returns Type Description sharedbytes . Region
Raises Type Condition string when the engine cannot allocate the region
sharedbytes.newBuilderfunction
Opens an empty builder.
Returns
Raises Type Condition string when the engine cannot allocate the builder
sharedbytes.readFilefunction
Reads a whole file directly into an engine-owned region, with no intermediate Lua string for the payload.
Arguments Name Type Description pathstring the native path of the file to read
Returns Type Description sharedbytes . Region ? the region, or nil when the file cannot be opened, sized, or read
string ? why it could not be read, when unsuccessful
← Previous nupp.mem.representation.spi Next → nupp.mem.soa