-
Notifications
You must be signed in to change notification settings - Fork 219
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Table remove by negative fix #132
base: master
Are you sure you want to change the base?
Table remove by negative fix #132
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() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Needs full coverage (other files missed)
- Validate tests existence coverage for examples provided
- Ensure it covers the stringasint edge
|
||
int pos = vpos.IsNil() ? len : (int)vpos.Number; | ||
case DataType.Number: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
> 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)