2012-02-13 17:00:35 +00:00
|
|
|
/*
|
|
|
|
* OpenClonk, http://www.openclonk.org
|
|
|
|
*
|
2013-12-17 20:01:09 +00:00
|
|
|
* Copyright (c) 2001-2009, RedWolf Design GmbH, http://www.clonk.de/
|
|
|
|
* Copyright (c) 2009-2013, The OpenClonk Team and contributors
|
2012-02-13 17:00:35 +00:00
|
|
|
*
|
2013-12-17 20:01:09 +00:00
|
|
|
* Distributed under the terms of the ISC license; see accompanying file
|
|
|
|
* "COPYING" for details.
|
2012-02-13 17:00:35 +00:00
|
|
|
*
|
2013-12-17 20:01:09 +00:00
|
|
|
* "Clonk" is a registered trademark of Matthes Bender, used with permission.
|
|
|
|
* See accompanying file "TRADEMARK" for details.
|
2012-02-13 17:00:35 +00:00
|
|
|
*
|
2013-12-17 20:01:09 +00:00
|
|
|
* To redistribute this file separately, substitute the full license texts
|
|
|
|
* for the above references.
|
2012-02-13 17:00:35 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef INC_C4AulFunc
|
|
|
|
#define INC_C4AulFunc
|
|
|
|
|
|
|
|
#include <C4StringTable.h>
|
|
|
|
|
|
|
|
#define C4AUL_MAX_Par 10 // max number of parameters
|
|
|
|
|
2012-05-27 21:35:23 +00:00
|
|
|
struct C4AulParSet
|
|
|
|
{
|
|
|
|
C4Value Par[C4AUL_MAX_Par];
|
|
|
|
|
|
|
|
C4AulParSet() {} // standard-constructor
|
|
|
|
C4AulParSet(const C4Value &par0, const C4Value &par1 = C4Value(), const C4Value &par2 = C4Value(), const C4Value &par3 = C4Value(), const C4Value &par4 = C4Value(),
|
|
|
|
const C4Value &par5 = C4Value(), const C4Value &par6 = C4Value(), const C4Value &par7 = C4Value(), const C4Value &par8 = C4Value(), const C4Value &par9 = C4Value())
|
|
|
|
{
|
|
|
|
Par[0].Set(par0); Par[1].Set(par1); Par[2].Set(par2); Par[3].Set(par3); Par[4].Set(par4);
|
|
|
|
Par[5].Set(par5); Par[6].Set(par6); Par[7].Set(par7); Par[8].Set(par8); Par[9].Set(par9);
|
|
|
|
}
|
2012-05-20 00:04:46 +00:00
|
|
|
C4AulParSet(const C4Value * Pars, int ParCount)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < ParCount; ++i)
|
|
|
|
Par[i].Set(Pars[i]);
|
|
|
|
}
|
2012-05-27 21:35:23 +00:00
|
|
|
C4Value & operator[](int iIdx) { return Par[iIdx]; }
|
|
|
|
C4AulParSet * operator&() { return this; }
|
|
|
|
};
|
|
|
|
|
2012-02-13 17:00:35 +00:00
|
|
|
// base function class
|
|
|
|
class C4AulFunc
|
|
|
|
{
|
|
|
|
friend class C4AulScript;
|
|
|
|
friend class C4AulScriptEngine;
|
|
|
|
friend class C4AulFuncMap;
|
2012-04-12 19:03:14 +00:00
|
|
|
friend class C4AulParse;
|
2012-02-13 17:00:35 +00:00
|
|
|
friend class C4ScriptHost;
|
|
|
|
|
2012-02-02 00:16:14 +00:00
|
|
|
// Reference counter
|
|
|
|
unsigned int iRefCnt;
|
|
|
|
|
2012-02-13 17:00:35 +00:00
|
|
|
public:
|
|
|
|
C4AulFunc(C4AulScript *pOwner, const char *pName);
|
2012-02-02 00:16:14 +00:00
|
|
|
|
|
|
|
// Add/Remove Reference
|
|
|
|
void IncRef() { iRefCnt++; }
|
|
|
|
void DecRef() { if (!--iRefCnt) delete this; }
|
2012-02-13 17:00:35 +00:00
|
|
|
|
|
|
|
C4AulScript *Owner; // owner
|
|
|
|
const char * GetName() const { return Name ? Name->GetCStr() : 0; }
|
|
|
|
virtual StdStrBuf GetFullName(); // get a fully classified name (C4ID::Name) for debug output
|
|
|
|
|
|
|
|
protected:
|
|
|
|
C4RefCntPointer<C4String> Name; // function name
|
|
|
|
C4AulFunc *MapNext; // map member
|
2012-02-02 00:16:14 +00:00
|
|
|
virtual ~C4AulFunc();
|
2012-02-13 17:00:35 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
virtual C4AulScriptFunc *SFunc() { return NULL; } // type check func...
|
|
|
|
|
|
|
|
// Wether this function should be visible to players
|
2013-11-02 12:38:26 +00:00
|
|
|
virtual bool GetPublic() const { return false; }
|
|
|
|
virtual int GetParCount() const { return C4AUL_MAX_Par; }
|
|
|
|
virtual const C4V_Type* GetParType() const = 0;
|
|
|
|
virtual C4V_Type GetRetType() const = 0;
|
2012-05-27 21:35:23 +00:00
|
|
|
C4Value Exec(C4PropList * p = NULL, C4AulParSet *pPars = NULL, bool fPassErrors=false)
|
|
|
|
{
|
2015-01-30 19:33:57 +00:00
|
|
|
// Every parameter type allows conversion from nil, so no parameters are always allowed
|
|
|
|
if (!pPars)
|
|
|
|
return Exec(p, C4AulParSet().Par, fPassErrors);
|
|
|
|
if (!CheckParTypes(pPars->Par, fPassErrors)) return C4Value();
|
2012-05-27 21:35:23 +00:00
|
|
|
return Exec(p, pPars->Par, fPassErrors);
|
|
|
|
}
|
|
|
|
virtual C4Value Exec(C4PropList * p, C4Value pPars[], bool fPassErrors=false) = 0;
|
2015-01-30 19:33:57 +00:00
|
|
|
bool CheckParTypes(const C4Value pPars[], bool fPassErrors) const;
|
2012-02-13 17:00:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|