🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

implementing partial templates

Started by
6 comments, last by Chisser98 6 years, 6 months ago

Hi,

I'm curious if anyone else would think that the use of a 'partial template' system in Angelscript would be useful. Specifically, if I want to bind a std::vector, I need to give it a unique name for each type (i.e. vectorInt, vectorFloat, etc).

What if Angelscript could allow the use of the angle bracket syntax to name a type (i.e. Bind `std::vector<int>` to `vector<int>`).

A user would not be able to instantiate a `vector<float>` unless this type was registered.

does anyone think this might be useful?

I haven't looked at the code yet, so I'm not sure how complicated this might be.

Advertisement

Not entirely sure what you mean, but generic types are already possible (they're called sub-types in Angelscript). Good example is the scriptarray addon, which registers an array<T>.

I think what's confusing to people new to the language is that C++ templates and Angelscript templates aren't the same thing. In C++ it's a specialization that relies on compile time code generation, in Angelscript it relies on storing an object's type along with the object.

Unfortunately you can't just register a type vector<T> and use std::vector for it, unless you have a class that can store an Angelscript object. Even if you did, it'd be more efficient to use a specially designed container that only stores type T's type info instead, since that takes up less memory.

hmm..what I was trying to get at is to allow the use of the angle brackets when defining a type in Angelscript.

so I could register the type `vector<int>` Which would be implemented with a `std::vector<int> `. so in angel script I could write something like:
 


vector<int> myInts;

myInts.push_back(1);

 

and it would work, but if I used:


vector<float> myFloats;

myFloats.push_back(1.0f);

it would fail to compile since the type `vector<float>` is not a defined type.

does that make sense?

So you want to register template specializations? That sounds good, it should complement the existing validation system, but then the callback wouldn't be invoked for specializations, right?

You can already do this without changing the angelscript library.

You can register the template type with dummy behaviours and a callback routine that prevents any template instance that you don't explicitly want. Then you can register the template specializations for the types that you do want.

This way the non-specialized template type can never be used in the script, and the compiler will print a useful error message. (If desired the callback routine can even print an additional informative message).

 

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

Oh awesome, I didn't know that, thanks WitchLord!

This topic is closed to new replies.

Advertisement