internal
| 1695 | |
| 1696 | // internal |
| 1697 | void CScriptArray::CopyBuffer(SArrayBuffer *dst, SArrayBuffer *src) |
| 1698 | { |
| 1699 | asIScriptEngine *engine = objType->GetEngine(); |
| 1700 | if( subTypeId & asTYPEID_OBJHANDLE ) |
| 1701 | { |
| 1702 | // Copy the references and increase the reference counters |
| 1703 | if( dst->numElements > 0 && src->numElements > 0 ) |
| 1704 | { |
| 1705 | int count = dst->numElements > src->numElements ? src->numElements : dst->numElements; |
| 1706 | |
| 1707 | void **max = (void**)(dst->data + count * sizeof(void*)); |
| 1708 | void **d = (void**)dst->data; |
| 1709 | void **s = (void**)src->data; |
| 1710 | |
| 1711 | for( ; d < max; d++, s++ ) |
| 1712 | { |
| 1713 | void *tmp = *d; |
| 1714 | *d = *s; |
| 1715 | if( *d ) |
| 1716 | engine->AddRefScriptObject(*d, objType->GetSubType()); |
| 1717 | // Release the old ref after incrementing the new to avoid problem incase it is the same ref |
| 1718 | if( tmp ) |
| 1719 | engine->ReleaseScriptObject(tmp, objType->GetSubType()); |
| 1720 | } |
| 1721 | } |
| 1722 | } |
| 1723 | else |
| 1724 | { |
| 1725 | if( dst->numElements > 0 && src->numElements > 0 ) |
| 1726 | { |
| 1727 | int count = dst->numElements > src->numElements ? src->numElements : dst->numElements; |
| 1728 | if( subTypeId & asTYPEID_MASK_OBJECT ) |
| 1729 | { |
| 1730 | // Call the assignment operator on all of the objects |
| 1731 | void **max = (void**)(dst->data + count * sizeof(void*)); |
| 1732 | void **d = (void**)dst->data; |
| 1733 | void **s = (void**)src->data; |
| 1734 | |
| 1735 | asITypeInfo *subType = objType->GetSubType(); |
| 1736 | if (subType->GetFlags() & asOBJ_ASHANDLE) |
| 1737 | { |
| 1738 | // For objects that should work as handles we must use the opHndlAssign method |
| 1739 | // TODO: Must support alternative syntaxes as well |
| 1740 | // TODO: Move the lookup of the opHndlAssign method to Precache() so it is only done once |
| 1741 | string decl = string(subType->GetName()) + "& opHndlAssign(const " + string(subType->GetName()) + "&in)"; |
| 1742 | asIScriptFunction *func = subType->GetMethodByDecl(decl.c_str()); |
| 1743 | if (func) |
| 1744 | { |
| 1745 | // TODO: Reuse active context if existing |
| 1746 | asIScriptContext* ctx = engine->RequestContext(); |
| 1747 | for (; d < max; d++, s++) |
| 1748 | { |
| 1749 | ctx->Prepare(func); |
| 1750 | ctx->SetObject(*d); |
| 1751 | ctx->SetArgAddress(0, *s); |
| 1752 | // TODO: Handle errors |
| 1753 | ctx->Execute(); |
| 1754 | } |
nothing calls this directly
no test coverage detected