I have just started writing my first AngelScript scripts and would benefit from being able to write a template class in the script I'm writing; is this possible? The syntax I've tried is class MyClass<class T>
, class MyClass<T>
and template<class T> class MyClass
. The ability to do this isn't shown in the documentation while the ability to register template classes from C++ is, so my suspicion is that it is not possible.
Is It Possible to Create Template Classes In Scripts
That's true. It is not possible to declare template classes from within the script language.
Would you mind giving me a bit more context on the type of scripts you're planning to write in order to think about using template classes from the script? I don't currently have this on my to-do list as future functionality, but perhaps if I see enough use for it I can add it.
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game
The current plan is to segregate game-specific logic as much as possible from the game engine; instead, programming all game-specific stuff in AngelScript. Things that can be written completely in scripts should be… the first to be written are the interpolators of values over time (to allow things like animation and movement) - these interpolators would benefit from not having a single value type to operate over, but instead basically “any numeric”, which would be good to get from templatization. These interpolators will never be registered from the C++ side and so will never get the option to be templated.
Another object that I have been thinking of making for a while now is effectively std::optional - while it may be good to do this from registration, writing it in pure AngelScript would be better in my opinion.
There are of course different ways to achieve that, more verbose and less C++-y in my opinion. Maintaining parity between the possible registration elements and pure-script elements would also be good I think.
Although not exactly the same you may be able accomplish some what you're looking for with auto declaration and mixins.
As for adding support for template declarations within the script, I'll have to think about it. It wouldn't be a trivial task to do this, and I definitely won't have time to do it anytime soon, but I'll add it to the to-do list for further consideration.
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game