Difference between revisions of "Buffer.copy"

From GiderosMobile
(Created page with "__NOTOC__ '''Available since:''' Gideros 2025.1<br/> '''Class:''' buffer_luau<br/> === Description === Copies ''count'' bytes from ''source'' starting at offset ''sourceO...")
 
 
Line 16: Line 16:
 
'''source''': (buffer) buffer to take the data from<br/>
 
'''source''': (buffer) buffer to take the data from<br/>
 
'''sourceOffset''': (number) offset from the beginning of the buffer memory, starting from 0 '''optional''' default = 0<br/>
 
'''sourceOffset''': (number) offset from the beginning of the buffer memory, starting from 0 '''optional''' default = 0<br/>
'''count''': (number) Number of bytes to copy '''optional''' if omitted, the whole source data starting from sourceOffset is taken<br/>
+
'''count''': (number) number of bytes to copy '''optional''' if omitted, the whole source data starting from sourceOffset is taken<br/>
  
 
=== Example ===
 
=== Example ===

Latest revision as of 05:57, 6 February 2025

Available since: Gideros 2025.1
Class: buffer_luau

Description

Copies count bytes from source starting at offset sourceOffset into the target at targetOffset.

buffer.copy(target,targetOffset,source,sourceOffset,count)

It's possible for source and target to be the same. Copying an overlapping region inside the same buffer acts as if the source region is copied into a temporary buffer and then that buffer is copied over to the target.

Parameters

target: (buffer) buffer to copy data into
targetOffset: (number) offset from the beginning of the buffer memory, starting from 0
source: (buffer) buffer to take the data from
sourceOffset: (number) offset from the beginning of the buffer memory, starting from 0 optional default = 0
count: (number) number of bytes to copy optional if omitted, the whole source data starting from sourceOffset is taken

Example

local b: buffer = buffer.create(16)
local count = 7
local b2: buffer = buffer.create(count)
local targetOffset, sourceOffset = 0, 2
buffer.copy(b2, targetOffset, b, sourceOffset, count)
print(buffer.tostring(b2))