Thread Tools Display Modes
Prev Previous Post   Next Post Next
04-16-13, 07:45 AM   #28
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
Originally Posted by Rainrider View Post
you could take #{...} instead of the first select. Don't know if that's 'cheaper' though.
You could completely avoid using select by iterating over it as a table. This uses more memory but is far more efficient in terms of cpu usage. Cpu cycles are generally more valuable than memory, so it's usually a good trade-off.
Lua Code:
  1. local func = function(...)
  2.     for _, arg in ipairs({...}) do
  3.         -- you can use pairs or ipairs if the order matters
  4.         -- i don't think there's much difference in performance
  5.     end
  6. end

If you did #{...} like your example, you would already be creating a table and throwing it away just to get the number of variables.

There are situations where you wouldn't want to turn it into a table though, for example if you had a very large number of items and couldn't construct a table (there is a size limit) or you only wanted a range of items out of a very large list, then select might be more practical.

Last edited by semlar : 04-16-13 at 08:00 AM.
  Reply With Quote
 

WoWInterface » Developer Discussions » Lua/XML Help » Issue with select() and IsInInstance()


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