ThreadStatus ILuaAPI.Resume(ILuaState from, int numArgs) { LuaState fromState = from as LuaState; NumCSharpCalls = (fromState != null) ? fromState.NumCSharpCalls + 1 : 1; NumNonYieldable = 0; // allow yields Utl.ApiCheckNumElems(this, (Status == ThreadStatus.LUA_OK) ? numArgs + 1 : numArgs); var resumeParam = new ResumeParam(); resumeParam.L = this; resumeParam.firstArg = Top.Index - numArgs; ThreadStatus status = D_RawRunProtected(DG_Resume, ref resumeParam); if (status == ThreadStatus.LUA_RESUME_ERROR) // error calling `lua_resume'? { status = ThreadStatus.LUA_ERRRUN; } else // yield or regular error { while (status != ThreadStatus.LUA_OK && status != ThreadStatus.LUA_YIELD) // error? { if (Recover(status)) // recover point? { var unrollParam = new UnrollParam(); unrollParam.L = this; status = D_RawRunProtected(DG_Unroll, ref unrollParam); } else // unrecoverable error { Status = status; // mark thread as `dead' SetErrorObj(status, Top); CI.TopIndex = Top.Index; break; } } Utl.Assert(status == Status); } NumNonYieldable = 1; // do not allow yields NumCSharpCalls--; Utl.Assert(NumCSharpCalls == ((fromState != null) ? fromState.NumCSharpCalls : 0)); return(status); }
ThreadStatus ILuaAPI.Resume( ILuaState from, int numArgs ) { LuaState fromState = from as LuaState; NumCSharpCalls = (fromState != null) ? fromState.NumCSharpCalls + 1 : 1; NumNonYieldable = 0; // allow yields Utl.ApiCheckNumElems( this, (Status == ThreadStatus.LUA_OK) ? numArgs + 1 : numArgs ); var resumeParam = new ResumeParam(); resumeParam.L = this; resumeParam.firstArg = Top.Index-numArgs; ThreadStatus status = D_RawRunProtected( DG_Resume, ref resumeParam ); if( status == ThreadStatus.LUA_RESUME_ERROR ) // error calling `lua_resume'? { status = ThreadStatus.LUA_ERRRUN; } else // yield or regular error { while( status != ThreadStatus.LUA_OK && status != ThreadStatus.LUA_YIELD ) // error? { if( Recover( status ) ) // recover point? { var unrollParam = new UnrollParam(); unrollParam.L = this; status = D_RawRunProtected( DG_Unroll, ref unrollParam ); } else // unrecoverable error { Status = status; // mark thread as `dead' SetErrorObj( status, Top ); CI.TopIndex = Top.Index; break; } } Utl.Assert( status == Status ); } NumNonYieldable = 1; // do not allow yields NumCSharpCalls--; Utl.Assert( NumCSharpCalls == ((fromState != null) ? fromState.NumCSharpCalls : 0) ); return status; }
private static void UnrollWrap(ref UnrollParam param) { param.L.Unroll(); }