fmt module: format and style anything


The fmt module is a small (~200 lines of code) module which formats arbitrary lua types as well as enables users to define formatting for their own metatypes via the function __fmt(self, fmter) method.
It also provides several helper methods such as print, assertf and errorf, making it more convienent to print or format types. In addition, it sets io.fmt = io.fmt or Fmt{to=io.stderr}, providing a default hook for #ds.log and command line utilities to write formatted text to.
The #fmt.Fmt interface (which is passed to a metaty's __fmt method if present) accepts both write (like a file) and styled("style", "styled text", ..."non-styled text"), enabling the asciicolor library (or your own library!) to provide user-configurable colors for specific styles which integrate with the vt100 library and the cxt libraries. This is used throughout civlua to provide user-configurable (and optional) color to the terminal, web-pages and the civlua editor.

API / Architecture


#fmt.Fmt defines the formatter which has methods/settings: (argument): where to write to. Default is to push to self, treating Fmt as a list of strings (which you can call table.concat on).
* style [boolean