Log-class / Variable argument count

Started by
3 comments, last by WitchLord 18 years, 4 months ago
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); ) ?
_-=[ "If there's anything more important than my ego around, I want it caught and shot now." ]=--=[ BeatHarness ]=-=[ Guerrilla Games ]=-=[ KillZone ]=-
Advertisement
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.
enum Bool { True, False, FileNotFound };
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++ ;)
_-=[ "If there's anything more important than my ego around, I want it caught and shot now." ]=--=[ BeatHarness ]=-=[ Guerrilla Games ]=-=[ KillZone ]=-
No, it's not. However, it does support the same abstraction that C++ uses - iostreams.
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

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

This topic is closed to new replies.

Advertisement