Jump to content

  • Log In with Google      Sign In   
  • Create Account

Jake Albano

Member Since 10 Aug 2010
Offline Last Active Oct 04 2015 06:44 PM

Topics I've Started

How is cast<T>() registered?

04 September 2015 - 12:35 PM

Just what it says in the title. I know you can't register template methods on objects, but it's recently occurred to me that cast appears to use a templated function. Is that something that's built into the language, or can it be repeated in user code?


I'm working on a few classes that expose reflection to the scripting language, and currently I've got it set up like this:


  • I have a Type class, which has no default factory. It requires a parameter of type __typeof.
  • I have a Typeof class, which is registered with the engine as both __typeof and typeof<T>.
  • typeof<T> is implicitly convertable to __typeof.
  • __typeof has no factory defined at all, so it can only be created from an instance of typeof<T>.

It's a convoluted setup, but ultimately it allows me to do this:

Type myType(typeof<MyClass>())

What I'm wondering now is whether I can make a function that behaves in the same way as cast<T>(), with the end result being a syntax that looks like this:

Type myType = typeof<MyClass>();

Of course, the best possible result would be to mimic C# syntax exactly, but I don't think that's possible;

Type myType = typeof(MyClass);

"Behaviour already registered" - troubles after upgrading

20 March 2013 - 05:10 PM

I just upgraded to the latest release after skipping one or two releases -- back from when we were still using FuncIDs. I've got my code compiling, but it doesn't run any more; behavior checks for all of my classes are asserting.


Here's the output from my check functions (they check the return value and print messages copied from the AS documentation):


-- Error (line 0, column 0) : Failed in call to function 'RegisterObjectBehaviour' with 'Component' and 'Component@ f()' (Code: -13)
Failed registering behavior with type 'Component: The behaviour is already registered with the same signature
Assertion failed: r >= 0, file C:\Users\Jake\Documents\CodeBlocks\indigo\IndigoSDK\indigo\/scripting/asIClassBinder.h, line 151


I can post more info if necessary; I was just wondering if this was a known problem. I haven't changed anything in the binding process since upgrading.

Static / Type members?

30 January 2013 - 10:37 AM

I've recently gotten in the habit of using static member constants and the named constructor idiom to improve readability of my C++ code. For example:


Vector3 vec = Vector3::Up;
Matrix mat = Matrix::Identity;

if (getPosition() == Vector3::Zero)


I think the addition of constant class members to Angelscript would be really helpful. Something like this -- in C++:

class MyCType
    static const int MyConst;


engine->RegisterTypeProperty("MyType", "int myConst", &MyCType::myConst); // just like RegisterGlobalProperty


...and in Angelscript:

int foo = MyType.myConst; // properties accessed through the type, not an instance


Is there any chance we'll see a feature like this? I'd be willing to try and implement it myself, but I have no idea where to start.

Implicit cast to bool

17 October 2012 - 08:47 PM

What is the reasoning behind disallowing implicit value casts to bool? Is there a better way to do the same thing?

I'm looking to be able to do something like this:

Keystate@ state = keyboard.getKeystate("space");

// elsewhere...
if (state)
   // key is down

Template methods

08 August 2012 - 06:59 PM

I have a class which is responsible for creating instances of my component classes, registered as a singleton. Currently it looks like this:

[source lang = "cpp"]// IComponent is an abstract C++ class that all of my components extend in the applicationIComponent@ animation = componentFactory.get("SpriteAnimation");[/source]

Obviously this isn't ideal; for one thing, errors won't be caught until the line is executed. I'm wondering if there's any way for a method to take a template parameter, like this:

[source lang = "cpp"]IComponent@ animation = componentFactory.get&lt;SpriteAnimation&gt;(); // returns an instance of SpriteAnimation[/source]

All I can find in the docs is a way to register template types, which won't help me with this. Is there something I'm missing, or could this be added in a future release?