This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
CCDan's profile picture

textutils.tabulate & Table in Tables

Started by CCDan, 01 July 2013 - 06:13 AM
CCDan #1
Posted 01 July 2013 - 08:13 AM
I'm trying to use textutils.tabulate to output tables within tables. However the amount of tables are unknown. How can I loop through available tables within textutils.tabulate?

Example below:

local tTable = {
{"Heading1", "Heading2", "Heading3"},
{"Entry1a", "Entry1b", "Entry1c"},
{"Entry2a", "Entry2b", "Entry2c"}}
--tabulate tables, knowing first entry will always exist
textutils.tabulate(tTable[1], ???)

Thanks
Lyqyd #2
Posted 01 July 2013 - 02:05 PM
Split into new topic.
Zudo #3
Posted 01 July 2013 - 02:36 PM
I think you need to do something like this

for x = 1, #tTables do
 textutils.tabulate(tTables[x])
end

This is probably not the best way to do it tho…
MysticT #4
Posted 01 July 2013 - 02:53 PM
If you are using numerical indices, you can use unpack. unpack returns all the values stored in the table (only for numerical indices), so you can then pass them to the tabulate function. Like this:

textutils.tabulate(unpack(tTables))
CCDan #5
Posted 02 July 2013 - 07:19 PM
Thank you MysticT this worked great.