focusedHash

Same as focusedArray but it's a hash of arrays

Parameters description

ParameterTypeDescriptionDefault

hash

table<string, table<string, any>[]>|table<string, any>

the hash to focus in

---

focus

table|any

the focus (it might be a table of values or the value)

---

cb

fun(key: string, value: any, arrayInfo: { i: integer, curr: any })?

the callback function, triggered when a match is found in the arrays elements

---

Example

local db = {
    contextMenus = {
        {
            name = 'context1',
            colour = 'black'
        },
        {
            name = 'context2',
            colour = 'green'
        },
        {
            name = 'context3',
            colour = 'black'
        },
    },
    dialogMenus = {
        {
            name = 'dialog1',
            colour = 'black'
        },
        {
            name = 'dialog2',
            colour = 'green'
        },
    }
}

RegisterCommand('allBlackMenus', function()
    print('All Black Menus:')

    HRLib.table.focusedHash(db, { colour = 'black' }, function(key, value, arrayInfo)
        print('Menu Type:', key, '|', arrayInfo.curr.name)
    end)
end)
--[[ Output:
    All Black Menus:
    Menu Type: contextMenus | context1
    Menu Type: contextMenus | context3
    Menu Type: dialogMenus | dialog1
]]

-- Or

local db = {
    contextMenus = {
        'test'
    },
    dialogMenus = {
        'test'
    },
    otherMenus = {
        'test2'
    }
}

RegisterCommand('allBlackMenus', function()
    print('All .... Menus:')

    HRLib.table.focusedHash(db, 'test', function(key, value, arrayInfo)
        print('Menu Type:', key, '|', arrayInfo.curr)
    end)
end)
--[[ Output:
    All .... Menus:
    Menu Type: contextMenus | test
    Menu Type: dialogMenus | test
]]

Last updated