script context and nested calls (PushState/PopState)

Started by
3 comments, last by iraxef 10 years, 4 months ago

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.

Advertisement

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.

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

Thanks. Once you've PushState(), the outer execution isn't continuing to run though, is it?

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:

application::DoProcessing
  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.

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

Thank you.

This topic is closed to new replies.

Advertisement