OpenClonk
C4AulEngineFunc< RType, ThisType, ParTypes > Class Template Reference

#include <C4AulDefFunc.h>

Inheritance diagram for C4AulEngineFunc< RType, ThisType, ParTypes >:
[legend]
Collaboration diagram for C4AulEngineFunc< RType, ThisType, ParTypes >:
[legend]

Public Types

typedef RType(* Func) (ThisType *, ParTypes...)
 

Public Member Functions

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

Public Attributes

C4PropListStaticParent
 

Protected Attributes

Func pFunc
 
C4V_Type ParType [C4AUL_MAX_Par]
 
bool Public
 
C4RefCntPointer< C4StringName
 
C4AulFuncMapNext
 
unsigned int RefCnt {0}
 

Detailed Description

template<typename RType, typename ThisType, typename ... ParTypes>
class C4AulEngineFunc< RType, ThisType, ParTypes >

Definition at line 214 of file C4AulDefFunc.h.

Member Typedef Documentation

◆ Func

template<typename RType , typename ThisType , typename ... ParTypes>
typedef RType(* C4AulEngineFunc< RType, ThisType, ParTypes >::Func) (ThisType *, ParTypes...)

Definition at line 218 of file C4AulDefFunc.h.

Constructor & Destructor Documentation

◆ C4AulEngineFunc()

template<typename RType , typename ThisType , typename ... ParTypes>
C4AulEngineFunc< RType, ThisType, ParTypes >::C4AulEngineFunc ( C4PropListStatic Parent,
const char *  pName,
Func  pFunc,
bool  Public 
)
inline

Definition at line 220 of file C4AulDefFunc.h.

220  :
221  C4AulFunc(Parent, pName),
223  {
225  for(int i = GetParCount(); i < C4AUL_MAX_Par; ++i)
226  ParType[i] = C4V_Any;
227  }
#define C4AUL_MAX_Par
Definition: C4AulFunc.h:26
C4Value C4VFunction(C4AulFunc *pFn)
Definition: C4Value.h:247
@ C4V_Any
Definition: C4Value.h:37
C4V_Type ParType[C4AUL_MAX_Par]
Definition: C4AulDefFunc.h:256
int GetParCount() const override
Definition: C4AulDefFunc.h:229
C4RefCntPointer< C4String > Name
Definition: C4AulFunc.h:60
C4AulFunc(C4PropListStatic *Parent, const char *pName)
Definition: C4AulFunc.cpp:22
C4PropListStatic * Parent
Definition: C4AulFunc.h:55
virtual void SetPropertyByS(C4String *k, const C4Value &to)
Definition: C4PropList.cpp:940

References C4AUL_MAX_Par, C4V_Any, C4VFunction(), C4AulEngineFunc< RType, ThisType, ParTypes >::GetParCount(), C4AulFunc::Name, C4AulFunc::Parent, C4AulEngineFunc< RType, ThisType, ParTypes >::ParType, and C4PropList::SetPropertyByS().

Here is the call graph for this function:

Member Function Documentation

◆ CheckParTypes()

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

Definition at line 58 of file C4AulFunc.cpp.

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 }
C4AulScriptEngine ScriptEngine
Definition: C4Globals.cpp:43
const char * GetC4VName(const C4V_Type Type)
Definition: C4Value.cpp:32
C4V_Type
Definition: C4Value.h:24
StdStrBuf FormatString(const char *szFmt,...)
Definition: StdBuf.cpp:270
virtual void OnError(const char *msg)=0
const char * GetName() const
Definition: C4AulFunc.h:56
virtual const C4V_Type * GetParType() const =0
virtual int GetParCount() const
Definition: C4AulFunc.h:69
C4AulErrorHandler * GetErrorHandler() const
Definition: C4Aul.h:173

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

Referenced by C4AulFunc::Exec().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DecRef()

void C4RefCnt::DecRef ( )
inlineinherited

Definition at line 28 of file C4StringTable.h.

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

References C4RefCnt::RefCnt.

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

Here is the caller graph for this function:

◆ Exec() [1/2]

template<typename RType , typename ThisType , typename ... ParTypes>
C4Value C4AulEngineFunc< RType, ThisType, ParTypes >::Exec ( C4PropList _this,
C4Value  pPars[],
bool  fPassErrors 
)
inlineoverridevirtual

Implements C4AulFunc.

Definition at line 249 of file C4AulDefFunc.h.

250  {
252  pPars, std::index_sequence_for<ParTypes...>{});
253  }
static C4Value Exec(RType(*pFunc)(ThisType *, ParTypes...), ThisType *_this, C4Value pPars[], std::index_sequence< Is... >)
Definition: C4AulDefFunc.h:121

References ExecImpl< RType, ThisType, ParTypes >::Exec(), and C4AulEngineFunc< RType, ThisType, ParTypes >::pFunc.

Here is the call graph for this function:

◆ Exec() [2/2]

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

Definition at line 72 of file C4AulFunc.h.

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  }
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
C4Value Par[C4AUL_MAX_Par]
Definition: C4AulFunc.h:30

References C4AulFunc::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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetFullName()

StdStrBuf C4AulFunc::GetFullName ( ) const
virtualinherited

Definition at line 38 of file C4AulFunc.cpp.

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 GetDataString() const
Definition: C4PropList.cpp:229
StdStrBuf GetData() const
Definition: C4StringTable.h:50
void Ref(const char *pnData)
Definition: StdBuf.h:455
void AppendChar(char cChar)
Definition: StdBuf.h:588
void Append(const char *pnData, size_t iChars)
Definition: StdBuf.h:519
void Take(char *pnData)
Definition: StdBuf.h:457

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

Here is the call graph for this function:

◆ GetName()

const char* C4AulFunc::GetName ( ) const
inlineinherited

Definition at line 56 of file C4AulFunc.h.

56 { return Name ? Name->GetCStr() : nullptr; }
const char * GetCStr() const
Definition: C4StringTable.h:49

References C4String::GetCStr(), and C4AulFunc::Name.

Referenced by C4AulFuncMap::Add(), C4AulFunc::C4AulFunc(), C4AulParseError::C4AulParseError(), C4AulFunc::CheckParTypes(), C4Value::CompileFunc(), C4EditCursor::DoContextMenu(), C4AulScriptFunc::DumpByteCode(), C4AulFuncMap::GetFirstFunc(), C4AulFunc::GetFullName(), C4AulFuncMap::GetNextSNFunc(), C4AulFuncMap::Remove(), C4AulScriptContext::ReturnDump(), and C4AulFunc::~C4AulFunc().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetParCount()

template<typename RType , typename ThisType , typename ... ParTypes>
int C4AulEngineFunc< RType, ThisType, ParTypes >::GetParCount ( ) const
inlineoverridevirtual

Reimplemented from C4AulFunc.

Definition at line 229 of file C4AulDefFunc.h.

230  {
231  return sizeof...(ParTypes);
232  }

Referenced by C4AulEngineFunc< RType, ThisType, ParTypes >::C4AulEngineFunc().

Here is the caller graph for this function:

◆ GetParType()

template<typename RType , typename ThisType , typename ... ParTypes>
const C4V_Type* C4AulEngineFunc< RType, ThisType, ParTypes >::GetParType ( ) const
inlineoverridevirtual

Implements C4AulFunc.

Definition at line 234 of file C4AulDefFunc.h.

235  {
236  return ParType;
237  }

References C4AulEngineFunc< RType, ThisType, ParTypes >::ParType.

◆ GetPublic()

template<typename RType , typename ThisType , typename ... ParTypes>
bool C4AulEngineFunc< RType, ThisType, ParTypes >::GetPublic ( ) const
inlineoverridevirtual

Reimplemented from C4AulFunc.

Definition at line 244 of file C4AulDefFunc.h.

245  {
246  return Public;
247  }

References C4AulEngineFunc< RType, ThisType, ParTypes >::Public.

◆ GetRetType()

template<typename RType , typename ThisType , typename ... ParTypes>
C4V_Type C4AulEngineFunc< RType, ThisType, ParTypes >::GetRetType ( ) const
inlineoverridevirtual

Implements C4AulFunc.

Definition at line 239 of file C4AulDefFunc.h.

240  {
242  }

◆ IncRef()

void C4RefCnt::IncRef ( )
inlineinherited

Definition at line 27 of file C4StringTable.h.

27 { RefCnt++; }

References C4RefCnt::RefCnt.

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

Here is the caller graph for this function:

◆ SFunc()

virtual C4AulScriptFunc* C4AulFunc::SFunc ( )
inlinevirtualinherited

Reimplemented in C4AulScriptFunc.

Definition at line 65 of file C4AulFunc.h.

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

Referenced by C4ScriptHost::CopyPropList(), and C4ScriptHost::UnlinkOwnedFunctions().

Here is the caller graph for this function:

Member Data Documentation

◆ MapNext

C4AulFunc* C4AulFunc::MapNext
protectedinherited

◆ Name

◆ Parent

◆ ParType

template<typename RType , typename ThisType , typename ... ParTypes>
C4V_Type C4AulEngineFunc< RType, ThisType, ParTypes >::ParType[C4AUL_MAX_Par]
protected

◆ pFunc

template<typename RType , typename ThisType , typename ... ParTypes>
Func C4AulEngineFunc< RType, ThisType, ParTypes >::pFunc
protected

Definition at line 255 of file C4AulDefFunc.h.

Referenced by C4AulEngineFunc< RType, ThisType, ParTypes >::Exec().

◆ Public

template<typename RType , typename ThisType , typename ... ParTypes>
bool C4AulEngineFunc< RType, ThisType, ParTypes >::Public
protected

◆ RefCnt

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 file: