Jump to content
  • Advertisement
Sign in to follow this  
saejox

When can i use asGetActiveContext

This topic is 2274 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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 Edited by Andreas Jonsson

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!