lua-users home
lua-l archive

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

Hi all,

The Lua interactive prompt contains two shortcuts that make it a bit
more pleasant to use:

 - Lines of the form '= ...' are translated to 'return ...'
 - Lines starting with 'return ...' are translated to 'print(...)'

For a long time I used $LUA_INIT to redefine print() to a pretty
printer* for Lua values (primarily tables). Unfortunately this can break
Lua programs that use print() for output instead of io.write() and
assume it works exactly the same as print() from the base library. There
is a very easy way to fix this: Change the second rule above to call a
function that is dedicated to pretty printing of values in the
interactive prompt, e.g. prettyprint(), dump(), something like that (I
don't care about the name as long as it's different from print() :-).

My question is: Are the Lua authors open to changing this? I would love
to always have pretty printing in the interactive prompt without
breaking any Lua programs that assume print() has it's regular behavior
of calling tostring() on all arguments and printing the resulting
strings delimited by tabs.

Thanks for your consideration,

 - Peter

PS. If anyone knows of a reliable way for my redefined print() function
to recognize whether it's being executed directly from the interactive
prompt that would work just as well.