Jump to content
  • Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal
  • 0
Nexarius

table.concat()

Question

1 answer to this question

Recommended Posts

  • 1
  • Solution

When table.concat is called without specifying the fourth argument it's assumed to be #list. The default value for the third argument is 1.

Operator # returns any of the table's borders. A border is a natural index of a non-nil element that is followed by a nil element.

There's only one border in sequences. In table {1, 1, 2, 3, 5, 8}, the border is 6.

Your table is different, as it has more than one border: 0 and 2. The border the operator # chooses depends on the Lua table implementation -- it could be 0 as well as 2 depending on how the table was populated and its non-numeric key elements' memory addresses. In your case, the implementation has chosen 0.

So you have implicitly called table.concat(a, "", 1, 0) and because the end index was less than the starting index, table.concat returned an empty string, which was then printed to the console.

More info:

  1. https://www.lua.org/manual/5.3/manual.html#pdf-table.concat
  2. https://www.lua.org/manual/5.3/manual.html#3.4.7
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.