BxorFunction.cs 787 B

123456789101112131415161718192021222324252627
  1. namespace Lua.Standard.Bitwise;
  2. public sealed class BxorFunction : LuaFunction
  3. {
  4. public override string Name => "bxor";
  5. public static readonly BxorFunction Instance = new();
  6. protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
  7. {
  8. if (context.ArgumentCount == 0)
  9. {
  10. buffer.Span[0] = uint.MaxValue;
  11. return new(1);
  12. }
  13. var value = Bit32Helper.ToUInt32(context.GetArgument<double>(0));
  14. for (int i = 1; i < context.ArgumentCount; i++)
  15. {
  16. var v = Bit32Helper.ToUInt32(context.GetArgument<double>(i));
  17. value ^= v;
  18. }
  19. buffer.Span[0] = value;
  20. return new(1);
  21. }
  22. }