MCPcopy Create free account
hub / github.com/anjo76/angelscript / SetValue

Method SetValue

sdk/add_on/scriptarray/scriptarray.cpp:589–651  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

587}
588
589void CScriptArray::SetValue(asUINT index, void *value)
590{
591 // At() will take care of the out-of-bounds checking, though
592 // if called from the application then nothing will be done
593 void *ptr = At(index);
594 if( ptr == 0 ) return;
595
596 if ((subTypeId & ~asTYPEID_MASK_SEQNBR) && !(subTypeId & asTYPEID_OBJHANDLE))
597 {
598 asITypeInfo *subType = objType->GetSubType();
599 if (subType->GetFlags() & asOBJ_ASHANDLE)
600 {
601 // For objects that should work as handles we must use the opHndlAssign method
602 // TODO: Must support alternative syntaxes as well
603 // TODO: Move the lookup of the opHndlAssign method to Precache() so it is only done once
604 string decl = string(subType->GetName()) + "& opHndlAssign(const " + string(subType->GetName()) + "&in)";
605 asIScriptFunction* func = subType->GetMethodByDecl(decl.c_str());
606 if (func)
607 {
608 // TODO: Reuse active context if existing
609 asIScriptEngine* engine = objType->GetEngine();
610 asIScriptContext* ctx = engine->RequestContext();
611 ctx->Prepare(func);
612 ctx->SetObject(ptr);
613 ctx->SetArgAddress(0, value);
614 // TODO: Handle errors
615 ctx->Execute();
616 engine->ReturnContext(ctx);
617 }
618 else
619 {
620 // opHndlAssign doesn't exist, so try ordinary value assign instead
621 objType->GetEngine()->AssignScriptObject(ptr, value, subType);
622 }
623 }
624 else
625 objType->GetEngine()->AssignScriptObject(ptr, value, subType);
626 }
627 else if( subTypeId & asTYPEID_OBJHANDLE )
628 {
629 void *tmp = *(void**)ptr;
630 *(void**)ptr = *(void**)value;
631 objType->GetEngine()->AddRefScriptObject(*(void**)value, objType->GetSubType());
632 if( tmp )
633 objType->GetEngine()->ReleaseScriptObject(tmp, objType->GetSubType());
634 }
635 else if( subTypeId == asTYPEID_BOOL ||
636 subTypeId == asTYPEID_INT8 ||
637 subTypeId == asTYPEID_UINT8 )
638 *(char*)ptr = *(char*)value;
639 else if( subTypeId == asTYPEID_INT16 ||
640 subTypeId == asTYPEID_UINT16 )
641 *(short*)ptr = *(short*)value;
642 else if( subTypeId == asTYPEID_INT32 ||
643 subTypeId == asTYPEID_UINT32 ||
644 subTypeId == asTYPEID_FLOAT ||
645 subTypeId > asTYPEID_DOUBLE ) // enums have a type id larger than doubles
646 *(int*)ptr = *(int*)value;

Callers

nothing calls this directly

Calls 14

GetFlagsMethod · 0.80
RequestContextMethod · 0.80
SetObjectMethod · 0.80
SetArgAddressMethod · 0.80
ExecuteMethod · 0.80
ReturnContextMethod · 0.80
AssignScriptObjectMethod · 0.80
AddRefScriptObjectMethod · 0.80
ReleaseScriptObjectMethod · 0.80
GetSubTypeMethod · 0.45
GetNameMethod · 0.45
GetMethodByDeclMethod · 0.45

Tested by

no test coverage detected