🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Variable Argument Count

Started by
5 comments, last by WitchLord 17 years, 3 months ago
Will AngelScript support variable argument count any time soon? I'm looking for something similar to C's ... to allow a printf type function. - Dave Krusu
Advertisement
Probably not soon, but I do intend to implement it in the future. It will not be compatible with C's elipse operator though, as that is not safe enough for scripting. You will be able to implement functions similar to printf, but you won't be able to register printf with ... directly.

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

Could you give me a few pointers on what I'd have to modify to add support for this?

Basically my idea would be to use the GetVar functions that would allow you to get the count, type id, and a pointer to the variable.
My idea for function declaration is that a function would be declared only with the required variables. Then when adding the function you would use ... to accept variable argument count.

So a printf would be like this
void printf(string fmt){}


Registered with: "void printf(string, ...)"

I'm guessing that would be the easiest and safest method.
Why do you need a printf like function in the high-level object oriented language like C++ or AngelScript? Isn't it better to use operator/behaviour overload like iostreams do?
It's more about preference. I always hated the way cout looked, and always liked the printf style a lot more.

This would also be handy in other areas as well, printf was just an example.
You'd have to change a lot in the compiler to add this support. I've only got some ideas for how it could be implemented, but not enough to really help you. If you're really interested you could take a look at how the compiler handles the Any type, it might give you some ideas.

The application would only be able to register functions that take variable arguments by using the asCALL_GENERIC calling convention. That way it would have safe access to the necessary information to handle the argument types.

For functions with variable arguments to be really useful, it would also be necessary to have a way of passing the unknown variables on to a second function in the script. Sort of how var_args are used in C++, though I don't want to force the script writer to have to write two functions to do the same thing, i.e. printf and vprintf.

void func1(...){   // Add an argument and then call func2    // passing on the same arguments we received.   func2(1, push_varargs());}void func2(int, ...){   int cnt = count_varargs();}


It must also be possible to call functions that take variable arguments and pass output references (think of scanf). I'm thinking the syntax for that would be something like:

void getvalues(...) {}void function(){  int a;  // Pass the a variable as an output reference to get the value  getvalues(out a); // May also be &a, but that may be confused with C++' &a}


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