Advertisement

When can i use asGetActiveContext

Started by July 02, 2012 10:38 PM
2 comments, last by saejox 12 years, 5 months ago
Hi,

Script calls this

obj.SomeFunc();

in c++

void OBJ::SomeFunc()
{
asIScriptContext *ctx = asGetActiveContext();
}


i get the ctx that called the script. thats fine.
but now i want to call some other script script function inside SomeFunc()
i cant call ctx->Prepare(func);
i do not want to create a new context (very slow), and dont have access to my context pool since this an extension.

how do call my script function without creating a new context?

thanks
Well, the latest version of AngelScript implemented support for nested calls on a single context. You could give that a try.
Advertisement
Pre-2.24.0 the asGetActiveContext was only used to get the context for reporting a script exception, suspending the execution, getting user data from it, or possibly inspecting the call stack.

But with 2.24.0 you can now reuse the context for a new script call without having to create another context or access a context pool. It's done something like this:



void OBJ::SomeFunc()
{
asIScriptContext *ctx = asGetActiveContext();

// store the current state
ctx->PushState();

// call the new function
ctx->Prepare(...);
ctx->Execute(...);

// restore the previous state to continue the original script
ctx->PopState();
}


asGetActiveContext() will return the context that is currently executing in the current thread, so you can use it even if you're calling scripts from multiple threads in parallel.

Regards,
Andreas

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game


Pre-2.24.0 the asGetActiveContext was only used to get the context for reporting a script exception, suspending the execution, getting user data from it, or possibly inspecting the call stack.

But with 2.24.0 you can now reuse the context for a new script call without having to create another context or access a context pool. It's done something like this:



void OBJ::SomeFunc()
{
asIScriptContext *ctx = asGetActiveContext();

// store the current state
ctx->PushState();

// call the new function
ctx->Prepare(...);
ctx->Execute(...);

// restore the previous state to continue the original script
ctx->PopState();
}


asGetActiveContext() will return the context that is currently executing in the current thread, so you can use it even if you're calling scripts from multiple threads in parallel.

Regards,
Andreas


i should read changelogs with more care.

thanks a lot.

This topic is closed to new replies.

Advertisement