CoroutineStatusFunction.cs 765 B

1234567891011121314151617181920212223
  1. namespace Lua.Standard.Coroutines;
  2. public sealed class CoroutineStatusFunction : LuaFunction
  3. {
  4. public const string FunctionName = "status";
  5. public override string Name => FunctionName;
  6. protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
  7. {
  8. var thread = context.ReadArgument<LuaThread>(0);
  9. buffer.Span[0] = thread.GetStatus() switch
  10. {
  11. LuaThreadStatus.Normal => "normal",
  12. LuaThreadStatus.Suspended => "suspended",
  13. LuaThreadStatus.Running => "running",
  14. LuaThreadStatus.Dead => "dead",
  15. _ => throw new NotImplementedException(),
  16. };
  17. return new(1);
  18. }
  19. }