Thread Tools Display Modes
Prev Previous Post   Next Post Next
01-22-14, 06:13 PM   #20
Lombra
A Molten Giant
 
Lombra's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 554
Originally Posted by Fizzlemizz View Post
For the final piece of the puzzle, is Clamsoda's assertion (belief) correct that

"_G is just a table in the global scope, "

and that is where you store (copy, place) variables and functions you want make accessible to other addons (directories under \Interface\Addons).
_G is a table in the global scope (or just "it's a global table"), but _G also *is* the entire global scope. To access variables between addons, you must have some global reference to it, yes.

Did not carefully read all replies, but I just want to clarify, that the reason people use _G is often because they already have a identically named local variable. Take the previous example:
Code:
local _, MyAddon = ...
_G.MyAddon = MyAddon
_G is necessary because otherwise you would just be assigning a value to the local variable that you just declared above. If you named that one differently, _G would not be necessary.
Code:
local _, addon = ...
MyAddon = addon
MyAddon is now global. MyAddon and _G.MyAddon points to the same table.

The reason you might not want to do MyAddon = {} directly is because ... already contains a [private addon] table, which will get passed to all Lua files in your addon folder, allowing you to use the same table in your whole addon without needing a global reference to it to access it between files.
__________________
Grab your sword and fight the Horde!
  Reply With Quote
 

WoWInterface » Developer Discussions » Lua/XML Help » funcName = function(p1, p2, ...) instead of function funcName(p1, p2, ...)?


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