lua-users home
lua-l archive

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


Hi all,

This is an experiment to see if a Lua REPL and a shell can co-exist.
It is like the old Saturday Night joke, about a new product that is 'a
dessert topping and a floor polish'.

David Manura's lua.lua [0] provided a good solid base for this project.

It needs Rob Hoelz' lua-linenoise and Reuben Thomas' luaposix, and has
an optional dependency on Microlight (just for pretty table printing)

> = {1,2,3}, 'boo'
{1,2,3}   "boo"

Otherwise, things work pretty much as expected; the main feature being
global Lua tab completion. If I type 'st' <tab> I get 'string', and
<tab> after 'string.' will cycle through the contents of that table.
This also works for objects.  It makes no attempt to evaluate
expressions to find completions, just chains of identifiers separated
by '.' and ':' (without purity guarantees arbitrary evaluation is
_not_ what you want here).  It will save the history as
~./luai-history, and will load anything it finds in ~/luairc.lua, if
this exists.

Anything that starts with a '.' (period) is evaluated as a shell
command; global Lua variables are expanded. When you switch to shell
mode, completion then works on pathnames. (a good reason to keep the
modes separate)

> .tail -n 1 luaish.lua
return lsh
> P = 'hello'
> .echo $P $(pwd)
 hello /mnt/extra/luaish

'.cd' and '.export' work as expected, but they're pseudo-commands,
setting the process working directory and process environment
respectively.

There is a special form for passing the output of a command through a
Lua filter; '>' is one of the predefined ones.

> .ls -1 | -> ls
> = ls
{"luaish.lua","lua.lua","readme.md"}

Apart from being good for dessert and cleaning, it can also be useful
glue for scripting.  For the seriously impatient there's a 32-bit Lua
5.2 prebuilt version at [1], which seems to be surprisingly portable
(i.e. an old SUSE amd64 server was fine with it)   This can be useful
as a luaposix-powered self-contained scripting tool that fits into 222
Kb, thanks to soar and srlua.

Otherwise, it's just lua/lua52 lua.lua  (works with both versions)

It's important not to lose sight of a 'better Lua REPL' as well!  I
think Dirk is right, documentation and help is a big thing.  ilua's
trick of making '=' redundant by trying the compile both ways is also
a possibility.  Thanks to Jay for prodding my brain in interesting
directions on this one.

steve d.

[0] http://lua-users.org/wiki/LuaInterpreterInLua
[1] https://github.com/stevedonovan/luaish
[2] http://stevedonovan.github.com/files/luaish