diff --git a/src/Lua/LuaTable.cs b/src/Lua/LuaTable.cs index 3afe4263..d510dbb5 100644 --- a/src/Lua/LuaTable.cs +++ b/src/Lua/LuaTable.cs @@ -12,7 +12,7 @@ public LuaTable() : this(8, 8) public LuaTable(int arrayCapacity, int dictionaryCapacity) { - array = new LuaValue[Math.Max(arrayCapacity, 8)]; + array = arrayCapacity>1?new LuaValue[arrayCapacity] :[]; dictionary = new(dictionaryCapacity); } diff --git a/src/Lua/Standard/TableLibrary.cs b/src/Lua/Standard/TableLibrary.cs index 2667aa45..dfb2f83d 100644 --- a/src/Lua/Standard/TableLibrary.cs +++ b/src/Lua/Standard/TableLibrary.cs @@ -130,18 +130,14 @@ public ValueTask Remove(LuaFunctionExecutionContext context, CancellationTo var n = (int)n_arg; - if (n <= 0 || n > table.GetArraySpan().Length) + if ((!context.HasArgument(1) && n == 0) || n == table.GetArraySpan().Length + 1) { - if (!context.HasArgument(1) && n == 0) - { - return new(context.Return(LuaValue.Nil)); - } - - throw new LuaRuntimeException(context.Thread, "bad argument #2 to 'remove' (position out of bounds)"); + return new(context.Return(LuaValue.Nil)); } - else if (n > table.ArrayLength) + + if (n <= 0 || n > table.GetArraySpan().Length) { - return new(context.Return(LuaValue.Nil)); + throw new LuaRuntimeException(context.Thread, "bad argument #2 to 'remove' (position out of bounds)"); } return new(context.Return(table.RemoveAt(n)));