OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4AulExec Class Reference

#include <C4AulExec.h>

Public Member Functions

 C4AulExec ()
 
C4Value Exec (C4AulScriptFunc *pSFunc, C4PropList *p, C4Value pPars[], bool fPassErrors)
 
C4Value DirectExec (C4PropList *p, const char *szScript, const char *szContext, bool fPassErrors=false, C4AulScriptContext *context=nullptr, bool parse_function=false)
 
void StartTrace ()
 
void StartDirectExec ()
 
void StopDirectExec ()
 
int GetContextDepth () const
 
C4AulScriptContextGetContext (int iLevel)
 
void LogCallStack ()
 
void ClearPointers (C4Object *)
 

Static Public Member Functions

static C4StringFnTranslate (C4PropList *_this, C4String *text)
 
static bool FnLogCallStack (C4PropList *_this)
 

Friends

class C4AulProfiler
 

Detailed Description

Definition at line 54 of file C4AulExec.h.

Constructor & Destructor Documentation

C4AulExec::C4AulExec ( )
inline

Definition at line 58 of file C4AulExec.h.

59  : pCurCtx(Contexts - 1), pCurVal(Values - 1)
60  { }

Member Function Documentation

void C4AulExec::ClearPointers ( C4Object obj)

Definition at line 136 of file C4AulExec.cpp.

Referenced by C4Game::ClearPointers().

137 {
138  for (C4AulScriptContext *pCtx = pCurCtx; pCtx >= Contexts; pCtx--)
139  {
140  if (pCtx->Obj == obj)
141  pCtx->Obj = nullptr;
142  }
143 }

Here is the caller graph for this function:

C4Value C4AulExec::DirectExec ( C4PropList p,
const char *  szScript,
const char *  szContext,
bool  fPassErrors = false,
C4AulScriptContext context = nullptr,
bool  parse_function = false 
)

Definition at line 1013 of file C4AulExec.cpp.

References AddDbgRec(), C4VNull, Config, C4ConfigGeneral::DebugRec, DEBUGREC_SCRIPT, Exec(), GameScript, C4Config::General, C4PropList::GetDef(), C4AulScriptEngine::GetErrorHandler(), C4GameScriptHost::GetPropList(), C4PropList::GetPropListNumbered(), C4PropList::IsStatic(), LogCallStack(), C4PropListNumbered::Number, C4AulErrorHandler::OnError(), C4AulParSet::Par, C4AulScriptFunc::ParseDirectExecFunc(), C4AulScriptFunc::ParseDirectExecStatement(), RCT_DirectExec, ScriptEngine, StartDirectExec(), StopDirectExec(), and C4AulError::what().

Referenced by C4ObjectMenu::MenuCommand(), C4Object::MenuCommand(), C4EditCursor::PerformDuplication(), C4PropertyPath::ResolveRoot(), and C4PropertyPath::ResolveValue().

1014 {
1016  {
1017  AddDbgRec(RCT_DirectExec, szScript, strlen(szScript)+1);
1018  int32_t iObjNumber = p && p->GetPropListNumbered() ? p->GetPropListNumbered()->Number : -1;
1019  AddDbgRec(RCT_DirectExec, &iObjNumber, sizeof(int32_t));
1020  }
1021  // profiler
1022  StartDirectExec();
1024  if (p && p->IsStatic())
1025  script = p->IsStatic();
1026  else if (p && p->GetDef())
1027  script = p->GetDef();
1028  // Add a new function
1029  auto pFunc = std::make_unique<C4AulScriptFunc>(script, nullptr, nullptr, szScript);
1030  // Parse function
1031  try
1032  {
1033  if (parse_function)
1034  {
1035  // Expect a full function (e.g. "func foo() { return bar(); }")
1036  pFunc->ParseDirectExecFunc(&::ScriptEngine, context);
1037  }
1038  else
1039  {
1040  // Expect a single statement (e.g. "bar()")
1041  pFunc->ParseDirectExecStatement(&::ScriptEngine, context);
1042  }
1043  C4AulParSet Pars;
1044  C4Value vRetVal(Exec(pFunc.get(), p, Pars.Par, fPassErrors));
1045  // profiler
1046  StopDirectExec();
1047  return vRetVal;
1048  }
1049  catch (C4AulError &ex)
1050  {
1051  if(fPassErrors)
1052  throw;
1054  LogCallStack();
1055  StopDirectExec();
1056  return C4VNull;
1057  }
1058 }
C4Config Config
Definition: C4Config.cpp:833
C4Value Exec(C4AulScriptFunc *pSFunc, C4PropList *p, C4Value pPars[], bool fPassErrors)
C4AulErrorHandler * GetErrorHandler() const
Definition: C4Aul.h:173
C4GameScriptHost GameScript
C4AulScriptEngine ScriptEngine
Definition: C4Globals.cpp:43
constexpr bool DEBUGREC_SCRIPT
Definition: C4Include.h:30
C4ConfigGeneral General
Definition: C4Config.h:251
void StopDirectExec()
Definition: C4AulExec.h:85
void LogCallStack()
Definition: C4AulExec.cpp:94
virtual class C4PropListStatic * IsStatic()
Definition: C4PropList.h:85
C4Value Par[C4AUL_MAX_Par]
Definition: C4AulFunc.h:30
C4PropListStatic * GetPropList() override
virtual C4Def const * GetDef() const
Definition: C4PropList.cpp:685
const char * what() const noexceptoverride
void AddDbgRec(C4RecordChunkType eType, const void *pData, int iSize)
Definition: C4Record.cpp:32
virtual void OnError(const char *msg)=0
const C4Value C4VNull
Definition: C4Value.cpp:30
int32_t DebugRec
Definition: C4Config.h:60
virtual C4PropListNumbered * GetPropListNumbered()
Definition: C4PropList.cpp:703
void StartDirectExec()
Definition: C4AulExec.h:84

