interface
| 446 | |
| 447 | // interface |
| 448 | int asCGeneric::SetReturnObject(void *obj) |
| 449 | { |
| 450 | asCDataType *dt = &sysFunction->returnType; |
| 451 | if( !dt->IsObject() && !dt->IsFuncdef() ) |
| 452 | return asINVALID_TYPE; |
| 453 | |
| 454 | if( dt->IsReference() ) |
| 455 | { |
| 456 | *(void**)&returnVal = obj; |
| 457 | return 0; |
| 458 | } |
| 459 | |
| 460 | if( dt->IsObjectHandle() ) |
| 461 | { |
| 462 | // Increase the reference counter |
| 463 | if (dt->IsFuncdef()) |
| 464 | { |
| 465 | if (obj) |
| 466 | reinterpret_cast<asIScriptFunction*>(obj)->AddRef(); |
| 467 | } |
| 468 | else |
| 469 | { |
| 470 | asSTypeBehaviour *beh = &CastToObjectType(dt->GetTypeInfo())->beh; |
| 471 | if (obj && beh && beh->addref) |
| 472 | engine->CallObjectMethod(obj, beh->addref); |
| 473 | } |
| 474 | } |
| 475 | else |
| 476 | { |
| 477 | // If function returns object by value the memory is already allocated. |
| 478 | // Here we should just initialize that memory by calling the copy constructor |
| 479 | // or the default constructor followed by the assignment operator |
| 480 | void *mem = (void*)*(asPWORD*)&stackPointer[-AS_PTR_SIZE]; |
| 481 | engine->ConstructScriptObjectCopy(mem, obj, CastToObjectType(dt->GetTypeInfo())); |
| 482 | return 0; |
| 483 | } |
| 484 | |
| 485 | objectRegister = obj; |
| 486 | |
| 487 | return 0; |
| 488 | } |
| 489 | |
| 490 | // internal |
| 491 | void *asCGeneric::GetReturnPointer() |