Advertisement

Register a templated function?

Started by May 25, 2019 03:01 PM
2 comments, last by WitchLord 5 years, 5 months ago

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?

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)
 

Advertisement

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"));

 

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

This topic is closed to new replies.

Advertisement