Jump to content
  • Advertisement
Sign in to follow this  
Chisser98

implementing partial templates

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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>.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

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).

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!