Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


- - - - -

Any class with operator overloads


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
6 replies to this topic

#1 thd.MM   Members   -  Reputation: 208

Like
0Likes
Like

Posted 08 November 2012 - 04:05 AM

Wouldn't it be handy to have CScriptAny have operator overloads for at least the basic types so you can do:
any x = 100;

Has anyone done that already?

Sponsor:

#2 Jake Albano   Members   -  Reputation: 646

Like
0Likes
Like

Posted 08 November 2012 - 08:55 AM

I may be mistaken (I've never used the any class), but isn't its intended use for parameters to application functions? I can't think of a situation when it would be good practice to use it otherwise.

Edited by Jake Albano, 08 November 2012 - 08:55 AM.


#3 thd.MM   Members   -  Reputation: 208

Like
0Likes
Like

Posted 09 November 2012 - 02:52 AM

I want to do this:

any[] list = { 0, "string", someObject, 4.0f };

So I want "any" to overload = for the basic types.

#4 Andreas Jonsson   Moderators   -  Reputation: 3413

Like
0Likes
Like

Posted 09 November 2012 - 11:56 AM

You can certainly implement an opAssign method for each of the basic types you want to support.

The method would have to look up the type id of the value. This could be done once and cached so you don't have a performance hit for each assignment.

Edited by Andreas Jonsson, 09 November 2012 - 12:00 PM.

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

#5 thd.MM   Members   -  Reputation: 208

Like
0Likes
Like

Posted 12 November 2012 - 06:38 AM

OK thanks, will do. Just thought somebody has already done that. I can show the results when it's working.

#6 thd.MM   Members   -  Reputation: 208

Like
0Likes
Like

Posted 12 November 2012 - 04:36 PM

One more thing. I'd like to do this:

SomeFunc( { x, y, "test } );

where void SomeFunc( any[]@ ) or void SomeFunc( any[] )

If you know actionscript, I think you know where I'm heading.
Anyway I could accomplish this?

#7 Andreas Jonsson   Moderators   -  Reputation: 3413

Like
0Likes
Like

Posted 13 November 2012 - 08:24 AM

I have this on my to-do list already. I'm not sure when I'll have the time to implement it though.

It will require quite a bit of change in the compiler in order to handle this scenario. The compiler would have to defer the evaluation of the array until it knows where it will be used so it can determine the exact type of the array object and initialize it appropriately.
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game




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