public static void resume(LuaInterop lua) { LuaThread co = lua.Argument <LuaThread>(0); co.BeginResume(lua.ArgumentCount - 1); for (int argument = 0; argument < lua.ArgumentCount - 1; ++argument) { co.ResumeArgument(argument, lua.Argument(argument)); } int resultCount; try { resultCount = co.Resume(LuaThread.VarResult); } catch (Exception e) { lua.BeginReturn(2); lua.ReturnResult(0, false); lua.ReturnResult(1, e.Message); lua.EndReturn(); return; } lua.BeginReturn(resultCount + 1); lua.ReturnResult(0, true); for (int result = 0; result < resultCount; ++result) { lua.ReturnResult(result + 1, co.ResumeResult(result)); } co.EndResume(); lua.EndReturn(); }
internal override void Call(LuaThread thread, int frameBase, int argumentCount, int resultCount) { coroutine.BeginResume(argumentCount); // Copy arguments. for (int argument = 0; argument < argumentCount; ++argument) { coroutine.ResumeArgument(argument, thread.Stack[frameBase + 1 + argument]); } // Resume. int actualResultCount = coroutine.Resume(resultCount); // Calculate number of results we want. int copyCount; if (resultCount == -1) { copyCount = actualResultCount; thread.Top = frameBase + actualResultCount - 1; } else { copyCount = Math.Min(resultCount, actualResultCount); } // Copy results. for (int result = 0; result < copyCount; ++result) { thread.Stack[frameBase + result] = coroutine.ResumeResult(result); } for (int result = copyCount; result < resultCount; ++result) { thread.Stack[frameBase + result] = null; } coroutine.EndResume(); }