Thread Tools Display Modes
10-27-10, 10:52 PM   #1
Xubera
A Cobalt Mageweaver
 
Xubera's Avatar
AddOn Author - Click to view addons
Join Date: May 2009
Posts: 207
vararg... just how many values are in there? oO

is there a way i can determine the amount of variables passed through a vararg?

#... and #(...) seem to return the string length of the first value passed... ugh xD lol
__________________
Chat Consolidate is the solution to any out of control trade chat. Ignore lines, throttle chat, consolidate posts!Follow the link to find out how!

▲ ▲ WoWInterface wont let me triforce >.>
  Reply With Quote
10-28-10, 07:29 AM   #2
Taroven
A Cyclonian
AddOn Author - Click to view addons
Join Date: Dec 2006
Posts: 49
Something like this should work.

Code:
local function foo(...)
    local args = {...}
    local numargs = #args
end
Wrapping a multiple value return in table brackets results in a keyless table containing the values. So if ... is (1,2,3,5,6,7), you end up with a table like such:
Code:
{
    [1] = 1,
    [2] = 2,
    [3] = 3,
    [4] = 5,
    [5] = 6,
    [6] = 7
}
...and numargs will be 6.
__________________
Former author of EventHorizon Continued and Other Releases.

Last edited by Taroven : 10-28-10 at 01:34 PM.
  Reply With Quote
10-28-10, 07:32 AM   #3
Ailae
A Rage Talon Dragon Guard
 
Ailae's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2007
Posts: 318
You can also get the number of variables by using select.

lua Code:
  1. local therearethismanyvariables = select("#", ...)
__________________
Oh, the simulated horror!
  Reply With Quote
10-28-10, 01:33 PM   #4
Taroven
A Cyclonian
AddOn Author - Click to view addons
Join Date: Dec 2006
Posts: 49
Yep, either way should work fine. The table method works great if you're working with a dynamic number of params, while the select method is better if you just want to know if there are more than X number of params.

Whichever you find easier to code with, or fits better. I use the select method for parts of EventHorizon's frame activation, and the table method for a CLI framework that I've been toying with.
__________________
Former author of EventHorizon Continued and Other Releases.
  Reply With Quote
10-28-10, 03:08 PM   #5
Xubera
A Cobalt Mageweaver
 
Xubera's Avatar
AddOn Author - Click to view addons
Join Date: May 2009
Posts: 207
lol i knew i was close to the mark ><

thanks for your help
__________________
Chat Consolidate is the solution to any out of control trade chat. Ignore lines, throttle chat, consolidate posts!Follow the link to find out how!

▲ ▲ WoWInterface wont let me triforce >.>
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » vararg... just how many values are in there? oO


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