Sign in to follow this  
saejox

When can i use asGetActiveContext

Recommended Posts

saejox    714
Hi,

Script calls this
[CODE]
obj.SomeFunc();
[/CODE]
in c++
[CODE]
void OBJ::SomeFunc()
{
asIScriptContext *ctx = asGetActiveContext();
}
[/CODE]

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
SiCrane    11839
Well, [url=http://www.gamedev.net/topic/626917-angelscript-2240-is-here-bug-fix-in-2240a/]the latest version of AngelScript[/url] implemented support for nested calls on a single context. You could give that a try.

Share this post


Link to post
Share on other sites
WitchLord    4677
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:

[code]

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();
}
[/code]

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
saejox    714
[quote name='Andreas Jonsson' timestamp='1341279393' post='4955135']
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:

[code]

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();
}
[/code]

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
[/quote]

i should read changelogs with more care.

thanks a lot.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this