This is not really an ace question but I think it is a good place to ask :)
I read somewhere in wowiki (an article about Hook functions) that since WoW 2.0 and the inclusion of lua 5.1.1 the "..." construct could be used without any huge memory impact but it does not say much about performance so I made my own test.
Here is the script I ran in a console on Mac OS X with lua 5.1.3 :
function two(a, b, c, d)
local before = os.clock()
for i=0,1000000 do
one(1, 2, 3, 4)
local try1 = os.clock() - before
print("time: " .. try1)
before = os.clock()
for i=0,1000000 do
two(1, 2, 3, 4)
local try2 = os.clock() - before
print("time: " .. try2)
The output is:
Are that results correct ?
If they are I am wondering why this construct is even used in WoW where performance should be the first priority but maybe I am missing something.
In Hooking a function, you should always use the "...", We call this a "safe Hook". Being that if the number of args returned from the BlizzardAPI changes then your hook dosn't break stuff in the patch.
Also in use you should, imo, only use it when you need to, Like an multi-Event handler is good place to use it. Or when proccessing unknown number of args. But if what your doing is a fixed number of vars then using the ... is rather useless. In order to get to them you usualy have to do somthing like this:
local arg1, argN = ...
local arg_i_want = select(i, ...)
thanks for your answers, I started learning lua recently and I am still trying to figure out best practices before writing real addons.
For function hooking I clearly understand the use case and I had no doubt about its use for this specific case, it was more for my own code that I was wondering but it is true that you do not need variable arguments in a lot of places anyway.
I don't understand how the generated op code could be the same considering they do not take the same execution time, btw how can you se the generated op code ? is it the interpreter that can show you ?