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