Jump to content

  • Log In with Google      Sign In   
  • Create Account

- - - - -

Default Parameters


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 meink   Members   -  Reputation: 133

Like
Likes
Like

Posted 02 May 2004 - 01:05 AM

Is it possible to define default parameters for angelscript functions? I''ve tried defining both: CParticle* createParticle(float, float) CParticle* createParticle(float, float, bstr) Both point to the same C Function, which has a default value set for the last parameter. I can call the latter, but the former results in confusion about which function to call. I also tried: CParticle* createParticle(float, float, bstr="") But it didn''t like that at all. I couldn''t find anything about this in the documentation or the sample code. Is this deliberate behaviour, something I''ve missed, or a bug? - Xavier

Sponsor:

#2 Desdemona   Members   -  Reputation: 158

Like
Likes
Like

Posted 02 May 2004 - 11:02 AM

Default arguments are not part of the language... You can''t just leave out one of the arguments are expect the default to be applied because it is AngelScript that is pushing the arguments onto the stack- if you leave one off, then that argument isnt on the stack when the function gets executed. I''m not an expert on how the stack works with regards to passing arguments, but I would assume that if AngelScript didnt push all the proper data, then the function you called would be interpreting some random data as the last argument...

#3 Andreas Jonsson   Moderators   -  Reputation: 3335

Like
Likes
Like

Posted 02 May 2004 - 01:30 PM

Desdemona is correct.

In C/C++ you are allowed to define default parameters for functions, but these default parameters doesn''t really change the function interface. It''s just that the compiler fills in the missing parameters for you. The parameters are still sent to the function.

When you register a function with AngelScript you have to declare all of the parameters, even those that have default arguments, otherwise AngelScript won''t push the correct amount of data on the stack, resulting in random behaviour.

Currently AngelScript doesn''t allow you to define default parameters for function calls, but I might consider it for a future version.



__________________________________________________________
www.AngelCode.com - game development and more...
AngelScript - free scripting library - Tower - free puzzle game

#4 meink   Members   -  Reputation: 133

Like
Likes
Like

Posted 02 May 2004 - 01:39 PM

OK, thanks for your help.

- Xavier




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS