Skip to main content

DataModule

Description:

  Provides functionality for creating and transforming data.

newByteData

Type: Function.

Description:

  Creates a new Data object containing arbitrary bytes.

-- Data:getPointer along with LuaJIT's FFI can be used to manipulate the contents of the ByteData object after it has been created.

Signature:

newByteData: function(size: integer): ByteData

Parameters:

ParameterTypeDescription
sizeintegerThe size in bytes of the new Data object. (Default: data:getSize().)

Returns:

Return TypeDescription
ByteDatabytedata — The new Data object.

newByteData

Type: Function.

Description:

  Creates a new Data object containing arbitrary bytes.

-- Data:getPointer along with LuaJIT's FFI can be used to manipulate the contents of the ByteData object after it has been created.

Signature:

newByteData: function(bytes: string): ByteData

Parameters:

ParameterTypeDescription
bytesstringThe size in bytes of the new Data object.

Returns:

Return TypeDescription
ByteDatabytedata — The new Data object.

newByteData

Type: Function.

Description:

  Creates a new Data object containing arbitrary bytes.

-- Data:getPointer along with LuaJIT's FFI can be used to manipulate the contents of the ByteData object after it has been created.

Signature:

newByteData: function(data: Data, offset?: integer, size?: integer): ByteData

Parameters:

ParameterTypeDescription
dataDataThe existing Data object to copy.
offsetintegerThe offset of the subsection to copy, in bytes. (Default: 0.)
sizeintegerThe size in bytes of the new Data object.

Returns:

Return TypeDescription
ByteDatabytedata — The new Data object.

newDataView

Type: Function.

Description:

  Creates a new Data referencing a subsection of an existing Data object. Overload details:

  1. Data:getString and Data:getPointer will return the original Data object's contents, with the view's offset and size applied.

Signature:

newDataView: function(data: any, offset: integer, size: integer): DataView

Parameters:

ParameterTypeDescription
dataanyThe Data object to reference.
offsetintegerThe offset of the subsection to reference, in bytes.
sizeintegerThe size in bytes of the subsection to reference.

Returns:

Return TypeDescription
DataViewThe new Data view.

encode

Type: Function.

Description:

  Encode Data or a string to a Data or string in one of the EncodeFormats.

Signature:

encode: function(container: string, format: EncodeFormat, source: string | Data, line_length?: integer): string

Parameters:

ParameterTypeDescription
containerstringWhat type to return the encoded data as.
formatEncodeFormatThe format of the output data.
sourcestringData
line_lengthintegerThe maximum line length of the output. Only supported for base64, ignored if 0. (Default: 0.)

Returns:

Return TypeDescription
stringencoded — ByteData/string which contains the encoded version of source.

encode

Type: Function.

Description:

  Encode Data or a string to a Data or string in one of the EncodeFormats.

Signature:

encode: function(container: string, format: EncodeFormat, source: string | Data, line_length?: integer): ByteData

Parameters:

ParameterTypeDescription
containerstringWhat type to return the encoded data as.
formatEncodeFormatThe format of the output data.
sourcestringData
line_lengthintegerThe maximum line length of the output. Only supported for base64, ignored if 0. (Default: 0.)

Returns:

Return TypeDescription
ByteDataencoded — ByteData/string which contains the encoded version of source.

decode

Type: Function.

Description:

  Decode Data or a string from any of the EncodeFormats to Data or string.

Signature:

decode: function(container: string, format: EncodeFormat, source: string | Data): string

Parameters:

ParameterTypeDescription
containerstringWhat type to return the decoded data as.
formatEncodeFormatThe format of the input data.
sourcestringData

Returns:

Return TypeDescription
stringdecoded — ByteData/string which contains the decoded version of source.

decode

Type: Function.

Description:

  Decode Data or a string from any of the EncodeFormats to Data or string.

Signature:

decode: function(container: string, format: EncodeFormat, source: string | Data): ByteData

Parameters:

ParameterTypeDescription
containerstringWhat type to return the decoded data as.
formatEncodeFormatThe format of the input data.
sourcestringData

Returns:

Return TypeDescription
ByteDatadecoded — ByteData/string which contains the decoded version of source.

compress

Type: Function.

Description:

  Compresses a string or data using a specific compression algorithm.

Signature:

compress: function(container: string, format: CompressionFormat, source: string | Data, level?: integer): string

Parameters:

ParameterTypeDescription
containerstringWhat type to return the compressed data as.
formatCompressionFormatThe format to use when compressing the string.
sourcestringData
levelintegerThe level of compression to use, between 0 and 9. -1 indicates the default level. The meaning of this argument depends on the compression format being used. (Default: -1.)

Returns:

Return TypeDescription
stringcompressedData — CompressedData/string which contains the compressed version of rawstring.

compress

Type: Function.

Description:

  Compresses a string or data using a specific compression algorithm.

Signature:

compress: function(container: string, format: CompressionFormat, source: string | Data, level?: integer): CompressedData

Parameters:

ParameterTypeDescription
containerstringWhat type to return the compressed data as.
formatCompressionFormatThe format to use when compressing the data.
sourcestringData
levelintegerThe level of compression to use, between 0 and 9. -1 indicates the default level. The meaning of this argument depends on the compression format being used. (Default: -1.)

Returns:

Return TypeDescription
CompressedDataCompressedData/string which contains the compressed version of data.

decompress

