When calling script hooks from another script, re-use existing script context.
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2020-02-08 09:39:36 +01:00
parent b8b692d4d6
commit af2f62a278
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
1 changed files with 15 additions and 4 deletions

View File

@ -33,7 +33,14 @@ public:
auto s = _type->Get##name(); \
if (!s.Exists) \
return; \
auto ctx = _ctxPool->RequestContext(); \
auto ctx = asGetActiveContext(); \
bool newContext = false; \
if (ctx == nullptr) { \
ctx = _ctxPool->RequestContext(); \
newContext = true; \
} else { \
ctx->PushState(); \
} \
ctx->Prepare(s.Function); \
ctx->SetObject(_obj); \
setup; \
@ -41,7 +48,11 @@ public:
if (scriptResult != 0) { \
throw CreatureException("Script didn't finish properly; message " + std::to_string(scriptResult)); \
} \
_ctxPool->ReturnContextToPool(ctx);
if (newContext) { \
_ctxPool->ReturnContextToPool(ctx); \
} else { \
ctx->PopState(); \
}
void Stack() override { CALLHOOK(Stack, ); }