A Lua REPL implemented in Lua for embedding in other programs
Clone or download
Latest commit a9600fc Oct 24, 2016
Permalink
Failed to load latest commit information.
dev
repl
t
.editorconfig Added support for EditorConfig enabled editors. Mar 4, 2015
.gitignore Add build outputs to gitignore Sep 28, 2012
.proverc Add proverc Sep 27, 2012
.travis.yml
COPYING
Changes Update Changelog Aug 23, 2015
IDEAS.md
Makefile Inherit the LUA_PATH from the parent shell while running tests Aug 11, 2016
README.md
RELEASE-GUIDE.md
Roadmap.md
luarepl-0.8-1.rockspec
plugins.md
rep.lua

README.md

REPL.lua - a reusable Lua REPL written in Lua, and an alternative to /usr/bin/lua

This project has two uses:

  • An alternative to the standalone interpreter included with Lua, one that supports things like plugins, tab completion, and automatic insertion of return in front of expressions.

  • A REPL library you may embed in your application, to provide all of the niceties of the standalone interpreter included with Lua and then some.

Many software projects have made the choice to embed Lua in their projects to allow their users some extra flexibility. Some of these projects would also like to provide a Lua REPL in their programs for debugging or rapid development. Most Lua programmers are familiar with the standalone Lua interpreter as a Lua REPL; however, it is bound to the command line. Until now, Lua programmers would have to implement their own REPL from scratch if they wanted to include one in their programs. This project aims to provide a REPL implemented in pure Lua that almost any project can make use of.

This library also includes an example application (rep.lua), which serves as an alternative to the standalone interpreter included with Lua. If the lua-linenoise library is installed, it uses linenoise for history and tab completion; otherwise, it tries to use rlwrap for basic line editing.

Project Goals

  • Provide REPL logic to Lua programs that include this module.

  • Be extensible through polymorphism and plugins.

  • Abstract away I/O, so you can run this REPL on the command line or in your own event loop and expect the same behavior.

Building

Compatibility

The current version of the software runs on Lua 5.1, LuaJIT ?.? etc. A port to Lua 5.2 is envisaged, but is not at this stage a priority. Since it is written purely in Lua, it should work on any platform that has one of those versions of Lua installed.

XXX Check which version of LuaJIT this works with XXX Check that it works with other Lua interpreters

Installation

You can install lua-repl via LuaRocks:

luarocks install luarepl

You can also install it by hand by copying the repl directory to a location in your package.path, and copying rep.lua to somewhere in your PATH.

Recommended packages

rep.lua works best if you also have linenoise installed, available from https://github.com/hoelzro/lua-linenoise. rep.lua will fallback to using rlwrap if you have that as well; without either of these, you will have command editing, history, or other features generally provided by readline.

Features

rep.lua prints the results of simple expressions without requiring a return or a = in front of it. If linenoise is installed, it also offers persistent history and tab completion. It also offers a number of plugins; see plugins.md for a list of plugins that come with lua-repl.

Backwards Compatibility Changes

Removal of default plugins in 0.8

Lua REPL 0.8 breaks backwards compatability by disabling the loading of the default plugins (currently linenoise, rlwrap, history, completion, and autoreturn) if an rcfile is found for a user. This is so that plugins may not be forced onto a user if they don't want them, or play tricks with their setup (see issue #47). If you would like to continue using these plugins, please put the following code into your ~/.rep.lua:

if repl.VERSION >= 0.8 then
  -- default plugins
  repl:loadplugin 'linenoise'
  repl:loadplugin 'history'
  repl:loadplugin 'completion'
  repl:loadplugin 'autoreturn'
end

-- suppress warning message
repl.quiet_default_plugins = true

As mentioned in the code snippet, repl.quiet_default_plugins suppresses the warning. You can remove this after upgrading to Lua REPL 0.8.