User:Egingell/InsideFuncs

strtrim
function strtrim(str, chars) if not chars then chars = " \t" end return string.match(str, "["..chars.."]*(.*)["..chars.."]*") end

OpenAllBags
do    -- Helper function local function AllBagsOpen(bags) for _,v in pairs(bags) do            if not v:IsShown then return false end end return true end local available_bags = {} local frame function OpenAllBags(arg) available_bags = wipe(available_bags) for i=1, NUM_CONTAINER_FRAMES + NUM_BANKBAGSLOTS, 1 do            frame = getglobal("ContainerFrame"..i)             if frame then available_bags[i] = frame end end if arg == true or arg == 1 then for _,v in pairs(available_bags) do                v:Show v:SetChecked(1) end elseif not arg then if AllBagsOpen(available_bags) then for _,v in pairs(available_bags) do                    v:Hide v:SetChecked(0) end else for _,v in pairs(available_bags) do                    v:Show v:SetChecked(1) end end else _ERRORMESSAGE('Usage: OpenAllBags([boolean])') end end end

function (...) return select(random(select("#", ...)), ...) end

getglobal
function getglobal(name) return _G[name] end

EnableAllAddOns
function EnableAllAddOns for i = 1, GetNumAddOns do        EnableAddOn(i) end end

DisableAllAddOns
function DisableAllAddOns for i = 1, GetNumAddOns do        DisableAddOn(i) end end

mod
function mod(input, mod) return input % mod end

SetBindingSpell
function SetBindingSpell(key, command) if command then command = "SPELL " .. command end return SetBinding(key, command) end

SetBindingItem
function SetBindingItem(key, command) if command then command = "ITEM " .. command end return SetBinding(key, command) end

SetBindingMacro
function SetBindingMacro(key, command) if command then command = "MACRO " .. command end return SetBinding(key, command) end

SetBindingClick
function SetBindingClick(key, command, button) if command then command = "CLICK " .. command end if button then command = command .. ":" .. button end return SetBinding(key, command) end

UnitBuff
function UnitBuff(unit, buff, filter) return UnitAura(unit, buff, "HELPFUL" .. (filter == 1 and "|PLAYER" or "")) end

UnitDebuff
function UnitDebuff(unit, buff, filter) return UnitAura(unit, buff, "HARMFUL" .. (filter == 1 and "|CANCELABLE" or "")) end

print
function print(...) local n    local out = tostring((select(1, ...))) for i = 2, select("#", ...) do        out = out .. " " .. tostring((select(i, ...))) end DEFAULT_CHAT_FRAME:AddMessage(out) end

do    local strtab = {} function (...) wipe(strtab) for i = 1, select('#', ...) do            table.insert(strtab, tostring(select(i, ...))) end return unpack(strtab) end end

function (tab, func) for k, v in pairs(tab) do        local ret = func(k, v)         if ret ~= nil then return ret end end end

function (tab, func) for k, v in ipairs(tab) do        local ret = func(k, v)         if ret ~= nil then return ret end end end