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
|
|
|
|
|
2014-05-29 22:13:48 +00:00
|
|
|
#ifndef INC_C4Value
|
|
|
|
#error Include C4Value.h instead of C4AulFunc.h
|
|
|
|
#endif
|
|
|
|
|
2016-04-03 18:07:56 +00:00
|
|
|
#include "script/C4StringTable.h"
|
2012-02-13 17:00:35 +00:00
|
|
|
|
|
|
|
#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
|
2014-05-30 23:00:31 +00:00
|
|
|
template<class ...T> explicit C4AulParSet(T&& ...pars):
|
|
|
|
Par {C4Value(std::forward<T>(pars))...}
|
2012-05-27 21:35:23 +00:00
|
|
|
{
|
|
|
|
}
|
2014-05-30 22:37:18 +00:00
|
|
|
void Copy(const C4Value * Pars, int ParCount)
|
2012-05-20 00:04:46 +00:00
|
|
|
{
|
|
|
|
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
|
2014-06-01 19:21:10 +00:00
|
|
|
class C4AulFunc: public C4RefCnt
|
2012-02-13 17:00:35 +00:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
public:
|
2014-04-20 13:52:09 +00:00
|
|
|
C4AulFunc(C4PropListStatic * Parent, const char *pName);
|
2012-02-02 00:16:14 +00:00
|
|
|
|
2014-04-20 13:52:09 +00:00
|
|
|
const C4PropListStatic * Parent;
|
2012-02-13 17:00:35 +00:00
|
|
|
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
|
|
|
|
|