lua-users home
lua-l archive

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


Rima has an "enhanced" tostring that I've called repr (I pinched the name from python, but I don't really know much about python's repr).

It's the same as tostring (so there's a corresponding __repr) except that it takes a second format argument. The format is a table of, well, format information, whatever suits you really. I use it to keep a default number format and control how I output rima objects (prettily or a as a tree dump, and one day it might support ouput in LaTeX or in re-readable lua).

Because the format argument is optional, setting a metatable's __tostring to its __repr works just fine.

Is there any general interest in such a thing? It's really not a big bit of code, but if it was of interest it'd be nice if it was standardised in some sense.

One problem repr presents is that now you have to handle outputting a range of possible objects in a range of possible formats - there are objectsxformats options. Should each object's repr be smart enough to handle all formats? Should format tables be smart enough to handle all objects?