XUtils

Penlight

Broad, heavyweight utility library, inspired by Python's standard libs. Provides the batteries that Lua doesn't.


Penlight Lua Libraries

Unix build AppVeyor build status Coveralls code coverage Luacheck SemVer

Why a new set of libraries?

Penlight brings together a set of generally useful pure Lua modules, focusing on input data handling (such as reading configuration files), functional programming (such as map, reduce, placeholder expressions, etc), and OS path management. Much of the functionality is inspired by the Python standard libraries.

Module Overview

Paths, Files and Directories

  • path: queries like isdir,isfile,exists, splitting paths like dirname and basename
  • dir: listing files in directories (getfiles,getallfiles) and creating/removing directory paths
  • file: copy,move; read/write contents with read and write

Extra String Operations

  • utils: can split a string with a delimiter using utils.split
  • stringx: extended string functions covering the Python string type
  • stringio: open strings for reading, and creating strings using standard Lua IO methods
  • lexer: lexical scanner for splitting text into tokens; special cases for Lua and C
  • text: indenting and dedenting text, wrapping paragraphs; optionally make % work as in Python
  • template: small but powerful template expansion engine
  • sip: Simple Input Patterns - higher-level string patterns for parsing text

Extra Table Operations

  • tablex: copying, comparing and mapping over
  • pretty: pretty-printing Lua tables, and various safe ways to load Lua as data
  • List: implementation of Python ‘list’ type - slices, concatenation and partitioning
  • Map, Set, OrderedMap: classes for specialized kinds of tables
  • data: reading tabular data into 2D arrays and efficient queries
  • array2d: operations on 2D arrays
  • permute: generate permutations

Iterators, OOP and Functional

  • seq: working with iterator pipelines; collecting iterators as tables
  • class: a simple reusable class framework
  • func: symbolic manipulation of expressions and lambda expressions
  • utils: utils.string_lambda converts short strings like ‘|x| x^2’ into functions
  • comprehension: list comprehensions: C'x for x=1,4'()=={1,2,3,4}

Versioning

Penlight is strictly versioned according to Semantic Versioning.

In scope of the version:

  • functionality provided by Penlight modules/classes
  • based on stock Lua PuC-Rio or LuaJIT

Not in scope of the version:

  • Documentation
  • Error messages (textual changes)
  • Deprecation warnings (by default to stderr)

Dependencies

The file and directory functions depend on LuaFileSystem, which is installed automatically if you are using LuaRocks. Additionally, if you want dir.copyfile to work elegantly on Windows, then you need Alien. Both libraries are present in Lua for Windows.

Building the Documentation

Requires ldoc, which is available through LuaRocks. Then it’s a simple matter of running ldoc . from the repo.

Running tests

Execute lua run.lua tests to run the tests. Execute lua run.lua examples to run examples.

History

For a complete history of the development of Penlight, please check the changelog.


Articles

  • coming soon...