lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On 23/02/2014 13.37, steve donovan wrote:
That's nice to know! In the meantime, have a look at ilua

https://github.com/ilua/ilua

which uses an exploratory compile trick to remove the restriction. It
also has a default pretty-printer which is good enough for most
purposes.

A basic table printer that could perhaps be useful in the standalone interpreter could be:

- first print all the entries from 1 to #t using ipairs()
- mark the last one with '#'
- then print all entries with pairs() except those printed before

For example, this table:

{ 'monday', 'tuesday', 'wednesday', 'thursday', 'friday';
  [27] = 'payday', [100] = { 1, 2, 3 },
  monday = 1, tuesday = 2, wednesday = 3, thursday = 4, friday = 5 }

could print like this:

1 = 'monday'
2 = 'tuesday'
3 = 'wednesday'
4 = 'thursday'
5 = 'friday'
#
'wednesday' = 3
'monday' = 1
100 = table: 00468538
'friday' = 5
'thursday' = 4
27 = 'payday'
'tuesday' = 2

If declared as a function (e.g. __table_printer()) the table printer would be replaceable with the usual command line options, or possibly disabled with a new option.

As an alternative, a sign different from '=' could be used to invoke the table printer, or generally speaking a more informative printer.
(I don't dare venturing into table recursion territory)

P.S. I'm still trying to decide if I like this. Probably not much: it just saves a few keys from calling a table printer loaded via LUA_INIT.

--
  Enrico