Browse Source

fix: table.sort extra arguments

Akeit0 7 months ago
parent
commit
b034a01cff
1 changed files with 4 additions and 0 deletions
  1. 4 0
      src/Lua/Standard/TableLibrary.cs

+ 4 - 0
src/Lua/Standard/TableLibrary.cs

@@ -151,6 +151,10 @@ public sealed class TableLibrary
         var arg1 = context.HasArgument(1)
             ? context.GetArgument<LuaFunction>(1)
             : new LuaClosure(context.State, defaultComparer);
+        
+        // discard extra  arguments
+        context = context with { ArgumentCount = 2 };
+        context.Thread.Stack.PopUntil(context.FrameBase+2);
 
         context.Thread.PushCallStackFrame(new() { Base = context.FrameBase, ReturnBase = context.ReturnFrameBase, VariableArgumentCount = 0, Function = arg1 });
         try