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), iTraceStart(-1)
60  { }

Member Function Documentation

void C4AulExec::ClearPointers ( C4Object obj)

Definition at line 140 of file C4AulExec.cpp.

Referenced by C4Game::ClearPointers().

141 {
142  for (C4AulScriptContext *pCtx = pCurCtx; pCtx >= Contexts; pCtx--)
143  {
144  if (pCtx->Obj == obj)
145  pCtx->Obj = nullptr;
146  }
147 }

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 1020 of file C4AulExec.cpp.

References AddDbgRec(), C4VNull, Config, C4ConfigGeneral::DebugRec, 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(), and C4EditCursor::PerformDuplication().

1021 {
1022 #ifdef DEBUGREC_SCRIPT
1023  if (Config.General.DebugRec)
1024  {
1025  AddDbgRec(RCT_DirectExec, szScript, strlen(szScript)+1);
1026  int32_t iObjNumber = p && p->GetPropListNumbered() ? p->GetPropListNumbered()->Number : -1;
1027  AddDbgRec(RCT_DirectExec, &iObjNumber, sizeof(int32_t));
1028  }
1029 #endif
1030  // profiler
1031  StartDirectExec();
1033  if (p && p->IsStatic())
1034  script = p->IsStatic();
1035  else if (p && p->GetDef())
1036  script = p->GetDef();
1037  // Add a new function
1038  auto pFunc = std::make_unique<C4AulScriptFunc>(script, nullptr, nullptr, szScript);
1039  // Parse function
1040  try
1041  {
1042  if (parse_function)
1043  {
1044  // Expect a full function (e.g. "func foo() { return bar(); }")
1045  pFunc->ParseDirectExecFunc(&::ScriptEngine, context);
1046  }
1047  else
1048  {
1049  // Expect a single statement (e.g. "bar()")
1050  pFunc->ParseDirectExecStatement(&::ScriptEngine, context);
1051  }
1052  C4AulParSet Pars;
1053  C4Value vRetVal(Exec(pFunc.get(), p, Pars.Par, fPassErrors));
1054  // profiler
1055  StopDirectExec();
1056  return vRetVal;
1057  }
1058  catch (C4AulError &ex)
1059  {
1060  if(fPassErrors)
1061  throw;
1063  LogCallStack();
1064  StopDirectExec();
1065  return C4VNull;
1066  }
1067 }
C4Config Config
Definition: C4Config.cpp:831
C4Value Exec(C4AulScriptFunc *pSFunc, C4PropList *p, C4Value pPars[], bool fPassErrors)
C4AulErrorHandler * GetErrorHandler() const
Definition: C4Aul.h:175
C4GameScriptHost GameScript
C4AulScriptEngine ScriptEngine
Definition: C4Globals.cpp:43
C4ConfigGeneral General
Definition: C4Config.h:252
void StopDirectExec()
Definition: C4AulExec.h:85
void LogCallStack()
Definition: C4AulExec.cpp:98
virtual class C4PropListStatic * IsStatic()
Definition: C4PropList.h:87
C4Value Par[C4AUL_MAX_Par]
Definition: C4AulFunc.h:30
virtual const char * what() const noexcept
virtual C4Def const * GetDef() const
Definition: C4PropList.cpp:640
void AddDbgRec(C4RecordChunkType eType, const void *pData, int iSize)
Definition: C4Record.cpp:36
virtual void OnError(const char *msg)=0
const C4Value C4VNull
Definition: C4Value.cpp:32
virtual C4PropListStatic * GetPropList()
int32_t DebugRec
Definition: C4Config.h:61
virtual C4PropListNumbered * GetPropListNumbered()
Definition: C4PropList.cpp:658
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 134 of file C4AulExec.cpp.

References LogCallStack().

Referenced by InitCoreFunctionMap().

135 {
137  return true;
138 }
void LogCallStack()
Definition: C4AulExec.cpp:98
C4AulExec AulExec
Definition: C4AulExec.cpp:33

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

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

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 98 of file C4AulExec.cpp.

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

99 {
100  for (C4AulScriptContext *pCtx = pCurCtx; pCtx >= Contexts; pCtx--)
101  pCtx->dump(StdStrBuf(" by: "));
102 }

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 911 of file C4AulExec.cpp.

912 {
913  if (iTraceStart < 0)
914  iTraceStart = ContextStackSize();
915 }
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: