WoW API: getglobal
Jump to navigation
Jump to search
Get a global variable, from a string.
local targetGlobal = getglobal("globalName")
Parameters
Arguments
- ("globalName")
- globalName
- String - Name of the global you want to get.
Returns
- The object from the given string, or nil if not found
Details
This function is used to get an object if you generate the name of the object manually in your script:
-- i = some_dynamic_number local curFrame = getglobal("myFrame"..i)
As of the introduction of getfenv() into the API, setglobal() and getglobal() are somewhat superfluous. You can always do something along the lines of:
local _G = getfenv() local prevval = _G["MyVariable"] -- "getglobal()" _G["MyVariable"] = 1234 -- "setglobal()"
Function calls always cost some overhead, so if a large number of getglobal calls are being made, the getfenv table will be a faster route. Note that for few or infrequent calls the performance gain of this method is negligible.
getglobal()
does a little more than_G[globalName]
. It also finds_G[anything][globalName]
or_G[anything][deeper][globalName]
or any deeper hidden child object.