how is better to write ...
Hi all,
having a lot of times in this period I am here polishing and refreshing my addons code ... A couple of questions: 1) having code like this: Lua Code:
Lua Code:
or Lua Code:
The above statement are equal I suppose, which is better to be written ? And the second question. Being defined as: Lua Code:
all its functions are local too automagically or it is better to defined them local too ? Thanks. |
Look at my code in your other thread.
|
Hi myrroddin,
So it is better to write functions in this way ? Lua Code:
even if I put them out of its context ? But I'd like to know also if it could be a problem to write in the other way or at the end of the story both syntax works in the same way with the same results. Thanks so much for your time. Thanks. |
As you said, they're equal.
|
Thanks sp much Seerah.
I have tried to write in both way and they obviusly works but before rewrite all addons in the same way and try to write everytime in the same ways I wanted to be sure :) And about the fact that the "dataobj" is defined local ... all its functions are local by defaults or I have to defined them "local" to let them be local ? Thanks. |
In general, they're equal, but there is a very niche difference between them, and that's the order of when the function is compiled in memory and when the variable it's assigned to is created. This difference can only be seen when dealing with local functions trying to access their own pointer, usually by recursive calling.
Code:
local function RecursiveFunc() Code:
local RecursiveFunc=function() |
I'd suggest creating the LDB object in PLAYER_LOGIN because you only need to do that once. You could do in the main chunk of your addon code but that would force you to look up the object to see if it exists, and if so, get its value, and if not, create it. That's doing more CPU work than necessary. Anyway, here is the variant if you do not use PLAYER_LOGIN:
Code:
local dataobj = dataobj or ldb:NewDataObject("gmVideoSwitch", { |
Quote:
|
Quote:
Usually I write in similar way: Lua Code:
Thanks so much for your inputs ! |
All times are GMT -6. The time now is 09:31 PM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI