# Log-class / Variable argument count

This topic is 4472 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I'd like to be able to output debug messages from my script, so I'd like to link them to my logger class. I'm sure the answer is no, but just in case :) Is there any way to do variable argument count functions (like printf("%i and %i", i1, i2); ) ?

##### Share on other sites
I don't understand what the question is?

Yes, you can declare variable argument functions (even as member functions). Just include <stdarg.h> and declare the function with a "..." at the end of the argument list. In side the function, use va_start and va_arg as usual.

However, if you're using C++, you're probably much better off to take a clue from the C++ streams, and use some operator overloading to add multiple arguments. That mechanism is type safe, whereas varargs are not.

##### Share on other sites
Quote:
 Original post by hplus0603I don't understand what the question is?Yes, you can declare variable argument functions (even as member functions). Just include and declare the function with a "..." at the end of the argument list. In side the function, use va_start and va_arg as usual.However, if you're using C++, you're probably much better off to take a clue from the C++ streams, and use some operator overloading to add multiple arguments. That mechanism is type safe, whereas varargs are not.

Okay, uhm....
This is the Angelcode section,
So my question was actually wether or not it's possible to do so in AngelScript - not how to do it in c++ ;)

##### Share on other sites
No, it's not. However, it does support the same abstraction that C++ uses - iostreams.

##### Share on other sites
Deyja is correct. It is currently not possible to register functions to take variable arguments with AngelScript. (Sometime in the future I may implement something similar though.)

Output streams, e.g. cout, can be used in AngelScript by overloading the << operator. Currently it can be a bit cumbersome however, since the left hand operator will not be the reference to the true stream class, but a copy of it. I'm working on changing this.

Input stream doesn't work very well at the moment, since the right hand operator will not get the reference to the true object. I'm working on changing this as well.

My suggestion is that you use string concatenation to format your messages and then a function that simply logs the formatted string, i.e:

log(i1 + " and " + i2);

Regards,
Andreas