Here is the call graph for this function:

Here is the caller graph for this function:

C4Value C4AulExec::Exec ( C4AulScriptFunc pSFunc,
C4PropList p,
C4Value  pPars[],
bool  fPassErrors 
)

Referenced by DirectExec(), and C4AulScriptFunc::Exec().

Here is the caller graph for this function:

bool C4AulExec::FnLogCallStack ( C4PropList _this)
static

Definition at line 130 of file C4AulExec.cpp.

References LogCallStack().

Referenced by InitCoreFunctionMap().

131 {
133  return true;
134 }
void LogCallStack()
Definition: C4AulExec.cpp:94
C4AulExec AulExec
Definition: C4AulExec.cpp:29

Here is the call graph for this function:

Here is the caller graph for this function:

C4String * C4AulExec::FnTranslate ( C4PropList _this,
C4String text 
)
static

Definition at line 100 of file C4AulExec.cpp.

References DebugLogF(), C4AulScriptContext::Func, C4String::GetCStr(), C4String::GetData(), C4PropList::GetDef(), StdStrBuf::isNull(), LogCallStack(), C4AulScriptFunc::pOrgScript, ReturnIfTranslationAvailable, C4Def::Script, and text.

Referenced by InitCoreFunctionMap().

101 {
102 #define ReturnIfTranslationAvailable(script, key) do \
103 { \
104  const auto &s = script; \
105  const auto &k = key; \
106  if (s) \
107  { \
108  try \
109  { \
110  return ::Strings.RegString(s->Translate(k).c_str()); \
111  } \
112  catch (C4LangStringTable::NoSuchTranslation &) {} \
113  } \
114 } while(0)
115 
116  if (!text || text->GetData().isNull()) return nullptr;
117  // Find correct script: translations of the context if possible, containing script as fallback
118  if (_this && _this->GetDef())
119  ReturnIfTranslationAvailable(&(_this->GetDef()->Script), text->GetCStr());
121 
122  // No translation available, log
123  DebugLogF(R"(WARNING: Translate: no translation for string "%s")", text->GetCStr());
124  // Trace
126  return text;
127 #undef ReturnIfTranslationAvailable
128 }
StdStrBuf GetData() const
Definition: C4StringTable.h:50
void LogCallStack()
Definition: C4AulExec.cpp:94
const char * GetCStr() const
Definition: C4StringTable.h:49
C4ScriptHost * pOrgScript
C4AulExec AulExec
Definition: C4AulExec.cpp:29
C4AulScriptFunc * Func
Definition: C4AulExec.h:46
virtual C4Def const * GetDef() const
Definition: C4PropList.cpp:685
bool DebugLogF(const char *strMessage...)
Definition: C4Log.cpp:278
#define ReturnIfTranslationAvailable(script, key)
bool isNull() const
Definition: StdBuf.h:441
C4DefScriptHost Script
Definition: C4Def.h:181

Here is the call graph for this function:

Here is the caller graph for this function:

C4AulScriptContext* C4AulExec::GetContext ( int  iLevel)
inline

Definition at line 88 of file C4AulExec.h.

References GetContextDepth().

Referenced by C4AulDebug::DebugStep().

88 { return iLevel >= 0 && iLevel < GetContextDepth() ? Contexts + iLevel : nullptr; }
int GetContextDepth() const
Definition: C4AulExec.h:87

Here is the call graph for this function:

Here is the caller graph for this function:

int C4AulExec::GetContextDepth ( ) const
inline

Definition at line 87 of file C4AulExec.h.

Referenced by C4AulDebug::DebugStep(), and GetContext().

87 { return pCurCtx - Contexts + 1; }

Here is the caller graph for this function:

void C4AulExec::LogCallStack ( )

Definition at line 94 of file C4AulExec.cpp.

Referenced by DirectExec(), FnLogCallStack(), and FnTranslate().

95 {
96  for (C4AulScriptContext *pCtx = pCurCtx; pCtx >= Contexts; pCtx--)
97  pCtx->dump(StdStrBuf(" by: "));
98 }

Here is the caller graph for this function:

void C4AulExec::StartDirectExec ( )
inline

Definition at line 84 of file C4AulExec.h.

References C4TimeMilliseconds::Now().

Referenced by DirectExec().

84 { if (fProfiling) tDirectExecStart = C4TimeMilliseconds::Now(); }
static C4TimeMilliseconds Now()

Here is the call graph for this function:

Here is the caller graph for this function:

void C4AulExec::StartTrace ( )

Definition at line 905 of file C4AulExec.cpp.

906 {
907  if (iTraceStart < 0)
908  iTraceStart = ContextStackSize();
909 }
void C4AulExec::StopDirectExec ( )
inline

Definition at line 85 of file C4AulExec.h.

References C4TimeMilliseconds::Now().

Referenced by DirectExec().

85 { if (fProfiling) tDirectExecTotal += C4TimeMilliseconds::Now() - tDirectExecStart; }
static C4TimeMilliseconds Now()

Here is the call graph for this function:

Here is the caller graph for this function:

Friends And Related Function Documentation

friend class C4AulProfiler
friend

Definition at line 78 of file C4AulExec.h.


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