Advertisement Jump to content
Sign in to follow this  

script context and nested calls (PushState/PopState)

This topic is 1855 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

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
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!