Thread Tools Display Modes
10-31-16, 04:11 AM   #1
Lolzen
An Aku'mai Servant
 
Lolzen's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2008
Posts: 36
Calling a function from another folder

I'd like to call a function from another folder.
Thought this would work, apparently it is restricted to files inside AA's folder. What do i have to do to be able to call AA's function on BB?
BB has AA as dependency.

addon 1: AA, addon2: BB

AA.lua
Code:
addon, ns = ..

ns.test = "TEST"
BB.lua
Code:
print(AA.test)
  Reply With Quote
10-31-16, 04:21 AM   #2
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
In order for one addon to access another's functions/variables/tables/anythings, you must put those things into the global namespace:

Code:
local addon, ns = ...
ns.test = "TEST"

_G[addon] = ns
...or, less indiscriminately, if you only need certain things to be accessible:

Code:
local addon, ns = ...
ns.test = "TEST"

_G[addon] = {
    test = ns.test
}
Either way, you can then to do this in other addons:

Code:
print(OtherAddon.test)
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
10-31-16, 04:27 AM   #3
Lolzen
An Aku'mai Servant
 
Lolzen's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2008
Posts: 36
Thanks a bunch, Phanx!
  Reply With Quote
10-31-16, 08:40 AM   #4
zork
A Pyroguard Emberseer
 
zork's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 1,740
If you need to access that variable from the other addon when the addon is initialized make sure you define the addon as a dependency.

Example from my addons. oUF_SimpleConfig is the config for oUF_Simple.

Code:
oUF_SimpleConfig = L.C
https://github.com/zorker/rothui/blo...g/init.lua#L17

Code:
## Dependencies: rLib, oUF_SimpleConfig
https://github.com/zorker/rothui/blo...oUF_Simple.toc

Code:
--get the config
L.C = oUF_SimpleConfig
https://github.com/zorker/rothui/blo...e/init.lua#L16
__________________
| Simple is beautiful.
| WoWI AddOns | GitHub | Zork (WoW)

"I wonder what the non-pathetic people are doing tonight?" - Rajesh Koothrappali (The Big Bang Theory)
  Reply With Quote
10-31-16, 03:56 PM   #5
Lolzen
An Aku'mai Servant
 
Lolzen's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2008
Posts: 36
Thank you too, Zork.

I actually used
Code:
_G[addon] = ns
Works fine and is pretty much what i wanted to do in the first place, but couldn't find a result on the web.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Calling a function from another folder


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