Jump to content
  • Advertisement
Pursche

Register a templated function?

Recommended Posts

Posted (edited)

Hi! I am having a hard time figuring out how to register a templated function.
I read this page: http://www.angelcode.com/angelscript/sdk/docs/manual/doc_adv_template.html
But it only seems to cover how to create a templated type with member functions (object behaviors).

I saw this thread that has almost the same problem and usecase as me, in it one of the comments says that the following usage should be possible in AngelScript.

Velocity@ vel = entity.getComponent<Velocity>();

But it doesn't go into any details on how to do this. It also suggests this syntax which I would prefer to avoid if possible, and yes I read the part about this having better performance.

entity.getVelocity();

My most preferable usecase would be getComponent<Velocity>(entity);  with entity.getComponent<Velocity>() as a close second.

Is this even possible without a templated type? Could anyone show me a concrete example of registering a templated global function, preferable with specializations as well?

Edited by Pursche

Share this post


Link to post
Share on other sites
Advertisement

I think AngelScript supports template types but not functions.
Something similar could maybe be made by using output variable parameters
(https://www.angelcode.com/angelscript/sdk/docs/manual/doc_adv_var_type.html)
 

Share this post


Link to post
Share on other sites

Templated functions are not yet supported in AngelScript. It is on the to-do list, but has a quite low priority so do not expect it to be implemented soon.

If you do not want to register a for each component type, then your best option is to use either the variable argument type that MrFloat indicated, or use the generic ref type add-on to return the component based on a named type.

Using the variable argument type the script code might look like this:

Velocity @vel;
entity.getComponent(@vel);

Using the generic ref type the script code might look like this:

Velocity @vel = cast<Velocity>(entity.getComponent("Velocity"));

 

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

  • Advertisement
×

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!