Browse Source

Add: bit32.bnot

AnnulusGames 1 year ago
parent
commit
3e13e8a403
1 changed files with 14 additions and 0 deletions
  1. 14 0
      src/Lua/Standard/Bitwise/BnotFunction.cs

+ 14 - 0
src/Lua/Standard/Bitwise/BnotFunction.cs

@@ -0,0 +1,14 @@
+namespace Lua.Standard.Bitwise;
+
+public sealed class BnotFunction : LuaFunction
+{
+    public override string Name => "bnot";
+    public static readonly BnotFunction Instance = new();
+
+    protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
+    {
+        var value = Bit32Helper.ToUInt32(context.GetArgument<double>(0));
+        buffer.Span[0] = ~value;
+        return new(1);
+    }
+}