Thread Tools Display Modes
07-05-09, 04:39 AM   #1
ilimo
A Deviate Faerie Dragon
Join Date: Jul 2009
Posts: 15
Anyaddon.Minimap.Button_OnLoad :: what kind of naming is this ?

hello,

Anyaddon.Minimap.Button_OnLoad

several points between names
is this a way of naming a function or table or anything ??


thank you for your help
  Reply With Quote
07-05-09, 04:51 AM   #2
ravagernl
Proceritate Corporis
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 1,176
This is a good idea because:

1. It keeps your code better organized.
2. It is easier to work with locals.
  Reply With Quote
07-05-09, 04:59 AM   #3
xConStruct
A Chromatic Dragonspawn
 
xConStruct's Avatar
AddOn Author - Click to view addons
Join Date: May 2008
Posts: 199
A point lets you access the entry in a table by its key ( table.key )

So basically "Anyaddon" is a table and has an entry "Minimap" which is also a table and we access its entry "Button_OnLoad".
__________________
« Website | GitHub »

Oh hai!
  Reply With Quote
07-05-09, 05:05 AM   #4
ilimo
A Deviate Faerie Dragon
Join Date: Jul 2009
Posts: 15
so if i understand correctly :

1- it is a way of naming , just to be more clear
2- it could be also a multi-table


  Reply With Quote
07-05-09, 10:42 AM   #5
xConStruct
A Chromatic Dragonspawn
 
xConStruct's Avatar
AddOn Author - Click to view addons
Join Date: May 2008
Posts: 199
It is in every case an access to the entry of a table

What mrruben5 said, is basically that a lot of authors (including me) store their functions and variables in a table, so we've got:
MyAddOn (table)
-- Function1
-- Function2

instead of
MyAddOn_Function1
MyAddOn_Function2

because it keeps the addons' functions more organized and clear, because you see to which thing the function belongs.
__________________
« Website | GitHub »

Oh hai!
  Reply With Quote
07-05-09, 03:20 PM   #6
ilimo
A Deviate Faerie Dragon
Join Date: Jul 2009
Posts: 15
in your exemple : are these the same :

MyAddOn_Function1 = MyAddOn.Function1 ?

(instead of underslash, i used a point )

----------------------------------------

because if i understood corectly, MyAddOn_Function1 is a function name
but
MyAddOn.Function1 ( with the point )
could be a function's name or a table member

---------------------------------------

i think using points is confusing to understand codes when you go through them
  Reply With Quote
07-05-09, 03:43 PM   #7
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
In your first example, the name of the function is MyAddOn_Function1. In the second, the name of the function is Function1, which is stored in/accessed from the table named MyAddOn. So, no, not the same.
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
07-05-09, 09:10 PM   #8
Medii
A Murloc Raider
Join Date: Jul 2009
Posts: 5
The dot itself really has noting to do with naming, you can't put dots in your variable/function names just like that.

The dot is used to access a value in a table, for example:
Code:
local myTable = {}

-- both these lines do the same thing
myTable.one = 1
myTable["one"] = 1
So if you have an myAddon table you can put functions as keys in that table.
for example:
Code:
myAddon = {
     PrintHello = function() print("Hello") end
}
You can then run that function by typing:
Code:
myAddon.PrintHello()
For more reading about tables: http://www.lua.org/pil/2.5.html
  Reply With Quote

WoWInterface » Developer Discussions » General Authoring Discussion » Anyaddon.Minimap.Button_OnLoad :: what kind of naming is this ?


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