I'm new to Angelscript.
I have some classes that I don't want scripts to create, but that I want to give scripts access to. I have several different class types like that ("Player","Enemy","Event", - scripts should never create any of these).
Would the appropriate registration flags be asOBJ_REF and asOBJ_NOCOUNT, and then simply not registering the constructors/destructors? All of these are guaranteed to out-live the scripts.
engine->RegisterObjectType("Event", sizeof(EventStructure_Server), asOBJ_REF | asOBJ_NOCOUNT)
I want (C++-side) functions that returns arrays of these references/pointers.
Things like, "event.GetPlayersInRange(pos, range)"
I see there is a CScriptArray, but I don't understand if this is a *replacement* for an existing built-in array type, or if there is no default array type?
In C++, how would I create an array of non-reference-counted references to return?
Is this correct: (going off of the addon Array example)
// Registered with AngelScript as 'array<Enemy> @CreateArrayOfString()'
CScriptArray *GetEnemiesInRange(cPointF pos, float radius)
{
asIScriptContext *ctx = asGetActiveContext();
Assert(ctx, "Error! Can only call this function from within scripts");
asIScriptEngine* engine = ctx->GetEngine();
// vvv Should this just be "Enemy"?
asITypeInfo *typeInfo = engine->GetTypeInfoByDecl("array<Enemy>");
std::vector<Enemy*> enemies = /*...whatever...*/;
CScriptArray *arr = CScriptArray::Create(typeInfo, enemies.size());
for( asUINT i = 0; i < arr->GetSize(); i++ )
{
arr->SetValue(i, enemies[i]); //Just give the CScriptArray pointers to the Enemy instances?
}
return arr;
}