Sign in to follow this  

script context and nested calls (PushState/PopState)

Recommended Posts

What are the expected uses of PushState/PopState on a script context?


One gotcha I'm thinking of is what if the script function you called via a nested-context-call suspends itself.. would that not also suspend the execution of the 'outer' function (which might be unexpected/undesirable)?


If you call the same script function (as the one that reached out to C++ and got it to make a nested call back into script).. it will have a different local stack/state than the 'outer' script function, due to the nested call, right?


Thank you very much.

Share this post

Link to post
Share on other sites

The use for Push/PopState is exactly how you imagine it. When a script calls an application function that needs to call another script function you can reuse the active context rather than create a new one. After calling PushState() the context can be used exactly like a newly created context, i.e. you'd call Prepare(), SetArg...() and Execute() to make a call to the new function.


When the context is suspended only the inner-most execution is suspended. The outer execution will only be suspended if the application first calls PopState() and then Suspend() again.

Share this post

Link to post
Share on other sites

The outer execution will only continue once the PopState() is called.


Remember that normally Push/PopState() is called from a function called by the context, so the application call stack will look something like this:


  asCScriptContext::Execute                    <-- outer execution
    application::RegisteredFunction          <-- application registered function that called PushState
      asCScriptContext::Execute                <-- inner execution


The outer execution can only continue after the application registered function returns.




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