Skip to content

Commit dd03393

Browse files
authored
Merge pull request #188 from nuskey8/fix-tab-remove-and-initial-size
fix: adjust LuaTable initialization and fix remove method argument va…
2 parents 10af33c + a20cc28 commit dd03393

File tree

2 files changed

+6
-10
lines changed

2 files changed

+6
-10
lines changed

src/Lua/LuaTable.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public LuaTable() : this(8, 8)
1212

1313
public LuaTable(int arrayCapacity, int dictionaryCapacity)
1414
{
15-
array = new LuaValue[Math.Max(arrayCapacity, 8)];
15+
array = arrayCapacity>1?new LuaValue[arrayCapacity] :[];
1616
dictionary = new(dictionaryCapacity);
1717
}
1818

src/Lua/Standard/TableLibrary.cs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -130,18 +130,14 @@ public ValueTask<int> Remove(LuaFunctionExecutionContext context, CancellationTo
130130

131131
var n = (int)n_arg;
132132

133-
if (n <= 0 || n > table.GetArraySpan().Length)
133+
if ((!context.HasArgument(1) && n == 0) || n == table.GetArraySpan().Length + 1)
134134
{
135-
if (!context.HasArgument(1) && n == 0)
136-
{
137-
return new(context.Return(LuaValue.Nil));
138-
}
139-
140-
throw new LuaRuntimeException(context.Thread, "bad argument #2 to 'remove' (position out of bounds)");
135+
return new(context.Return(LuaValue.Nil));
141136
}
142-
else if (n > table.ArrayLength)
137+
138+
if (n <= 0 || n > table.GetArraySpan().Length)
143139
{
144-
return new(context.Return(LuaValue.Nil));
140+
throw new LuaRuntimeException(context.Thread, "bad argument #2 to 'remove' (position out of bounds)");
145141
}
146142

147143
return new(context.Return(table.RemoveAt(n)));

0 commit comments

Comments
 (0)