Advertisement

Any class with operator overloads

Started by November 08, 2012 10:05 AM
5 comments, last by WitchLord 12 years ago
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?
KAG DEVLOG: http://kagdev.tumblr.com/
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.
Advertisement
I want to do this:

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

So I want "any" to overload = for the basic types.
KAG DEVLOG: http://kagdev.tumblr.com/
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.

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

OK thanks, will do. Just thought somebody has already done that. I can show the results when it's working.
KAG DEVLOG: http://kagdev.tumblr.com/
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?
KAG DEVLOG: http://kagdev.tumblr.com/
Advertisement
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

This topic is closed to new replies.

Advertisement