Table remove by negative fix#132
Table remove by negative fix#132havietisov wants to merge 3 commits intomoonsharp-devs:legacy/2.0from
Conversation
…pos", stopping exception from being thrown
…, than a number, into table.remove table.remove now not accept any negative indices table.remove now accept 0 index if table length equal to zero
This check already is in the base code..
Not true. Out-of-bound indices are valid in Lua and should not throw an exception, just return nil. 0 in an empty table is just a special case of this. |
old one never worked. I fixed it. had a huge headache because of infinitely growing table while passing string as index for table.remove() |
LimpingNinja
left a comment
There was a problem hiding this comment.
- Needs full coverage (other files missed)
- Validate tests existence coverage for examples provided
- Ensure it covers the stringasint edge
| throw new ScriptRuntimeException(string.Format("bad argument #2 to 'remove' (number expected, got {0})", args[1].Type.ToLuaTypeString())); | ||
|
|
||
| int pos = vpos.IsNil() ? len : (int)vpos.Number; | ||
| case DataType.Number: |
There was a problem hiding this comment.
> a = { 10, 15, 20, 25, 30 }
> table.remove(a,1)
10
> table.remove(a,"fifty")
stdin:1: bad argument #2 to 'remove' (number expected, got string)
> table.remove(a,"15")
stdin:1: bad argument #1 to 'remove' (position out of bounds)
> table.remove(a,"1")
15
More precise to pure lua behaviour : addional exception added, changed odd and improper check that caused table overflow upon passing something non-numerical as argument to table.remove().
table.remove now accept only numbers and nil as indices (same as pure lua does)
table.remove now does nothing if table is empty and passed index is 0 (same as pure lua does)