Hey, I made some useful command that can help people with writing their addons. I thought I will share it with you. First the code, then examples:
Lua Code:
local function pairs_safe_grep(table)
return function(arg,lastval)
local val = nil
repeat
repeat
ok,lastval,v = pcall(next,arg.t,lastval)
if ok == false then
lastval = string.match(lastval, "private function '([%w_]+)' from" )
if lastval == nil then
break
end
end
until ok == true
if lastval == nil then return nil end
val = rawget(arg.t, lastval)
local isend = false
if arg.k == nil or ( arg.k and string.match(lastval, arg.k) ) then
isend = true
elseif arg.k then
isend = false
end
if isend and ( arg.v == nil or ( arg.v and string.match(tostring(val), arg.v) ) ) then
isend = true
elseif isend and arg.v then
isend = false
end
until isend
return lastval, val
end,table,nil
end
local function harven_dumpg(raw_args)
local args = {}
for arg in string.gmatch(raw_args, "|([:;'<,>/%[%]\\=_~`!@#&*%(%)%c%^%$%(%)%%%.%[%]%*%+%-%?%s%w]+)|") do
table.insert(args,arg)
end
local i = 0
if args[1] == "nil" then
args[1] = nil
end
for k,v in pairs_safe_grep({t=_G,k=args[1],v=args[2]}) do
d(k.." = "..tostring(v))
i = i + 1
end
d("count: "..i)
end
SLASH_COMMANDS["/dumpg"] = harven_dumpg
It will iterate over _G table with my custom iterator function pairs_safe_grep. It can dump all global variables or search based on lua patterns. You can specify a pattern for keys and a pattern for values. It will skip all private functions.
Usage:
Code:
/dumpg |key_pattern|value_pattern|
value_pattern is optional and so is key_pattern. But when you want to skip key_pattern and use only value_pattern then you must write nil in key_pattern.
Examples:
will dump all global variables
will dump all available event types with their codes.
Code:
/dumpg |^EVENT_.*UPDATE$||
will dump all event that start with EVENT_ and end with UPDATE
Code:
/dumpg |nil|function|
will dump all functions
Code:
/dumpg |ZoFont|userdata|
will dump names of all fonts
will dump all variables with 3 in their value
will dump all variables with value == 3
Code:
/dumpg |^LOOT_TYPE||
will dump all loot types
will search for control type with value 5 (which appears to be CT_ROOT_WINDOW),
and so one.
I often use this command to find a name of interface element. For example I wanted to find the name of Split Stack window. So I opened the window, moved my mouse over it and executed command
which is another useful command:
Lua Code:
SLASH_COMMANDS["/control"] = function(...)
d(WINDOW_MANAGER:GetMouseOverControl())
end
It says:
in my case (it will change after reloadui)
Then i just execute:
Code:
/dumpg |nil|3BE780C0|
and got:
Code:
ZO_StackSplitModalUnderlay = userdata: 3BE780C0
And that is all i needed, the window will be ZO_StackSplit. You can check if it really exists by typing:
Code:
/dumpg |^ZO_StackSplit$||