View Single Post
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