Sign in to follow this  
LDenninger

Log-class / Variable argument count

Recommended Posts

LDenninger    122
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 this post


Link to post
Share on other sites
hplus0603    11356
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 this post


Link to post
Share on other sites
LDenninger    122
Quote:
Original post by hplus0603
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.


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 this post


Link to post
Share on other sites
WitchLord    4678
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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this