Shared

table.focusedArray

Function to filter indexes in an array of tables with common value(s)

function HRLib.table.focusedArray(
    array: table<string, any>[],
    focus: table<string, any>,
    cb: fun(i: integer, curr: any)?
)

Parameters description

  • array - the array to filter the indexes from

  • focus - the table that includes the filter values

  • cb - the function that is being triggered when a match is found

Example

local array = {
    {
        ownerName = 'player_1',
        cashBalance = 2500
    },
    {
        ownerName = 'player_2',
        cashBalance = 6000
    },
    {
        ownerName = 'player_1',
        cashBalance = 1050
    }
}

HRLib.table.focusedArray(array, { ownerName = 'player_1' }, function(_, curr)
    print(curr.cashBalance)
end) -- the output is two printed values, 2500 and 1050

table.focusedHash

Function to filter keys in a hash table of arrays with common values in the arrays

Parameters description

  • hash - the hash table to filter the keys from

  • focus - the table that includes the filter values or any value to find match with the values from the array

  • cb - the function that is being triggered when a match is found

Example 1

Example 2

table.getHashLength

Function to get the number of keys with values in a hash table (if in any scenario you're gonna need it)

Parameters description

  • hash - the hash table to get the length of

table.find

Function to values in any table and different kinds of value

Parameters description

  • tbl - the table to search the value in

  • value - the value to search a match with

  • returnIndex - sets whether or not the index should be returned

  • isValueKey - sets whether or not the function should be focused on finding a key match instead of value match

  • returnUnderIndex - sets whether or not the underIndex should be returned if there is underIndex (not tested, not completely done logic)

Return description

  • isFound - contains the status (is a match found or not)

  • index - contains the index(es) of the given table where the match is found (only available if returnIndex is true)

  • underIndex - contains a string of the underIndex(es) (only available if returnUnderIndex is true) (not tested, don't recommend to use before fixing its logic and test it)

Example 1

Example 2

Example 3

table.deepclone

Function to make a deepclone of a table so its changes won't change the main one

Parameters description

  • tbl - the table to make the deepclone of

  • dontCopyMetatable - sets whether or not if a metatable exists of the given table, it should be copied

cloneStateBag

Function to clone a state bag so you can't lose its value even after it's removed

Parameters description

  • bagName - the state bag name to clone

table.compare

Function to compare if all values of two tables are same (like tbl1 == tb2 it works with deepcloned tables, because otherwise they won't match because their table identifiers are different)

Parameters description

  • tbl1 - the first table for the match

  • tbl2 - the second table for the match

  • noKeyCompare - sets whether or not the function should compare and with keys or not (true to compare tables only with their values, false to compare keys too)

table.getKeys

Function to get a table's keys in an array of strings or multiple values

Parameters description

  • tbl - the table to get the keys of

  • isArray - sets whether or not the return value must be in array format or not

table.toString

Function to convert lua tables into visible strings that can be loaded via load function, (helpful for .lua metadata files)

Parameters description

  • tbl - the target table to convert to string

  • indent - sets whether or not the string should include new rows, tabs and so forth just like the lua tables usually look when they're being created or the string should include the table on one row.

  • rowsSpace - the number of new rows between values declaration (by default it's 1)

Last updated