Type: Function.

Description:

  Decompresses a CompressedData or previously compressed string or Data object.

Signature:

decompress: function(container: string, compressed: CompressedData): string

Parameters:

ParameterTypeDescription
containerstringWhat type to return the decompressed data as.
compressedCompressedDataThe compressed data to decompress.

Returns:

Return TypeDescription
stringdecompressedData — Data/string containing the raw decompressed data.

decompress

Type: Function.

Description:

  Decompresses a CompressedData or previously compressed string or Data object.

Signature:

decompress: function(container: string, compressed: CompressedData): ByteData

Parameters:

ParameterTypeDescription
containerstringWhat type to return the decompressed data as.
compressedCompressedDataThe compressed data to decompress.

Returns:

Return TypeDescription
ByteDatadecompressedData — Data/string containing the raw decompressed data.

decompress

Type: Function.

Description:

  Decompresses a CompressedData or previously compressed string or Data object.

Signature:

decompress: function(container: string, format: CompressionFormat, source: string | Data): string

Parameters:

ParameterTypeDescription
containerstringWhat type to return the decompressed data as.
formatCompressionFormatThe format that was used to compress the given data.
sourcestringData

Returns:

Return TypeDescription
stringdecompressedData — Data/string containing the raw decompressed data.

decompress

Type: Function.

Description:

  Decompresses a CompressedData or previously compressed string or Data object.

Signature:

decompress: function(container: string, format: CompressionFormat, source: string | Data): ByteData

Parameters:

ParameterTypeDescription
containerstringWhat type to return the decompressed data as.
formatCompressionFormatThe format that was used to compress the given data.
sourcestringData

Returns:

Return TypeDescription
ByteDatadecompressedData — Data/string containing the raw decompressed data.

pack

Type: Function.

Description:

  Packs (serializes) simple Lua values.

-- This function behaves the same as Lua 5.3's string.pack.

Signature:

pack: function(container: string, format: string, values: any...): string

Parameters:

ParameterTypeDescription
containerstringWhat type to return the encoded data as.
formatstringA string determining how the values are packed. Follows the rules of Lua 5.3's string.pack format strings.
valuesany...The first value (number, boolean, or string) to serialize.

Returns:

Return TypeDescription
stringdata — Data/string which contains the serialized data.

pack

Type: Function.

Description:

  Packs (serializes) simple Lua values.

-- This function behaves the same as Lua 5.3's string.pack.

Signature:

pack: function(container: string, format: string, values: any...): ByteData

Parameters:

ParameterTypeDescription
containerstringWhat type to return the encoded data as.
formatstringA string determining how the values are packed. Follows the rules of Lua 5.3's string.pack format strings.
valuesany...The first value (number, boolean, or string) to serialize.

Returns:

Return TypeDescription
ByteDatadata — Data/string which contains the serialized data.

unpack

Type: Function.

Description:

  Unpacks (deserializes) a byte-string or Data into simple Lua values.

-- This function behaves the same as Lua 5.3's string.unpack.

Signature:

unpack: function(format: string, source: string, position?: integer): any...

Parameters:

ParameterTypeDescription
formatstringA string determining how the values were packed. Follows the rules of Lua 5.3's string.pack format strings.
sourcestringA string containing the packed (serialized) data.
positionintegerWhere to start reading in the string. Negative values can be used to read relative from the end of the string. (Default: 1.)

Returns:

Return TypeDescription
any...v1 — The first value (number, boolean, or string) that was unpacked.

unpack

Type: Function.

Description:

  Unpacks (deserializes) a byte-string or Data into simple Lua values.

-- This function behaves the same as Lua 5.3's string.unpack.

Signature:

unpack: function(format: string, source: Data, position?: integer): any...

Parameters:

ParameterTypeDescription
formatstringA string determining how the values were packed. Follows the rules of Lua 5.3's string.pack format strings.
sourceDataA Data object containing the packed (serialized) data.
positioninteger1-based index indicating where to start reading in the Data. Negative values can be used to read relative from the end of the Data object. (Default: 1.)

Returns:

Return TypeDescription
any...v1 — The first value (number, boolean, or string) that was unpacked.

getPackedSize

Type: Function.

Description:

  Gets the size in bytes that a given format used with love.data.pack will use. This function behaves the same as Lua 5.3's string.packsize. Overload details:

  1. The format string cannot have the variable-length options 's' or 'z'.

Signature:

getPackedSize: function(format: string): integer

Parameters:

ParameterTypeDescription
formatstringA string determining how the values are packed. Follows the rules of Lua 5.3's string.pack format strings.

Returns:

Return TypeDescription
integerThe size in bytes that the packed data will use.

hash

Type: Function.

Description:

  Compute the message digest of a string using a specified hash algorithm.

Signature:

hash: function(hash_function: HashFunction, source: string): string

Parameters:

ParameterTypeDescription
hash_functionHashFunctionHash algorithm to use.
sourcestringString to hash.

Returns:

Return TypeDescription
stringrawdigest — Raw message digest string.

hash

Type: Function.

Description:

  Compute the message digest of a string using a specified hash algorithm.

Signature:

hash: function(hash_function: HashFunction, source: Data): string

Parameters:

ParameterTypeDescription
hash_functionHashFunctionHash algorithm to use.
sourceDataData to hash.

Returns:

Return TypeDescription
stringrawdigest — Raw message digest string.