table.concat and table.condense
Posted: Wed Mar 02, 2011 11:15 am
I've rewritten table.concat, making use of a new function I wrote. This allows you to have a nil value in your table, such as
display(stuff)
table {
1: 5
2: 50
3: 52
8: 31
}
In the above, notice keys 4 - 7 are nil. We can either make use of table.condense to rewrite this table, or we can make it simply return the condensed form without rewriting. The new table.concat makes use of it without rewriting.
The new table.concat would display: '3hi10'
display(stuff)
table {
1: 5
2: 50
3: 52
8: 31
}
In the above, notice keys 4 - 7 are nil. We can either make use of table.condense to rewrite this table, or we can make it simply return the condensed form without rewriting. The new table.concat makes use of it without rewriting.
table.concat (table [, sep [, i [, j [,skiptable]]]])
Given an array where all elements are strings, numbers, OR NIL, returns table..sep..table[i+1] ยทยทยท sep..table[j], skipping the nil values. The default value for sep is the empty string, the default for i is 1, and the default for j is the length of the table. If i is greater than j, returns the empty string. If skiptable is true, tables will be skipped instead of generating an incorrect type error. Default for skiptable is true.
table.condense(table [,rewrite])
Given a table, it will condense it to the correct form for an ipairs to handle. If rewrite is true, it will rewrite it to the table. If rewrite is false, it will return the condensed form. The default for rewrite is true.
A small function to test condense and concat:
the old table.concat would display: '3'
The new table.concat would display: '3hi10'