Passing unknown number of referenced variables to a function

Geoff Canyon gcanyon at inspiredlogic.com
Fri Oct 29 10:44:36 EDT 2004


For the true kluge choosy kluge lovers choose, create the function with 
more input variables than you will ever need, and then pad calls to the 
function with dummy variables as needed. You need an additional 
parameter to identify the number of non-dummy arguments, like so:

function add10 pCount, at pVar1, at pVar2, at pVar3
   repeat with i = 1 to pCount
     do ("add 10 to pVar" & i)
   end repeat
end add10

Then these both work:

get add10(3,myVar1,myVar2,myVar3) -- all three are valid
get add10(1,myRealVar,x,y) -- x and y are dummies

You could also skip the count and just increment all the variables, 
obviously.

regards,

Geoff "Kluge-Man" Canyon
gcanyon at inspiredlogic.com

On Oct 28, 2004, at 10:26 AM, Ken Ray wrote:

> On 10/28/04 11:53 AM, "Dr.John R.Vokey" <vokey at uleth.ca> wrote:
>
>> Not true; just create the function with more input variables than you
>> would ever need to pass to it, then use the paramCount and params
>> functions within it to retrieve those passed.
>
> Unfortunately that only works with "regular" parameters; you can't do 
> that
> with pass-by-reference params because you need to have something 
> passed for
> each param to the function. For example, the following won't work:



More information about the use-livecode mailing list