Browse Source

Fix: compiler

AnnulusGames 1 year ago
parent
commit
e728fd6258
2 changed files with 4 additions and 2 deletions
  1. 3 1
      src/Lua/CodeAnalysis/Compilation/LuaCompiler.cs
  2. 1 1
      src/Lua/LuaFunction.cs

+ 3 - 1
src/Lua/CodeAnalysis/Compilation/LuaCompiler.cs

@@ -402,9 +402,11 @@ public sealed class LuaCompiler : ISyntaxNodeVisitor<ScopeCompilationContext, bo
             ? (ushort)0
             ? (ushort)0
             : (ushort)(node.Nodes.Length + 1);
             : (ushort)(node.Nodes.Length + 1);
 
 
+        var a = context.StackPosition;
+
         CompileExpressionList(node, node.Nodes, b - 1, context);
         CompileExpressionList(node, node.Nodes, b - 1, context);
 
 
-        context.PushInstruction(Instruction.Return((byte)(context.StackPosition - node.Nodes.Length), b), node.Position);
+        context.PushInstruction(Instruction.Return(a, b), node.Position);
 
 
         return true;
         return true;
     }
     }

+ 1 - 1
src/Lua/LuaFunction.cs

@@ -17,7 +17,7 @@ public abstract partial class LuaFunction
             CallPosition = context.SourcePosition,
             CallPosition = context.SourcePosition,
             ChunkName = context.ChunkName ?? LuaState.DefaultChunkName,
             ChunkName = context.ChunkName ?? LuaState.DefaultChunkName,
             RootChunkName = context.RootChunkName ?? LuaState.DefaultChunkName,
             RootChunkName = context.RootChunkName ?? LuaState.DefaultChunkName,
-            VariableArgumentCount = this is Closure closure ? context.ArgumentCount - closure.Proto.ParameterCount : 0,
+            VariableArgumentCount = this is Closure closure ? Math.Max(context.ArgumentCount - closure.Proto.ParameterCount, 0) : 0,
             Function = this,
             Function = this,
         };
         };