Skip to content

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

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:
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