Skip to content
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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

havietisov
Copy link

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)

Rygor Borodoolin added 3 commits March 11, 2016 14:20
…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
@xanathar
Copy link
Member

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)

This check already is in the base code..

table.remove now does nothing if table is empty and passed index is 0 (same as pure lua does)

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.

@havietisov
Copy link
Author

havietisov commented May 19, 2016

This check already is in the base code

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 LimpingNinja self-requested a review January 16, 2020 00:51
Copy link
Contributor

@LimpingNinja LimpingNinja left a 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:
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants