OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4AulFunc.cpp
Go to the documentation of this file.
1 /*
2  * OpenClonk, http://www.openclonk.org
3  *
4  * Copyright (c) 2001, 2007, Sven Eberhardt
5  * Copyright (c) 2011-2016, The OpenClonk Team and contributors
6  *
7  * Distributed under the terms of the ISC license; see accompanying file
8  * "COPYING" for details.
9  *
10  * "Clonk" is a registered trademark of Matthes Bender, used with permission.
11  * See accompanying file "TRADEMARK" for details.
12  *
13  * To redistribute this file separately, substitute the full license texts
14  * for the above references.
15  */
16 
17 #include "C4Include.h"
18 #include "script/C4Value.h"
19 #include "script/C4AulFunc.h"
20 #include "script/C4Aul.h"
21 
22 C4AulFunc::C4AulFunc(C4PropListStatic * Parent, const char *pName):
23  Parent(Parent),
24  Name(pName ? Strings.RegString(pName) : nullptr),
25  MapNext(nullptr)
26 {
27  // add to global lookuptable with this name
28  if (GetName())
30 }
31 
33 {
34  if (GetName())
36 }
37 
39 {
40  StdStrBuf r;
41  // "lost" function?
42  if (!Parent)
43  {
44  r.Ref("(unowned) ");
45  }
46  else
47  {
49  r.AppendChar('.');
50  }
51  if (GetName())
52  r.Append(Name->GetData());
53  else
54  r.Append("(unnamed)");
55  return r;
56 }
57 
58 bool C4AulFunc::CheckParTypes(const C4Value pPars[], bool fPassErrors) const {
59  // Convert parameters (typecheck)
60  const C4V_Type *pTypes = GetParType();
61  int parcount = GetParCount();
62  for (int i = 0; i < parcount; i++) {
63  if (!pPars[i].CheckParConversion(pTypes[i]))
64  {
66  R"(call to "%s" parameter %d: passed %s, but expected %s)",
67  GetName(), i + 1, pPars[i].GetTypeName(), GetC4VName(pTypes[i])).getData());
68  if (fPassErrors)
69  throw e;
70  else
71  {
73  return false;
74  }
75  }
76  }
77  return true;
78 }
StdStrBuf GetData() const
Definition: C4StringTable.h:50
C4V_Type
Definition: C4Value.h:23
C4AulErrorHandler * GetErrorHandler() const
Definition: C4Aul.h:173
C4AulScriptEngine ScriptEngine
Definition: C4Globals.cpp:43
const char * GetName() const
Definition: C4AulFunc.h:56
virtual const C4V_Type * GetParType() const =0
void AppendChar(char cChar)
Definition: StdBuf.h:588
~C4AulFunc() override
Definition: C4AulFunc.cpp:32
C4AulFuncMap FuncLookUp
Definition: C4Aul.h:116
C4StringTable Strings
Definition: C4Globals.cpp:42
C4AulFunc(C4PropListStatic *Parent, const char *pName)
Definition: C4AulFunc.cpp:22
void Add(C4AulFunc *func)
void Take(char *pnData)
Definition: StdBuf.h:457
void Append(const char *pnData, size_t iChars)
Definition: StdBuf.h:519
const char * what() const noexceptoverride
virtual StdStrBuf GetFullName() const
Definition: C4AulFunc.cpp:38
const char * GetC4VName(const C4V_Type Type)
Definition: C4Value.cpp:32
void Remove(C4AulFunc *func)
virtual void OnError(const char *msg)=0
void Ref(const char *pnData)
Definition: StdBuf.h:455
bool CheckParTypes(const C4Value pPars[], bool fPassErrors) const
Definition: C4AulFunc.cpp:58
C4PropListStatic * Parent
Definition: C4AulFunc.h:55
C4RefCntPointer< C4String > Name
Definition: C4AulFunc.h:60
StdStrBuf FormatString(const char *szFmt,...)
Definition: StdBuf.cpp:270
virtual int GetParCount() const
Definition: C4AulFunc.h:69
StdStrBuf GetDataString() const
Definition: C4PropList.cpp:253