OpenClonk
C4AulFunc Class Referenceabstract

#include <C4AulFunc.h>

Inheritance diagram for C4AulFunc:
[legend]
Collaboration diagram for C4AulFunc:
[legend]

Public Member Functions

 C4AulFunc (C4PropListStatic *Parent, const char *pName)
 
const char * GetName () const
 
virtual StdStrBuf GetFullName () const
 
virtual C4AulScriptFuncSFunc ()
 
virtual bool GetPublic () const
 
virtual int GetParCount () const
 
virtual const C4V_TypeGetParType () const =0
 
virtual C4V_Type GetRetType () const =0
 
C4Value Exec (C4PropList *p=nullptr, C4AulParSet *pPars=nullptr, bool fPassErrors=false)
 
virtual C4Value Exec (C4PropList *p, C4Value pPars[], bool fPassErrors=false)=0
 
bool CheckParTypes (const C4Value pPars[], bool fPassErrors) const
 
void IncRef ()
 
void DecRef ()
 

Public Attributes

C4PropListStaticParent
 

Protected Member Functions

 ~C4AulFunc () override
 

Protected Attributes

C4RefCntPointer< C4StringName
 
C4AulFuncMapNext
 
unsigned int RefCnt {0}
 

Friends

class C4AulScriptEngine
 
class C4AulFuncMap
 
class C4AulParse
 
class C4ScriptHost
 

Detailed Description

Definition at line 46 of file C4AulFunc.h.

Constructor & Destructor Documentation

◆ C4AulFunc()

C4AulFunc::C4AulFunc ( C4PropListStatic Parent,
const char *  pName 
)

Definition at line 22 of file C4AulFunc.cpp.

References C4AulFuncMap::Add(), C4AulScriptEngine::FuncLookUp, GetName(), and ScriptEngine.

22  :
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())
29  ::ScriptEngine.FuncLookUp.Add(this);
30 }
C4AulScriptEngine ScriptEngine
Definition: C4Globals.cpp:43
C4String * RegString(StdStrBuf String)
const char * GetName() const
Definition: C4AulFunc.h:56
C4AulFuncMap FuncLookUp
Definition: C4Aul.h:116
C4StringTable Strings
Definition: C4Globals.cpp:42
void Add(C4AulFunc *func)
Definition: C4Aul.cpp:314
C4AulFunc * MapNext
Definition: C4AulFunc.h:61
C4PropListStatic * Parent
Definition: C4AulFunc.h:55
C4RefCntPointer< C4String > Name
Definition: C4AulFunc.h:60
Here is the call graph for this function:

◆ ~C4AulFunc()

C4AulFunc::~C4AulFunc ( )
overrideprotected

Definition at line 32 of file C4AulFunc.cpp.

References C4AulScriptEngine::FuncLookUp, GetName(), C4AulFuncMap::Remove(), and ScriptEngine.

33 {
34  if (GetName())
36 }
C4AulScriptEngine ScriptEngine
Definition: C4Globals.cpp:43
const char * GetName() const
Definition: C4AulFunc.h:56
C4AulFuncMap FuncLookUp
Definition: C4Aul.h:116
void Remove(C4AulFunc *func)
Definition: C4Aul.cpp:325
Here is the call graph for this function:

Member Function Documentation

◆ CheckParTypes()

bool C4AulFunc::CheckParTypes ( const C4Value  pPars[],
bool  fPassErrors 
) const

Definition at line 58 of file C4AulFunc.cpp.

References FormatString(), GetC4VName(), C4AulScriptEngine::GetErrorHandler(), GetName(), GetParCount(), GetParType(), C4AulErrorHandler::OnError(), ScriptEngine, and C4AulError::what().

Referenced by C4AulExec::ClearPointers().

58  {
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 }
virtual int GetParCount() const
Definition: C4AulFunc.h:69
C4V_Type
Definition: C4Value.h:23
C4AulScriptEngine ScriptEngine
Definition: C4Globals.cpp:43
virtual const C4V_Type * GetParType() const =0
const char * GetName() const
Definition: C4AulFunc.h:56
C4AulErrorHandler * GetErrorHandler() const
Definition: C4Aul.h:173
const char * GetC4VName(const C4V_Type Type)
Definition: C4Value.cpp:32
virtual void OnError(const char *msg)=0
StdStrBuf FormatString(const char *szFmt,...)
Definition: StdBuf.cpp:270
Here is the call graph for this function:
Here is the caller graph for this function:

◆ DecRef()

void C4RefCnt::DecRef ( )
inlineinherited

◆ Exec() [1/2]

C4Value C4AulFunc::Exec ( C4PropList p = nullptr,
C4AulParSet pPars = nullptr,
bool  fPassErrors = false 
)
inline

Definition at line 72 of file C4AulFunc.h.

References C4AulParSet::C4AulParSet(), and C4AulParSet::Par.

Referenced by C4PropList::Call(), C4Effect::CallDamage(), C4Effect::CallEffect(), C4Effect::CallStart(), C4Effect::CallStop(), C4Effect::CallTimer(), C4AulExec::ClearPointers(), C4Effect::DoCall(), C4MaterialMap::mrfScript(), C4Player::NotifyOwnedObjects(), and C4Object::PutAwayUnusedObject().

73  {
74  // Every parameter type allows conversion from nil, so no parameters are always allowed
75  if (!pPars)
76  return Exec(p, C4AulParSet().Par, fPassErrors);
77  if (!CheckParTypes(pPars->Par, fPassErrors)) return C4Value();
78  return Exec(p, pPars->Par, fPassErrors);
79  }
C4Value Par[C4AUL_MAX_Par]
Definition: C4AulFunc.h:30
bool CheckParTypes(const C4Value pPars[], bool fPassErrors) const
Definition: C4AulFunc.cpp:58
C4Value Exec(C4PropList *p=nullptr, C4AulParSet *pPars=nullptr, bool fPassErrors=false)
Definition: C4AulFunc.h:72
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Exec() [2/2]

virtual C4Value C4AulFunc::Exec ( C4PropList p,
C4Value  pPars[],
bool  fPassErrors = false 
)
pure virtual

◆ GetFullName()

StdStrBuf C4AulFunc::GetFullName ( ) const
virtual

Definition at line 38 of file C4AulFunc.cpp.

References StdStrBuf::Append(), StdStrBuf::AppendChar(), C4String::GetData(), C4PropListStatic::GetDataString(), GetName(), Name, Parent, StdStrBuf::Ref(), and StdStrBuf::Take().

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 }
StdStrBuf GetData() const
Definition: C4StringTable.h:50
const char * GetName() const
Definition: C4AulFunc.h:56
void AppendChar(char cChar)
Definition: StdBuf.h:588
void Take(char *pnData)
Definition: StdBuf.h:457
void Append(const char *pnData, size_t iChars)
Definition: StdBuf.h:519
StdStrBuf GetDataString() const
Definition: C4PropList.cpp:253
void Ref(const char *pnData)
Definition: StdBuf.h:455
C4PropListStatic * Parent
Definition: C4AulFunc.h:55
C4RefCntPointer< C4String > Name
Definition: C4AulFunc.h:60
Here is the call graph for this function:

◆ GetName()

const char* C4AulFunc::GetName ( ) const
inline

Definition at line 56 of file C4AulFunc.h.

Referenced by C4AulFuncMap::Add(), C4AulFunc(), C4AulParseError::C4AulParseError(), CheckParTypes(), C4AulExec::ClearPointers(), C4Value::CompileFunc(), C4EditCursor::DoContextMenu(), C4AulFuncMap::GetFirstFunc(), GetFullName(), C4AulFuncMap::GetNextSNFunc(), InitCoreFunctionMap(), C4AulFuncMap::Remove(), C4ScriptHost::Warn(), and ~C4AulFunc().

56 { return Name ? Name->GetCStr() : nullptr; }
const char * GetCStr() const
Definition: C4StringTable.h:49
C4RefCntPointer< C4String > Name
Definition: C4AulFunc.h:60
Here is the caller graph for this function:

◆ GetParCount()

virtual int C4AulFunc::GetParCount ( ) const
inlinevirtual

Reimplemented in C4AulEngineFunc< RType, ThisType, ParTypes >, and C4AulScriptFunc.

Definition at line 69 of file C4AulFunc.h.

References C4AUL_MAX_Par.

Referenced by CheckParTypes(), and C4AulExec::ClearPointers().

69 { return C4AUL_MAX_Par; }
#define C4AUL_MAX_Par
Definition: C4AulFunc.h:26
Here is the caller graph for this function:

◆ GetParType()

virtual const C4V_Type* C4AulFunc::GetParType ( ) const
pure virtual

Implemented in C4AulDefFunc, C4AulEngineFunc< RType, ThisType, ParTypes >, and C4AulScriptFunc.

Referenced by CheckParTypes().

Here is the caller graph for this function:

◆ GetPublic()

virtual bool C4AulFunc::GetPublic ( ) const
inlinevirtual

Reimplemented in C4AulDefFunc, C4AulEngineFunc< RType, ThisType, ParTypes >, and C4AulScriptFunc.

Definition at line 68 of file C4AulFunc.h.

Referenced by C4AulScriptEngine::GetFunctionNames().

68 { return false; }
Here is the caller graph for this function:

◆ GetRetType()

virtual C4V_Type C4AulFunc::GetRetType ( ) const
pure virtual

◆ IncRef()

void C4RefCnt::IncRef ( )
inlineinherited

◆ SFunc()

virtual C4AulScriptFunc* C4AulFunc::SFunc ( )
inlinevirtual

Reimplemented in C4AulScriptFunc.

Definition at line 65 of file C4AulFunc.h.

Referenced by C4AulExec::ClearPointers(), C4ScriptHost::CopyPropList(), C4AulExec::DirectExec(), C4AulDebug::OnLog(), and C4ScriptHost::UnlinkOwnedFunctions().

65 { return nullptr; } // type check func...
Here is the caller graph for this function:

Friends And Related Function Documentation

◆ C4AulFuncMap

friend class C4AulFuncMap
friend

Definition at line 49 of file C4AulFunc.h.

◆ C4AulParse

friend class C4AulParse
friend

Definition at line 50 of file C4AulFunc.h.

◆ C4AulScriptEngine

friend class C4AulScriptEngine
friend

Definition at line 48 of file C4AulFunc.h.

◆ C4ScriptHost

friend class C4ScriptHost
friend

Definition at line 51 of file C4AulFunc.h.

Member Data Documentation

◆ MapNext

C4AulFunc* C4AulFunc::MapNext
protected

◆ Name

C4RefCntPointer<C4String> C4AulFunc::Name
protected

Definition at line 60 of file C4AulFunc.h.

Referenced by C4AulDefFunc::C4AulDefFunc(), C4ScriptHost::CopyPropList(), and GetFullName().

◆ Parent

C4PropListStatic* C4AulFunc::Parent

Definition at line 55 of file C4AulFunc.h.

Referenced by C4Value::CompileFunc(), and GetFullName().

◆ RefCnt

unsigned int C4RefCnt::RefCnt {0}
protectedinherited

Definition at line 31 of file C4StringTable.h.

Referenced by C4RefCnt::DecRef(), C4RefCnt::IncRef(), and C4String::~C4String().


The documentation for this class was generated from the following files: