Skip to content

Commit

Permalink
C4AulEngineFuncParArray: Use span for parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
maxmitti committed Dec 8, 2024
1 parent 46093eb commit fb821d9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/C4Script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1779,7 +1779,7 @@ static C4Object *FnFindBase(C4ValueInt iOwner, C4ValueInt iIndex)
return Game.FindBase(iOwner, iIndex);
}

C4FindObject *CreateCriterionsFromPars(const C4Value *pPars, C4FindObject **pFOs, C4SortObject **pSOs)
C4FindObject *CreateCriterionsFromPars(std::span<const C4Value> pPars, C4FindObject **pFOs, C4SortObject **pSOs)
{
int i, iCnt = 0, iSortCnt = 0;
// Read all parameters
Expand Down Expand Up @@ -1827,7 +1827,7 @@ C4FindObject *CreateCriterionsFromPars(const C4Value *pPars, C4FindObject **pFOs
return pFO;
}

static C4Value FnObjectCount2(C4AulContext *cthr, const C4Value *pPars)
static C4Value FnObjectCount2(C4AulContext *cthr, std::span<const C4Value> pPars)
{
// Create FindObject-structure
C4FindObject *pFOs[C4AUL_MAX_Par];
Expand All @@ -1843,7 +1843,7 @@ static C4Value FnObjectCount2(C4AulContext *cthr, const C4Value *pPars)
return C4VInt(iCnt);
}

static C4Value FnFindObject2(C4AulContext *cthr, const C4Value *pPars)
static C4Value FnFindObject2(C4AulContext *cthr, std::span<const C4Value> pPars)
{
// Create FindObject-structure
C4FindObject *pFOs[C4AUL_MAX_Par];
Expand All @@ -1860,7 +1860,7 @@ static C4Value FnFindObject2(C4AulContext *cthr, const C4Value *pPars)
return C4VObj(pObj);
}

static C4Value FnFindObjects(C4AulContext *cthr, const C4Value *pPars)
static C4Value FnFindObjects(C4AulContext *cthr, std::span<const C4Value> pPars)
{
// Create FindObject-structure
C4FindObject *pFOs[C4AUL_MAX_Par];
Expand Down
5 changes: 3 additions & 2 deletions src/C4ScriptHelpers.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <array>
#include <span>
#include <type_traits>

#include <C4Game.h>
Expand Down Expand Up @@ -250,7 +251,7 @@ namespace C4ScriptHelpers {
template<std::size_t ParCount, C4V_Type RetType>
class C4AulEngineFuncParArray : public C4AulEngineFuncHelper<ParCount>
{
using Func = C4Value(&)(C4AulContext *context, const C4Value *pars);
using Func = C4Value(&)(C4AulContext *context, std::span<const C4Value> pars);
Func func;

public:
Expand All @@ -259,7 +260,7 @@ namespace C4ScriptHelpers {
C4V_Type GetRetType() noexcept override { return RetType; }
C4Value Exec(C4AulContext *context, const C4Value pars[], bool = false) override
{
return func(context, pars);
return func(context, std::span<const C4Value>{pars, ParCount});
}
};
}

0 comments on commit fb821d9

Please sign in to comment.