Before calling the context's Execute method, set the callback function like so:
void ExecuteScript() { DWORD timeOut; ctx->SetLineCallback(asFUNCTION(LineCallback), &timeOut, asCALL_CDECL); int status = asEXECUTION_SUSPENDED; while( status == asEXECUTION_SUSPENDED ) { // Allow the long running script to execute for 10ms timeOut = timeGetTime() + 10; status = ctx->Execute(); // The execution was suspended, now we can do something else before // continuing the execution with another call to Execute(). ... } } void LineCallback(asIScriptContext *ctx, DWORD *timeOut) { // If the time out is reached we suspend the script if( *timeOut < timeGetTime() ) ctx->Suspend(); }
Take a look at the sample Events to see this working.