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

Method SetArgObject

sdk/angelscript/source/as_context.cpp:1336–1392  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1334}
1335
1336int asCContext::SetArgObject(asUINT arg, void *obj)
1337{
1338 if( m_status != asEXECUTION_PREPARED )
1339 return asCONTEXT_NOT_PREPARED;
1340
1341 if( arg >= (unsigned)m_initialFunction->parameterTypes.GetLength() )
1342 {
1343 m_status = asEXECUTION_ERROR;
1344 return asINVALID_ARG;
1345 }
1346
1347 // Verify the type of the argument
1348 asCDataType *dt = &m_initialFunction->parameterTypes[arg];
1349 if( !dt->IsObject() && !dt->IsFuncdef() )
1350 {
1351 m_status = asEXECUTION_ERROR;
1352 return asINVALID_TYPE;
1353 }
1354
1355 // If the object should be sent by value we must make a copy of it
1356 if( !dt->IsReference() )
1357 {
1358 if( dt->IsObjectHandle() )
1359 {
1360 // Increase the reference counter
1361 if (obj && dt->IsFuncdef())
1362 ((asIScriptFunction*)obj)->AddRef();
1363 else
1364 {
1365 asSTypeBehaviour *beh = &CastToObjectType(dt->GetTypeInfo())->beh;
1366 if (obj && beh->addref)
1367 m_engine->CallObjectMethod(obj, beh->addref);
1368 }
1369 }
1370 else
1371 {
1372 obj = m_engine->CreateScriptObjectCopy(obj, dt->GetTypeInfo());
1373 }
1374 }
1375
1376 // Determine the position of the argument
1377 int offset = 0;
1378 if( m_initialFunction->objectType )
1379 offset += AS_PTR_SIZE;
1380
1381 // If function returns object by value an extra pointer is pushed on the stack
1382 if( m_returnValueSize )
1383 offset += AS_PTR_SIZE;
1384
1385 for( asUINT n = 0; n < arg; n++ )
1386 offset += m_initialFunction->parameterTypes[n].GetSizeOnStackDWords();
1387
1388 // Set the value
1389 *(asPWORD*)(&m_regs.stackFramePointer[offset]) = (asPWORD)obj;
1390
1391 return 0;
1392}
1393

Callers 15

CreateControllerMethod · 0.80
CallOnMessageMethod · 0.80
ScriptObjectCopyFactoryFunction · 0.80
EqualsMethod · 0.80
operator()Function · 0.80
ScriptCreateCoRoutineFunction · 0.80
ExecFunction · 0.80
Test3Function · 0.80
TestFunction · 0.80
TestFunction · 0.80
TestBStrFunction · 0.80
test_exception.cppFile · 0.80

Calls 11

CastToObjectTypeFunction · 0.85
IsObjectMethod · 0.80
IsFuncdefMethod · 0.80
IsObjectHandleMethod · 0.80
GetTypeInfoMethod · 0.80
CallObjectMethodMethod · 0.80
GetSizeOnStackDWordsMethod · 0.80
GetLengthMethod · 0.45
IsReferenceMethod · 0.45
AddRefMethod · 0.45

Tested by 15

ExecFunction · 0.64
Test3Function · 0.64
TestFunction · 0.64
TestFunction · 0.64
TestBStrFunction · 0.64
TestFunction · 0.64
TestFunction · 0.64
TestFunction · 0.64
TestFunction · 0.64
TestFunction · 0.64
TestFunction · 0.64
TestFunction · 0.64