lua-users home
lua-l archive

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


Hi all,

Penlight is a set of pure Lua libraries only depending on
LuaFileSystem [1] which was originally heavily inspired by the Python
standard libraries, but has since moved off in its own interesting
directions

Clone or grab from downloads at https://github.com/stevedonovan/Penlight
The documentation is here:
http://stevedonovan.github.com/Penlight/api/index.html
Impatient LuaRocks users can use this SCM rockspec to install from the
master branch: http://stevedonovan.github.com/files/penlight-scm-1.rockspec

Notable Features:

- pl.path and pl.dir provide filesystem functions similar to the
equivalent Python libraries (this requires lfs)
- pl.text and pl.stringx are implementations of Python's text and
string functions (e.g. formatting and substituting text)
- pl.class provides a simple consistent OOP framework; available
classes are pl.List, pl.Map, pl.OrderedMap and pl.Set
- extended operations on tables and iterators ('sequences'[2])
pl.tablex, pl.seq and pl.array2d (for two-dimensional arrays)
- pl.data is a tabular data reader which includes the ability to
perform simple queries on the data
- pl.pretty provides fairly robust conversions between tables and
strings, notably pretty-printing and paranoid table loading
- pl.template is our old friend Rici Lake's SlightlyLessSimpleLuaPreprocessor
- pl.stringio allows you to work with text with Lua 5.2 file-like
objects (e.g. open a string and read from it)
- pl.app provides useful stuff for applications like require_here()
(rebasing require() to current directory) and parse_args()
- pl.lapp is a mini-framework for command-line applications
- pl.comprehension is David Manura's list comprehension librariy
- pl.xml works with LuaExpat LOM format and provides
'htmlification'-style constructors and pretty-printing

This is mostly a bugfix release, and it has been a very collaborative effort!

Geoff Leyland:  lapp improvements
Kevin Cox: more argument type assertions in source, and making
List:transform() return itself
Egil Hjelmeland contributed a much faster version of tablex.deepcompare
Pierre Chapuis improved cycle detection in pretty.write
Ross Berteig fixed text.indent
Eric S. Bullington pointed out that Set.__tostring does not _always_ work

On the features side,
- List.range(n) now works and returns {1,...n}
- Lua 5.2: with Sets, can use #, and OrderedMap defines __pairs
- utils.array_tostring turns a list of values into a list of strings -
a very useful building block
- config.read has been improved; there is a keysep option, and a smart
option for auto-detecting common Unix file formats.

Quoting the relevant test:

function smart(f)
    f = stringio.open(f)
    return config.read(f,{smart=true})
end

-- /proc/XXXX/status
asserteq (smart[[
Name:	bash
State:	S (sleeping)
Pid:	30071
Groups:	4 20 24 46 105 119 122 1000
VmPeak:	    6780 kB
VmSize:	    6716 kB
]],{
  Pid = 30071,
  VmSize = 6716,
  State = "S (sleeping)",
  Name = "bash",
  Groups = "4 20 24 46 105 119 122 1000",
  VmPeak = 6780,
  TracerPid = 0
})

-- updatedb.conf
asserteq (smart[[
PRUNE_BIND_MOUNTS="yes"
# PRUNENAMES=".git .bzr .hg .svn"
PRUNEPATHS="/tmp /var/spool /media"
PRUNEFS="NFS nfs nfs4 rpc_pipefs afs binfmt_misc proc smbfs autofs
iso9660 ncpfs coda devpts ftpfs devfs mfs shfs sysfs cifs lustre_lite
tmpfs usbfs udf fuse.glusterfs fuse.sshfs ecryptfs fusesmb devtmpfs"
]],{
  PRUNEPATHS = "/tmp /var/spool /media",
  PRUNE_BIND_MOUNTS = "yes",
  PRUNEFS = "NFS nfs nfs4 rpc_pipefs afs binfmt_misc proc smbfs autofs
iso9660 ncpfs coda devpts ftpfs devfs mfs shfs sysfs cifs lustre_lite
tmpfs usbfs udf fuse.glusterfs fuse.sshfs ecryptfs fusesmb devtmpfs"
})

- data.read now has a csv option, which allows fieldnames to be
double-quoted and contain commas (in addition trailing quotes are
considered meaningful; empty fields are empty strings). It isn't the
default because the extra checks can be expensive for simple numerical
data.   It also has an explicit convert option which is a table of
columns and custom conversion functions to be used.  Column rows which
aren't strings or numbers will now be written out using their default
tostring behaviour.

An updated rock will be submitted if there are no blinding errors
reported in the next few days.

My apologies for such a verbose announcement, but it's better to err
on that side rather than the classic 'foo 1.2 has been released'
one-liner.

steve d.

[1] On Windows, it will prefer to either use Alien or LuaJIT FFI to
use the system file copy/rename functions rather than shelling out;
another soft dependency is where pl.xml looks for lxp, (but falls back
to Roberto's simple XML parser).  For LuaJIT it would be better to
replace the lfs dependency with a compatible FFI version, which would
be a useful project in its own right.
[2] Unfortunately, 'sequence' now has a well-defined meaning in the
manual, meaning essentially 'array'.  In PL it means the values
generated by an iterator.