-
-
Notifications
You must be signed in to change notification settings - Fork 2
Library: Table
The Lua programming language relies on Tables to simulate Arrays, Objects, and Classes, highlighting their significant utility. Our modifications to the inherent table
module were necessary to address challenges encountered when inserting, removing, or unpacking indices associated with nil values. While this issue has been resolved in more recent Lua versions, MTA remains constrained to an earlier version for compatibility purposes.
It's already imported by default whenever you import assetify
. You need to declare the below globally only once:
loadstring(exports.assetify_library:import())()
ℹ️ Our extensions are designed with backward compatibility in mind; your existing code is expected to function as intended. Nonetheless, we recommend transitioning to newer syntax.
-
✨ Returns the length of a specified table.
local int: result = table.length( table: baseTable )
-
✨ Encapsulates all specified values into an ordered table.
✨ Retainsnil
values as well!local table: result = table.pack( ~: ...values )
-
✨ Extracts all ordered values from a specified table.
✨ Retainsnil
values as well!local ~: ...values = table.unpack( table: baseTable, int: length --Optional )
-
✨ Encodes specified table into a valid string format.
local string: baseString = table.encode( table: baseTable, string: encoding --Optional: Defaults to vcl if unspecified. Supported encodings: vcl & json )
-
✨ Decodes a valid encoded string back into a table.
local table: baseTable = table.decode( table: baseString, string: encoding --Optional: Defaults to vcl if unspecified. Supported encodings: vcl & json )
-
✨ Creates a copy of an existing table.
local table: result = table.clone( table: baseTable, bool: isRecursive --Optional: When enabled, this recursively clones all nested tables )
-
✨ Obtains a human-readable representation of the table.
local string: result = table.inspect( table: baseTable, bool: showHidden, --Optional: When enabled, this recursively displays all available data int: limit --Optional: Sets a recursive limit, defaulting to 1 )
-
✨ Outputs a human-readable representation of the table.
local string: result = table.print( table: baseTable, bool: showHidden, --Optional: When enabled, this recursively displays all available metadata (if any) int: limit --Optional: Sets a recursive limit, defaulting to 1 )
-
✨ Retrieves a list of keys from an existing table.
--Note: This retrieves keys, including those assigned nil/false values! local table: result = table.keys( table: baseTable )
-
✨ Inserts a specified value into an existing table.
--Syntax #1: local bool: result = table.insert( table: baseTable, int: index, ~: value, --Can be of any type, including nil/false. All adjacent elements will be shifted to maintain order bool: isForced --Optional: When enabled, it forces the value to be inserted ) --Syntax #2: --Note: This syntax appends values at the end of the table by default. local bool: result = table.insert( table: baseTable, ~: value --Can be of any type, including nil/false. All adjacent elements will be shifted to maintain order )
-
✨ Removes a specified index from an existing table.
local ~: value = table.remove( table: baseTable, int: index --Operates on indices with any value type, including nil/false. All adjacent elements will be pulled up to maintain order )
-
✨ Iterates through the numeric indices of the table while retrieving their values.
--Note: This works even for indices assigned nil/false values! local bool: result = table.forEach( table: baseTable, function: exec(int: index, ~: value) )