Skip to content

edrx/edrxrepl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Introduction

This is a simple REPL for Lua.

I wrote it because I was tired of not understanding the innards of Rob Hoelz’s lua-repl. As I use eepitch I need very few features from my REPLs – for example, I don’t need history or completion.

The code of this REPL is made of:

  • a few functions copied from my init file,
  • my implementation on OO in 5 lines (a commented version of it is here),
  • the class MyXpcall, that is a hacker-friendly wrapper around Lua’s xpcall; I wrote it because I needed better error handling in Dednat6 – I need several different error handlers, each with its own traceback function.
  • the class Repl, that uses MyXpcall to run the user code. Once MyXpcall was working the class Repl was trivial to write.

The code is full of eev-isms, but they are all in comments and can be ignored. Some of the multi-line comments are test blocks.

Here’s an example of how to use it from Lua. Note that the REPL uses >>> and ... for its prompts.

cd ~/edrxrepl/
/home/edrx/edrxrepl(edrx:sc)# lua5.3
Lua 5.3.3  Copyright (C) 1994-2016 Lua.org, PUC-Rio
> dofile "edrxrepl.lua"
> REPL = EdrxRepl.new(); REPL:repl()
>>> print(
...   1+2
... )
3
>>> = 1+2
3
>>> = 1, 2, 3
1	2	3
>>> = nil, 22
nil	22
>>> REPL.stop = 1
> os.exit()
/home/edrx/edrxrepl(edrx:sc)# 

And here is an example of how to use it from LuaLaTeX (without git!):

rm -Rfv /tmp/edrxrepl
mkdir   /tmp/edrxrepl/
cd      /tmp/edrxrepl/
wget http://angg.twu.net/edrxrepl/edrxrepl.lua
wget http://angg.twu.net/edrxrepl/edrxrepltest.tex
lualatex edrxrepltest.tex

The body of edrxrepltest.tex is just this:

\documentclass{article}
\begin{document}

\directlua{dofile "edrxrepl.lua"}
\directlua{print(); print(); print("Run REPL.stop = 1 to leave the REPL.")}
\directlua{REPL = EdrxRepl.new(); REPL:repl()}

\end{document}

I am also using this in emacs-lua, that at this moment is just a messy prototype.

About

A simple REPL for Lua

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published