Table - AlsoGhostglowDev/Ghost-s-Utilities GitHub Wiki
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'isdictionary(tbl: table|dictionary): booleanChecks 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): numberFetches 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): tFetches 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): booleanChecks 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): booleanChecks 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): voidSimilar 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): dynamicSimilar 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): numberFetches 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 fromd1tod2's value if there's any, defaults totrue.
Returns: The merged dictionary for chaining.
─────────────────────────
filter(tbl: table|dictionary, fn: dynamic->boolean): table|dictionaryCreates 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 returntrueto keep the value, orfalseto exclude it from the resulting table.
Returns: The filtered table.
─────────────────────────
pop(tbl: table<t>): tRemoves 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>): tRemoves 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): tableReverses 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|dictionaryMakes 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.0 • Docs 3.0.0, Revision 1
a Lua Library made by GhostglowDev; for Psych Engine
© 2025 GhostglowDev — Ghost's Utilities
Licensed under the MIT License.