Table - AlsoGhostglowDev/Ghost-s-Utilities GitHub Wiki

lua-addons/table.lua

An addon to Lua's standard table library.

This addon can be declared with the name "table" since it does NOT override the Lua's standard table library.

local table = require 'ghostutil.lua-addons.table'

Methods

isdictionary(tbl: table|dictionary): boolean

Checks if the passed table is a dictionary.
(Shortcut to helper.isDict. Result may not be accurate)

Parameters:

  • tbl: The table to check.

Returns: true if the passed table is a dictionary.

─────────────────────────

getkeys(dict: dictionary<t, dynamic>): table<t>

Fetches the keys in a dictionary.
(Shortcut to helper.getKeys. Aliases: table.keys)

Parameters:

  • dict: The dictionary to fetch the keys from.

Returns: Table containing the keys of the passed dictionary.

─────────────────────────

indexof(tbl: table<dynamic>, el: dynamic): number

Fetches the index of the first element matching with el found in tbl
(Shortcut to helper.findIndex)

Parameters:

  • tbl: The table to check.
  • el: The element to find.

Returns: The index of the first found el in tbl. Returns 0 if failed.

─────────────────────────

keyof(dict: dictionary<t, dynamic>, el: dynamic): t

Fetches the key of the first element matching with el found in dict.
(Shortcut to helper.findKey)

Parameters:

  • dict: The dictionary to check.
  • el: The element of the key to find.

Returns: The key of the first found el in dict. Returns nil if failed.

─────────────────────────

contains(tbl: table|dictionary, el: dynamic): boolean

Checks if the passed table has el as one of it's values.
(Shortcut to helper.existsFromTable. Aliases: table.exists, table.has, table.hasvalue)

Parameters:

  • tbl: The table to check.
  • el: The element to look for.

Returns: true if el is one of tbl's values.

─────────────────────────

containskey(dict: dictionary<t, dynamic>, key: t): boolean

Checks if the passed dictionary has the corresponding key.
(Shortcut to helper.keyExists. Aliases: table.keyexists, table.haskey)

Parameters:

  • dict: The dictionary to check.
  • key: The key to look for.

Returns: true if key is one of dict's keys.

─────────────────────────

rawsetdict(dict: dictionary, path: string, value: dynamic): void

Similar to Lua's rawset function, this sets the value of a dictionary with key path to value without invoking any metamethods, specifically bypassing the __newindex metamethod.
(This is an in-place function directly modifying dict's structure. Shortcut to helper.rawsetDict)

Parameters:

  • dict: The target dictionary to set.
  • path: The key to set, seperated with . for nested dictionaries.
  • value: The value to set it to.

─────────────────────────

rawgetdict(dict: dictionary, path: string): dynamic

Similar to Lua's rawget function, this fetches the value of a dictionary with key path without invoking any metamethods, specifically bypassing the __index metamethod.
(Shortcut to helper.rawgetDict)

Parameters:

  • dict: The target dictionary to fetch from.
  • path: The key to set, seperated with . for nested dictionaries.

Returns: Fetches the value that corresponds to the given path in dict.

─────────────────────────

getdictlength(dict: dictionary): number

Fetches the length of a dictionary.
(Shortcut to helper.getDictLength. Aliases: table.getdictlen)

Parameters:

  • dict: The dictionary to get the length from.

Returns: The passed dictionary's length.

─────────────────────────

fill(tbl: table<dynamic>, value: dynamic, len: number): table<dynamic>

Fills the passed table with value until tbl's length matches len.
(This is an in-place function directly modifying tbl's structure. Shortcut to helper.fillTable)

Parameters:

  • tbl: The table to fill.
  • value: The fill value.
  • len: The target table length.

Returns: The filled table for chaining.

─────────────────────────

resize(tbl: table<dynamic>, len: number): table<dynamic>

Resizes the passed table down to the given length.

(This is an in-place function directly modifying tbl's structure. Shortcut to helper.resizeTable)

Parameters:

  • tbl: The table to resize.
  • len: The target length to resize to.

Returns: The resized table for chaining.

─────────────────────────

arraycomp(from: number, to: number, fn: number->dynamic): table<dynamic>

Array comprehension made in Lua.
(Shortcut to helper.arrayComprehension)

Parameters:

  • from: Starting index.
  • to: End index.
  • fn: Function passing the index for the user to return the value to set for that index.

Returns: The newly made table.

─────────────────────────

dictcomp(keys: table<t1>, fn: t1->t2): dictionary<t1, t2>

Map comprehension made in Lua.
(Shortcut to helper.mapComprehension)

Parameters:

  • keys: The keys that the dictionary should have.
  • fn: Function passing the key for the user to return the value to map to that key.

Returns: The newly made dictionary.

─────────────────────────

merge(t1: table<t>, t2: table<t>): table<t>

Concatenates t1 with t2 into one singular table.
(This is an in-place function directly modifying t1's structure. Shortcut to helper.concat)

Parameters:

  • t1: The initial table.
  • t2: The table to merge with.

Returns: The merged table for chaining.

─────────────────────────

mergedict(d1: dictionary<t1, t2>, d2: dictionary<t1, t2>, ?override: boolean): dictionary<t1, t2>

Concatenates d1 with d2 into one singular dictionary.
(This is an in-place function directly modifying d1's structure. Shortcut to helper.concatDict)

Parameters:

  • d1: The initial dictionary.
  • d2: The dictionary to merge with.
  • override (optional): Whether to override existing value of the same key from d1 to d2's value if there's any, defaults to true.

Returns: The merged dictionary for chaining.

─────────────────────────

filter(tbl: table|dictionary, fn: dynamic->boolean): table|dictionary

Creates a new table by filtering the contents of tbl using fn.

Parameters:

  • tbl: The table/dictionary to filter.
  • fn: A function called for each key (or index). It should return true to keep the value, or false to exclude it from the resulting table.

Returns: The filtered table.

─────────────────────────

pop(tbl: table<t>): t

Removes the last element of tbl.
(This is an in-place function directly modifying tbl's structure.)

Parameters:

  • tbl: The table to pop.

Returns: The removed element.

─────────────────────────

shift(tbl: table<t>): t

Removes the first element of tbl.
(This is an in-place function directly modifying tbl's structure.)

Parameters:

  • tbl: The table to shift.

Returns: The removed element.

─────────────────────────

reverse(tbl: table): table

Reverses the contents of tbl.
(This is an in-place function directly modifying tbl's structure.)

Parameters:

  • tbl: The table to reverse.

Returns: The reversed table for chaining.

─────────────────────────

clone(tbl: table|dictionary): table|dictionary

Makes a deep-copy of tbl without shared references.
(Aliases: table.copy)

Parameters:

  • tbl: The table to clone.

Returns: The cloned table/dictionary.



GhostUtil 3.0.0Docs 3.0.0, Revision 1

a Lua Library made by GhostglowDev; for Psych Engine
© 2025 GhostglowDevGhost's Utilities
Licensed under the MIT License.

⚠️ **GitHub.com Fallback** ⚠️