Skip to content

Commit b478cbf

Browse files
authored
Merge pull request #82 from Veslo5/main
Ensure array capacity only if index is larger than array length with table.insert function
2 parents a26a4ab + 6eef1f2 commit b478cbf

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/Lua/LuaTable.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,11 @@ public void Insert(int index, LuaValue value)
168168
}
169169

170170
var arrayIndex = index - 1;
171-
EnsureArrayCapacity(array.Length + 1);
171+
172+
if (index > array.Length || array[^1].Type != LuaValueType.Nil)
173+
{
174+
EnsureArrayCapacity(array.Length + 1);
175+
}
172176

173177
if (arrayIndex != array.Length - 1)
174178
{

0 commit comments

Comments
 (0)