⌂ 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. See NEP 20.
const sharedbytes = nupp . mem . sharedbytes
const region = sharedbytes . copy ( "hello, region" )
const hello = region : slice ( 1 , 5 )
assert ( hello : size ( ) == 5 and hello : text ( ) == "hello" )
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:
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 one engine-owned block.
Functions Function Kind Description builderfunction Opens an empty builder. copyfunction Copies text once into an engine-owned region. 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.
Methods
append
Appends the chunk's bytes to the builder's storage.
Arguments Name Type Description ?sharedbytes . Builder ?string
Returns
Raises
reserve
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
commit
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
freeze
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
drop
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.
Methods
drop
drop : nosuspend function ( takes self : sharedbytes . BuilderToken ) : nil
Arguments
Returns
Regionrecord
record sharedbytes . Region
size : nosuspend function ( sharedbytes . Region ) : integer
slice : function ( sharedbytes . Region , integer , integer ) : sharedbytes . Region
view : function ( borrows self : sharedbytes . Region , integer ? , integer ? ) : span . ByteSpan borrows ( self )
viewAs : function < T > ( borrows self : sharedbytes . Region , ctype < T > ) : span . Span < T > borrows ( self )
text : nosuspend function ( sharedbytes . Region ) : string
end
An immutable extent of one engine-owned block. Crossing a worker boundary moves a reference, never the bytes; reading happens in place through a borrowed byte view, and text is the one explicit copy into a Lua state.
Methods
size
size : nosuspend function ( sharedbytes . Region ) : integer
How many bytes the region holds.
Arguments Name Type Description ?sharedbytes . Region
Returns
slice
slice : function ( sharedbytes . Region , integer , integer ) : sharedbytes . Region
A zero-copy region over bytes first through last of this one.
Arguments Name Type Description ?sharedbytes . Region ?integer ?integer
Returns Type Description sharedbytes . Region
Raises
view
view : function ( borrows self : sharedbytes . Region , integer ? , integer ? ) : span . ByteSpan borrows ( self )
A read-only borrowed view over the selected bytes, whole by default.
Arguments Name Type Description borrows selfsharedbytes . Region ?integer ? ?integer ?
Returns Type Description span . ByteSpan borrows ( self )
Raises
viewAs
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
text
text : nosuspend function ( sharedbytes . Region ) : string
The region's bytes copied and interned as an ordinary string.
Arguments Name Type Description ?sharedbytes . Region
Returns
Raises
Functions
sharedbytes.builderfunction
Opens an empty builder.
Returns
Raises
sharedbytes.copyfunction
function sharedbytes . copy ( text : string ) : sharedbytes . Region
Copies text once into an engine-owned region.
Arguments Name Type Description textstring
Returns Type Description sharedbytes . Region
Raises
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
Returns Type Description sharedbytes . Region
Raises
← Previous nupp.mem.pool Next → nupp.mem.soa