forked from Mirrors/openclonk
Script: Allow negative subscripts into arrays
parent
8d44dc28cd
commit
e18e51d36b
|
@ -44,7 +44,15 @@ public:
|
|||
|
||||
void Sort(class C4SortObject &rSort);
|
||||
|
||||
const C4Value &GetItem(int32_t iElem) const { return Inside<int32_t>(iElem, 0, iSize-1) ? pData[iElem] : C4VNull; }
|
||||
const C4Value &GetItem(int32_t iElem) const
|
||||
{
|
||||
if (-iSize <= iElem && iElem < 0)
|
||||
return pData[iSize + iElem];
|
||||
else if (0 <= iElem && iElem < iSize)
|
||||
return pData[iElem];
|
||||
else
|
||||
return C4VNull;
|
||||
}
|
||||
C4Value &GetItem(int32_t iElem);
|
||||
|
||||
C4Value operator[](int32_t iElem) const { return GetItem(iElem); }
|
||||
|
|
|
@ -106,8 +106,11 @@ void C4ValueList::Sort(class C4SortObject &rSort)
|
|||
|
||||
C4Value &C4ValueList::GetItem(int32_t iElem)
|
||||
{
|
||||
if(iElem < 0) iElem = 0;
|
||||
if(iElem >= iSize && iElem < MaxSize) this->SetSize(iElem + 1);
|
||||
if(iElem < -iSize)
|
||||
throw new C4AulExecError(NULL,"invalid subscript");
|
||||
else if(iElem < 0)
|
||||
iElem = iSize + iElem;
|
||||
else if(iElem >= iSize && iElem < MaxSize) this->SetSize(iElem + 1);
|
||||
// out-of-memory? This might not be catched, but it's better than a segfault
|
||||
if(iElem >= iSize)
|
||||
throw new C4AulExecError(NULL,"out of memory");
|
||||
|
|
Loading…
Reference in New Issue