variable argument list

BlitzMax Forums/BlitzMax Beginners Area/variable argument list

Rozek(Posted 2006) [#1]
Hello!

Please excuse this probably *very* basic question, but I could not find the answer neither by reading through the online help nor by searching this forum:

- how do I define functions with variable argument lists?
- how do I access any extra arguments?

Thanks in advance for any response!


Azathoth(Posted 2006) [#2]
Use a function that takes an object or array of objects as an argument then cast to the appropriate types.

Function ShowAll(a:Object[])
	Local b:Object
	
	For b=EachIn a
		Print String(b)
	Next 
EndFunction

ShowAll(["abc","def"])

You can only use Strings in that example.


Rozek(Posted 2006) [#3]
Hallo Paul!

Thanks for your response - it's a cute trick, indeed...but it could not be applied to "primitive" types such as byte, short, int etc.!?

Hmmm, do Strings count as objects? Will have to look into the spec.s again...


Azathoth(Posted 2006) [#4]
The Docs call Strings Objects but they support '+' for appending other strings.
For primitives you'd need some kind of primitive wrapper, or limit your array to a primitive type.
Another thing is AutoArrays(arrays that are constructed on one line like in my example) requires all the data to be of the same type, so even though it accepts an array of objects the AutoArray requires them to be all strings in the example; the only way I can see around this is not to use AutoArrays but this makes the code longer.