Advertisement

Context not suspending?

Started by June 16, 2015 04:52 AM
2 comments, last by dkrusu 9 years, 5 months ago

I'm trying to create a way to dynamically call methods on a script object, in order to do this I thought I would suspend execution on the active context, create a new context and execute the method, then resume execution on the original context. To start to test this plan I first am trying to suspend the execution and thats where I've hit a issue. I call Suspend on the context and it returns a value of 0, but then if I check the current state it says that it's still active.

Here is my code for suspending, it's part of a template class


bool callMethodVoid(void *objRef, int typeId, const UString& methodName)
{
    asIScriptContext* ctx = asGetActiveContext();
    int r = ctx->Suspend();
    
    printf("Suspend Return: %i\n", r);
    printf("Current State: %i\n", ctx->GetState());
    
    r = ctx->Execute();
    printf("Execute Return: %i\n", r);
    return true;
}

Here is the output for above:


Suspend Return: 0
Current State: 6
Execute Return: -4

It's called in the script language with the following


class Test
{
    void test()
    {
        stdout << "Works!";
    }
}

Object<Test> obj;
Test a;
obj.callMethod(a, "test");

Any idea what would keep the context from suspending?

Thank You,

dkrusu

Calling Abort() on the context also does nothing. I only have one context created and it's single threaded if that helps.

Advertisement

The Suspend() and Abort() will affect how the context proceed, after, the application function called by the script returns.

You can reuse the context from within the application function without calling Suspend() though, instead you should use PushState() and then PopState(). Like this:

bool callMethodVoid(void *objRef, int typeId, const UString& methodName) 
{ 
  asIScriptContext* ctx = asGetActiveContext(); 
 
  // Store the current state, so the context can be reused for a separate call
  ctx->PushState(); 
 
  // prepare and execute the new script
  ctx->Prepare(newFunction);
  ctx->Execute(); 
  
  // Return the original state to continue the execution of the original script before returning control to the VM
  ctx->PopState();
 
  return true; 
}

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 that's exactly what I am looking for. If you have time it might be helpful to state that in the documentation for Suspend() and Abort(), I thought it would immediately take effect.

This topic is closed to new replies.

Advertisement