Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ Bug reports ➜ Help file - table.insert

Help file - table.insert

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Fadedparadox   USA  (91 posts)  Bio
Date Wed 10 Jun 2009 09:38 PM (UTC)

Amended on Wed 10 Jun 2009 09:44 PM (UTC) by Fadedparadox

Message
I ran into a small mistake in the help file for the lua function table.insert that I didn't notice before. It says as follows:

"table.insert (t, pos, value)

Inserts the value at (optional) position 'pos', renumbering existing elements if necessary to make room. Thus the new element becomes the one with index 'pos'.

If called with 2 arguments, the value is inserted at n+1, that is, the end of the table."

It should have value and pos switched in either the prototype or the paragraphs. By the name I assume the prototype.
Top

Posted by Nick Gammon   Australia  (23,162 posts)  Bio   Forum Administrator
Date Reply #1 on Thu 11 Jun 2009 01:17 AM (UTC)

Amended on Thu 11 Jun 2009 01:18 AM (UTC) by Nick Gammon

Message
The help file is in fact correct. I quote from the Lua 5.1 Reference Manual:

http://www.lua.org/manual/5.1/manual.html#5.5




table.insert (table, [pos,] value)

Inserts element value at position pos in table, shifting up other elements to open space, if necessary.

The default value for pos is n+1, where n is the length of the table (see §2.5.5), so that a call table.insert(t,x) inserts x at the end of table t.




Note that the optional argument "pos" is in fact the second argument. This makes "value" the second or third argument, depending on whether or not pos is there.

I didn't put in the brackets, but the text of my help file states that the field pos is optional.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Fadedparadox   USA  (91 posts)  Bio
Date Reply #2 on Thu 11 Jun 2009 01:39 AM (UTC)

Amended on Thu 11 Jun 2009 01:41 AM (UTC) by Fadedparadox

Message
I misunderstood the file, compounded by the fact that in a script I wrote, I switched the variables, seeming to back up what I read it as. Sorry about that!
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


11,703 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.