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

Member Typedef Documentation

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

Definition at line 217 of file C4AulDefFunc.h.

Constructor & Destructor Documentation

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 219 of file C4AulDefFunc.h.

219  :
220  C4AulFunc(Parent, pName),
222  {
223  Parent->SetPropertyByS(Name, C4VFunction(this));
224  for(int i = GetParCount(); i < C4AUL_MAX_Par; ++i)
225  ParType[i] = C4V_Any;
226  }
int GetParCount() const override
Definition: C4AulDefFunc.h:228
C4V_Type ParType[C4AUL_MAX_Par]
Definition: C4AulDefFunc.h:255
#define C4AUL_MAX_Par
Definition: C4AulFunc.h:26
C4AulFunc(C4PropListStatic *Parent, const char *pName)
Definition: C4AulFunc.cpp:22
C4Value C4VFunction(C4AulFunc *pFn)
Definition: C4Value.h:250
virtual void SetPropertyByS(C4String *k, const C4Value &to)
Definition: C4PropList.cpp:952
C4RefCntPointer< C4String > Name
Definition: C4AulFunc.h:60

Member Function Documentation

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

Definition at line 58 of file C4AulFunc.cpp.

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

Referenced by C4AulFunc::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:56
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:69

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 
)
inlineinherited

Definition at line 72 of file C4AulFunc.h.

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

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
C4Value Exec(C4PropList *p=nullptr, C4AulParSet *pPars=nullptr, bool fPassErrors=false)
Definition: C4AulFunc.h:72
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:

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 248 of file C4AulDefFunc.h.

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

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

Here is the call graph for this function:

StdStrBuf C4AulFunc::GetFullName ( ) const
virtualinherited

Definition at line 38 of file C4AulFunc.cpp.

References StdStrBuf::Append(), StdStrBuf::AppendChar(), C4String::GetData(), C4PropListStatic::GetDataString(), C4AulFunc::GetName(), C4AulFunc::Name, C4AulFunc::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: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
void Ref(const char *pnData)
Definition: StdBuf.h:455
C4PropListStatic * Parent
Definition: C4AulFunc.h:55
C4RefCntPointer< C4String > Name
Definition: C4AulFunc.h:60
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
inlineinherited

Definition at line 56 of file C4AulFunc.h.

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

Referenced by C4AulFunc::C4AulFunc(), C4AulParseError::C4AulParseError(), C4AulFunc::CheckParTypes(), C4Value::CompileFunc(), ThisImpl< C4Object >::Conv(), C4EditCursor::DoContextMenu(), C4AulScriptFunc::DumpByteCode(), C4AulFunc::GetFullName(), C4AulScriptContext::ReturnDump(), C4AulCompiler::CodegenAstVisitor::visit(), and C4AulFunc::~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 call graph for this function:

Here is the caller graph for this function:

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

Reimplemented from C4AulFunc.

Definition at line 228 of file C4AulDefFunc.h.

229  {
230  return sizeof...(ParTypes);
231  }
template<typename RType , typename ThisType , typename... ParTypes>
const C4V_Type* C4AulEngineFunc< RType, ThisType, ParTypes >::GetParType ( ) const
inlineoverridevirtual

Implements C4AulFunc.

Definition at line 233 of file C4AulDefFunc.h.

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

234  {
235  return ParType;
236  }
C4V_Type ParType[C4AUL_MAX_Par]
Definition: C4AulDefFunc.h:255
template<typename RType , typename ThisType , typename... ParTypes>
bool C4AulEngineFunc< RType, ThisType, ParTypes >::GetPublic ( ) const
inlineoverridevirtual

Reimplemented from C4AulFunc.

Definition at line 243 of file C4AulDefFunc.h.

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

244  {
245  return Public;
246  }
template<typename RType , typename ThisType , typename... ParTypes>
C4V_Type C4AulEngineFunc< RType, ThisType, ParTypes >::GetRetType ( ) const
inlineoverridevirtual

Implements C4AulFunc.

Definition at line 238 of file C4AulDefFunc.h.

239  {
241  }
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 ( )
inlinevirtualinherited

Reimplemented in C4AulScriptFunc.

Definition at line 65 of file C4AulFunc.h.

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

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

Here is the caller graph for this function:

Member Data Documentation

C4AulFunc* C4AulFunc::MapNext
protectedinherited

Definition at line 61 of file C4AulFunc.h.

C4RefCntPointer<C4String> C4AulFunc::Name
protectedinherited
template<typename RType , typename ThisType , typename... ParTypes>
C4V_Type C4AulEngineFunc< RType, ThisType, ParTypes >::ParType[C4AUL_MAX_Par]
protected
template<typename RType , typename ThisType , typename... ParTypes>
Func C4AulEngineFunc< RType, ThisType, ParTypes >::pFunc
protected

Definition at line 254 of file C4AulDefFunc.h.

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

template<typename RType , typename ThisType , typename... ParTypes>
bool C4AulEngineFunc< RType, ThisType, ParTypes >::Public
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 file: