OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
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 47 of file C4AulFunc.h.

Constructor & Destructor Documentation

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
const char * GetName() const
Definition: C4AulFunc.h:57
C4String * RegString(StdStrBuf String)
C4AulFuncMap FuncLookUp
Definition: C4Aul.h:116
C4StringTable Strings
Definition: C4Globals.cpp:42
void Add(C4AulFunc *func)
C4AulFunc * MapNext
Definition: C4AulFunc.h:62
C4PropListStatic * Parent
Definition: C4AulFunc.h:56
C4RefCntPointer< C4String > Name
Definition: C4AulFunc.h:61

Here is the call graph for this function:

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:57
C4AulFuncMap FuncLookUp
Definition: C4Aul.h:116
void Remove(C4AulFunc *func)

Here is the call graph for this function:

Member Function Documentation

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 Exec().

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 }
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:57
virtual const C4V_Type * GetParType() const =0
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
virtual int GetParCount() const
Definition: C4AulFunc.h:70

Here is the call graph for this function:

Here is the caller graph for this function:

void C4RefCnt::DecRef ( )
inlineinherited

Definition at line 28 of file C4StringTable.h.

References C4RefCnt::RefCnt.

Referenced by C4Command::Clear(), C4Property::CompileFunc(), C4Command::CompileFunc(), C4Def::GetActionByName(), C4Property::operator=(), C4Object::SetActionByName(), C4AulScriptFunc::SetOverloaded(), C4AulScriptFunc::~C4AulScriptFunc(), C4Property::~C4Property(), and C4ScriptGuiWindow::~C4ScriptGuiWindow().

28 { if (!--RefCnt) delete this; }
unsigned int RefCnt
Definition: C4StringTable.h:31

Here is the caller graph for this function:

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

Definition at line 73 of file C4AulFunc.h.

References CheckParTypes().

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

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

Here is the call graph for this function:

Here is the caller graph for this function:

virtual C4Value C4AulFunc::Exec ( C4PropList p,
C4Value  pPars[],
bool  fPassErrors = false 
)
pure virtual
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().

Referenced by C4Value::GetDataString().

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:57
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
void Ref(const char *pnData)
Definition: StdBuf.h:455
C4PropListStatic * Parent
Definition: C4AulFunc.h:56
C4RefCntPointer< C4String > Name
Definition: C4AulFunc.h:61
StdStrBuf GetDataString() const
Definition: C4PropList.cpp:253

Here is the call graph for this function:

Here is the caller graph for this function:

const char* C4AulFunc::GetName ( ) const
inline

Definition at line 57 of file C4AulFunc.h.

References C4String::GetCStr(), and Name.

Referenced by C4AulFunc(), C4AulParseError::C4AulParseError(), CheckParTypes(), C4Value::CompileFunc(), ThisImpl< C4Object >::Conv(), C4EditCursor::DoContextMenu(), C4AulScriptFunc::DumpByteCode(), GetFullName(), C4AulScriptContext::ReturnDump(), C4AulCompiler::CodegenAstVisitor::visit(), and ~C4AulFunc().

57 { return Name ? Name->GetCStr() : nullptr; }
const char * GetCStr() const
Definition: C4StringTable.h:49
C4RefCntPointer< C4String > Name
Definition: C4AulFunc.h:61

Here is the call graph for this function:

Here is the caller graph for this function:

virtual int C4AulFunc::GetParCount ( ) const
inlinevirtual

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

Definition at line 70 of file C4AulFunc.h.

References C4AUL_MAX_Par.

Referenced by CheckParTypes(), and C4AulCompiler::CodegenAstVisitor::visit().

70 { return C4AUL_MAX_Par; }
#define C4AUL_MAX_Par
Definition: C4AulFunc.h:26

Here is the caller graph for this function:

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:

virtual bool C4AulFunc::GetPublic ( ) const
inlinevirtual

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

Definition at line 69 of file C4AulFunc.h.

69 { return false; }
virtual C4V_Type C4AulFunc::GetRetType ( ) const
pure virtual
void C4RefCnt::IncRef ( )
inlineinherited

Definition at line 27 of file C4StringTable.h.

References C4RefCnt::RefCnt.

Referenced by C4Property::C4Property(), C4StringTable::C4StringTable(), C4Property::CompileFunc(), C4Command::CompileFunc(), C4ScriptGuiWindow::CreateFromPropList(), C4Def::GetActionByName(), C4Property::operator=(), C4Command::Set(), C4Object::SetActionByName(), and C4AulScriptFunc::SetOverloaded().

27 { RefCnt++; }
unsigned int RefCnt
Definition: C4StringTable.h:31

Here is the caller graph for this function:

virtual C4AulScriptFunc* C4AulFunc::SFunc ( )
inlinevirtual

Reimplemented in C4AulScriptFunc.

Definition at line 66 of file C4AulFunc.h.

Referenced by C4ScriptHost::CopyPropList(), C4ScriptHost::UnlinkOwnedFunctions(), and C4AulCompiler::CodegenAstVisitor::visit().

66 { return nullptr; } // type check func...

Here is the caller graph for this function:

Friends And Related Function Documentation

friend class C4AulFuncMap
friend

Definition at line 50 of file C4AulFunc.h.

friend class C4AulParse
friend

Definition at line 51 of file C4AulFunc.h.

friend class C4AulScriptEngine
friend

Definition at line 49 of file C4AulFunc.h.

friend class C4ScriptHost
friend

Definition at line 52 of file C4AulFunc.h.

Member Data Documentation

C4AulFunc* C4AulFunc::MapNext
protected

Definition at line 62 of file C4AulFunc.h.

C4RefCntPointer<C4String> C4AulFunc::Name
protected
unsigned int C4RefCnt::RefCnt {0}
protectedinherited

Definition at line 31 of file C4StringTable.h.

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


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