Thread Tools Display Modes
12-27-17, 11:14 AM   #1
siweia
A Flamescale Wyrmkin
 
siweia's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2011
Posts: 126
How to access an addon's function?

For example, an addon named "ABC" use title like:
Code:
local A, B, C = unpack(select(2, ...))

A.CreateFrame = function() end
B.CreateColor = function() end
C.CreateName = function() end
If I want to change some of the functions in the table, what should I do in the title to access the addon?
The belowing line seems not working by using the addon name.
Code:
local A, B, C = unpack("ABC")
  Reply With Quote
12-27-17, 11:28 AM   #2
Kanegasi
A Molten Giant
 
Kanegasi's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2007
Posts: 666
It would be better if you gave the actual code, but I'm going to assume that top line is near the top of the addon's file. When an addon's code loads, it is given a vararg, which is ... and it contains the addon's name and a table that is shared among all files within that addon folder.

When you used the code, you aren't getting the same code that addon is getting. Also, that addon is localizing those functions by putting them in local tables. This means that you can only change them manually in the addon's files.

It is not possible to change those functions without editing that addon's files.
  Reply With Quote
12-27-17, 03:18 PM   #3
Aftermathhqt
A Molten Giant
 
Aftermathhqt's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2009
Posts: 784
Originally Posted by siweia View Post
For example, an addon named "ABC" use title like:
Code:
local A, B, C = unpack(select(2, ...))

A.CreateFrame = function() end
B.CreateColor = function() end
C.CreateName = function() end
If I want to change some of the functions in the table, what should I do in the title to access the addon?
The belowing line seems not working by using the addon name.
Code:
local A, B, C = unpack("ABC")
Lua Code:
  1. -- Lib Globals
  2. local _G = _G
  3. local select = select
  4. local unpack = unpack
  5. local tonumber = tonumber
  6. local match = string.match
  7. local floor = math.floor
  8.  
  9. -- Locals
  10. local Resolution = GetCurrentResolution() > 0 and select(GetCurrentResolution(), GetScreenResolutions()) or nil
  11. local Windowed = Display_DisplayModeDropDown:windowedmode()
  12. local Fullscreen = Display_DisplayModeDropDown:fullscreenmode()
  13.  
  14. -- Build the engine
  15. local AddOnName, Engine = ...
  16.  
  17. Engine[1] = {} -- Engine
  18. Engine[2] = {} -- Config
  19. Engine[3] = {} -- Locales
  20.  
  21. function Engine:unpack()
  22.     return self[1], self[2], self[3]
  23. end
  24.  
  25. Engine[1].WindowedMode = Windowed
  26. Engine[1].FullscreenMode = Fullscreen
  27. Engine[1].Resolution = Resolution or (Windowed and GetCVar("gxWindowedResolution")) or GetCVar("gxFullscreenResolution")
  28. Engine[1].ScreenHeight = tonumber(match(Engine[1].Resolution, "%d+x(%d+)"))
  29. Engine[1].ScreenWidth = tonumber(match(Engine[1].Resolution, "(%d+)x+%d"))
  30.  
  31. Engine[1].Mult = 768 / match(Engine[1].Resolution, "%d+x(%d+)") / 0.8
  32. Engine[1].Scale = function(x) return Engine[1].Mult * floor(x / Engine[1].Mult + 0.5) end
  33.  
  34. Engine[1].TexCoords = {0.08, 0.92, 0.08, 0.92}
  35.  
  36. Engine[1].MyName = UnitName("player")
  37. Engine[1].MyClass = select(2, UnitClass("player"))
  38. Engine[1].MyLevel = UnitLevel("player")
  39. Engine[1].MyRealm = GetRealmName()
  40. Engine[1].MyFaction = select(2, UnitFactionGroup("player"))
  41. Engine[1].MyRegion = GetLocale()
  42.  
  43. Engine[1].Version = GetAddOnMetadata(AddOnName, "Version")
  44. Engine[1].VersionNumber = tonumber(Engine[1].Version)
  45. Engine[1].WoWPatch, Engine[1].WoWBuild, Engine[1].WoWPatchReleaseDate, Engine[1].TocVersion = GetBuildInfo()
  46. Engine[1].WoWBuild = tonumber(Engine[1].WoWBuild)
  47.  
  48. _G[AddOnName] = Engine

Heres my code that i use as engine to access all my functions in every file.

Lua Code:
  1. local A, C, L = select(2, ...):unpack()

in every file to access those functions.
  Reply With Quote
12-28-17, 12:16 AM   #4
siweia
A Flamescale Wyrmkin
 
siweia's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2011
Posts: 126
Originally Posted by Game92 View Post
[highlight="Lua"]-- Lib Globals
local _G = _G
local select = select
local unpack = unpack
local tonumber = tonumber
local match = string.match
local floor = math.floor
...
Code:
local A, C, L = select(2, ...):unpack()
It is only available for the files inside the addon.
For other addon, it should be fine to just "local A, C, L = select(YourAddonName):unpack()", because of the bottom line of your code "_G[AddOnName] = Engine".

So now, for some addon that doesn't have the bottom code as you do, is there any way to access as well?

Last edited by siweia : 12-28-17 at 12:28 AM.
  Reply With Quote
12-28-17, 05:35 AM   #5
Aftermathhqt
A Molten Giant
 
Aftermathhqt's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2009
Posts: 784
Originally Posted by siweia View Post
Code:
local A, C, L = select(2, ...):unpack()
It is only available for the files inside the addon.
For other addon, it should be fine to just "local A, C, L = select(YourAddonName):unpack()", because of the bottom line of your code "_G[AddOnName] = Engine".

So now, for some addon that doesn't have the bottom code as you do, is there any way to access as well?
AddOnName will use your addon name from your TOC file

local A, C, L = unpack(YourAddonName)
  Reply With Quote
12-28-17, 10:30 AM   #6
siweia
A Flamescale Wyrmkin
 
siweia's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2011
Posts: 126
Originally Posted by Game92 View Post
AddOnName will use your addon name from your TOC file

local A, C, L = unpack(YourAddonName)
I know, but the addon I want to access didn't use this "_G[AddOnName] = Engine" as you do.
Currently, the only way I can do is to edit the file inside the addon.
  Reply With Quote
12-28-17, 02:11 AM   #7
Kanegasi
A Molten Giant
 
Kanegasi's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2007
Posts: 666
As I stated above, it is not possible. The vararg passed to each file of an addon is through Blizzard’s addon loader and is unique to each addon. You have to edit the addon’s files directly to either change what you want or make what you want to access a global.
  Reply With Quote
01-06-18, 12:14 PM   #8
Lolzen
An Aku'mai Servant
 
Lolzen's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2008
Posts: 36
I had a similar request not too long ago
http://www.wowinterface.com/forums/s...ad.php?t=54765
  Reply With Quote
01-07-18, 11:34 AM   #9
MunkDev
A Scalebane Royal Guard
 
MunkDev's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2015
Posts: 431
Anyone that answers anything but it's up to the addon author to expose their environment is either wrong or misunderstood what you're asking for. If something isn't globally accessible for you to modify, your best bet is probably to ask whoever designed it to make it so.
__________________
  Reply With Quote

WoWInterface » Developer Discussions » General Authoring Discussion » How to access an addon's function?

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off