Skip to main content
GameDev.net gamedev.net
🔒 Locked

More elaborated example of registering a global template function?

Started by S_Petrikov Dec 31, 2025 at 6:00 AM 3 replies 900+ views
Original Post
S_Petrikov
S_Petrikov

Hi,

I am trying to register a global template function and I feel a bit lost following the doc found here: https://www.angelcode.com/angelscript/sdk/docs/manual/doc_adv_template_func.html

Here's what I have attempted, but it seems that AS complains anout the signature already:

void EcsField(asIScriptGeneric* Generic)
{
	auto Engine = FAngelscriptManager::Get().GetScriptEngine();
	auto CompTypeAS = Generic->GetReturnTypeId();
	FFlecsIterator* Iterator = reinterpret_cast<FFlecsIterator*>(Generic->GetArgAddress(0));
	int FieldId = Generic->GetArgDWord(1);
	auto TypeInfo = Engine->GetTypeInfoById(CompTypeAS);
	if (TypeInfo == nullptr) FAngelscriptManager::Throw("Cannot find type info for component");
	void* Data = ecs_field_w_size(&Iterator->Iterator, TypeInfo->GetSize(), FieldId);
	new(Generic->GetAddressOfReturnLocation()) void*(Data);
}

AS_FORCE_LINK const FAngelscriptBinds::FBind Bind_FFlecsIterator(FAngelscriptBinds::EOrder::Late, []
{
	auto Engine = FAngelscriptManager::Get().GetScriptEngine();
	auto r = Engine->RegisterGlobalFunction("T@ EcsField<T>(FFlecsIterator@ It, int FieldIndex)", 
		asFUNCTION(EcsField), asCALL_GENERIC);
	check(r >= 0);
});
WitchLord
WitchLord

You've forgotten to include the after the function name to indicate that it is a template function, instead of an ordinary function.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - <a href="http://www.angelcode.com/tower" rel
S_Petrikov
S_Petrikov

@WitchLord Hi, yeah I noticed the problem, though after changing the signature it seems like the parser does not expect “<” ? (Euh actually, the forum probably thought that “<” and “>” are part of html tags so that did not show up in my original post )

Edit: Hurm, after inspection I think there seems to be some features that did not end up in the UE integration. Which might explain why the template didn't get parsed…

Error        Angelscript               System function:
Error        Angelscript                (1:12): Expected '('
Error        Angelscript                (1:12): Instead found '<'
Error        Angelscript               :
Error        Angelscript                Failed in call to function 'RegisterGlobalFunction' with 'T& EcsField\(FFlecsIterator∈ It, int FieldIndex)' (Code: asINVALID_DECLARATION, -10)
WitchLord
WitchLord

That may the case. Template functions are pretty recent. I don't which version of angelscript UE is using.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - <a href="http://www.angelcode.com/tower" rel

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.