forked from Mirrors/openclonk
Remove C4AulContext::Caller
parent
815d5a895a
commit
fb4bac65be
|
@ -190,7 +190,6 @@ struct C4AulContext
|
|||
{
|
||||
C4Object *Obj;
|
||||
C4PropList *Def;
|
||||
struct C4AulScriptContext *Caller;
|
||||
};
|
||||
|
||||
// execution context
|
||||
|
|
|
@ -108,6 +108,29 @@ void C4AulExec::LogCallStack()
|
|||
pCtx->dump(StdStrBuf(" by: "));
|
||||
}
|
||||
|
||||
C4String *C4AulExec::FnTranslate(C4AulContext *ctx, C4String *text)
|
||||
{
|
||||
if (!text || text->GetData().isNull()) return NULL;
|
||||
// Find correct script: translations of the context if possible, containing script as fallback
|
||||
C4AulScript *script = NULL;
|
||||
if (ctx->Def && ctx->Def->GetDef())
|
||||
script = &(ctx->Def->GetDef()->Script);
|
||||
else
|
||||
script = AulExec.pCurCtx[-1].Func->pOrgScript;
|
||||
assert(script);
|
||||
try
|
||||
{
|
||||
return ::Strings.RegString(script->Translate(text->GetCStr()).c_str());
|
||||
}
|
||||
catch (C4LangStringTable::NoSuchTranslation &)
|
||||
{
|
||||
DebugLogF("WARNING: Translate: no translation for string \"%s\"", text->GetCStr());
|
||||
// Trace
|
||||
AulExec.LogCallStack();
|
||||
return text;
|
||||
}
|
||||
}
|
||||
|
||||
void C4AulExec::ClearPointers(C4Object * obj)
|
||||
{
|
||||
#if 0
|
||||
|
@ -145,7 +168,6 @@ C4Value C4AulExec::Exec(C4AulScriptFunc *pSFunc, C4PropList * p, C4Value *pnPars
|
|||
ctx.Func = pSFunc;
|
||||
ctx.TemporaryScript = fTemporaryScript;
|
||||
ctx.CPos = NULL;
|
||||
ctx.Caller = NULL;
|
||||
PushContext(ctx);
|
||||
|
||||
// Execute
|
||||
|
@ -832,7 +854,6 @@ C4AulBCC *C4AulExec::Call(C4AulFunc *pFunc, C4Value *pReturn, C4Value *pPars, C4
|
|||
if (ctx.Obj && !ctx.Obj->Status)
|
||||
throw new C4AulExecError(ctx.Obj, "using removed object");
|
||||
ctx.Def = pContext;
|
||||
ctx.Caller = pCurCtx;
|
||||
ctx.Return = pReturn;
|
||||
ctx.Pars = pPars;
|
||||
ctx.Vars = pCurVal + 1;
|
||||
|
@ -859,7 +880,6 @@ C4AulBCC *C4AulExec::Call(C4AulFunc *pFunc, C4Value *pReturn, C4Value *pPars, C4
|
|||
if (ctx.Obj && !ctx.Obj->Status)
|
||||
throw new C4AulExecError(ctx.Obj, "using removed object");
|
||||
ctx.Def = pContext;
|
||||
ctx.Caller = pCurCtx;
|
||||
|
||||
#ifdef DEBUGREC_SCRIPT
|
||||
StdStrBuf sCallText;
|
||||
|
@ -911,7 +931,6 @@ C4AulBCC *C4AulExec::Call(C4AulFunc *pFunc, C4Value *pReturn, C4Value *pPars, C4
|
|||
C4AulScriptContext ctx;
|
||||
ctx.Obj = pContext ? pContext->GetObject() : 0;
|
||||
ctx.Def = pContext;
|
||||
ctx.Caller = pCurCtx;
|
||||
ctx.Return = pReturn;
|
||||
ctx.Pars = pPars;
|
||||
ctx.Vars = pPars + pFunc->GetParCount();
|
||||
|
@ -1059,7 +1078,6 @@ C4Value C4AulFunc::Exec(C4PropList * p, C4AulParSet* pPars, bool fPassErrors)
|
|||
C4AulContext ctx;
|
||||
ctx.Obj = p ? p->GetObject() : NULL;
|
||||
ctx.Def = p;
|
||||
ctx.Caller = NULL;
|
||||
// execute
|
||||
return Exec(&ctx, pPars ? pPars->Par : C4AulParSet().Par, fPassErrors);
|
||||
}
|
||||
|
|
|
@ -70,6 +70,7 @@ public:
|
|||
int GetContextDepth() const { return pCurCtx - Contexts + 1; }
|
||||
C4AulScriptContext *GetContext(int iLevel) { return iLevel >= 0 && iLevel < GetContextDepth() ? Contexts + iLevel : NULL; }
|
||||
void LogCallStack();
|
||||
static C4String *FnTranslate(C4AulContext *ctx, C4String *text);
|
||||
void ClearPointers(C4Object *);
|
||||
|
||||
private:
|
||||
|
|
|
@ -534,29 +534,6 @@ static bool FnStopScriptProfiler(C4AulContext *ctx)
|
|||
return true;
|
||||
}
|
||||
|
||||
static C4String *FnTranslate(C4AulContext *ctx, C4String *text)
|
||||
{
|
||||
if (!text || text->GetData().isNull()) return NULL;
|
||||
// Find correct script: translations of the context if possible, containing script as fallback
|
||||
C4AulScript *script = NULL;
|
||||
if (ctx->Def && ctx->Def->GetDef())
|
||||
script = &(ctx->Def->GetDef()->Script);
|
||||
else
|
||||
script = ctx->Caller->Func->pOrgScript;
|
||||
assert(script);
|
||||
try
|
||||
{
|
||||
return ::Strings.RegString(script->Translate(text->GetCStr()).c_str());
|
||||
}
|
||||
catch (C4LangStringTable::NoSuchTranslation &)
|
||||
{
|
||||
DebugLogF("WARNING: Translate: no translation for string \"%s\"", text->GetCStr());
|
||||
// Trace
|
||||
AulExec.LogCallStack();
|
||||
return text;
|
||||
}
|
||||
}
|
||||
|
||||
static Nillable<C4String *> FnGetConstantNameByValue(C4AulContext *ctx, int value, Nillable<C4String *> name_prefix, int idx)
|
||||
{
|
||||
C4String *name_prefix_s = name_prefix;
|
||||
|
@ -666,5 +643,5 @@ void InitCoreFunctionMap(C4AulScriptEngine *pEngine)
|
|||
AddFunc(pEngine, "this", Fn_this);
|
||||
AddFunc(pEngine, "GetConstantNameByValue", FnGetConstantNameByValue, false);
|
||||
|
||||
AddFunc(pEngine, "Translate", FnTranslate);
|
||||
AddFunc(pEngine, "Translate", C4AulExec::FnTranslate);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue