mt_repl is a Minetest mod that provides a Lua read–eval–print loop (REPL). You can type Lua statements or expressions and see the results in your favorite terminal emulator while Minetest is running. mt_repl is intended as a tool for debugging other mods.
Automatic
return
(e.g., you can just type2 + 2
instead ofreturn 2 + 2
or=2 + 2
)Pretty-printing:
~~> minetest.get_player_by_name('singleplayer'):getpos() { x = 133.19999694824, y = -2.5, z = -62.799999237061 }
GNU Readline support (including persistent history)
Custom startup files
A MoonScript input mode, with assignment to global variables by default (as in plain Lua)
- I've only tested it on Linux, and it's implemented in a way that it probably won't work on non-Unix-likes (it uses named pipes and luaposix).
- I've only tested it in single-player mode. There is no sandboxing. Don't enable this mod on a multiplayer server if you don't trust the other players not to erase your home directory.
- Multi-line commands aren't allowed.
print
will use the Minetest server's standard output, which isn't the terminal you're looking at while you're using the REPL.- In MoonScript, creating local variables is not possible. Even
local
declarations don't work.
Minetest versions 0.4.7 and later should be supported.
Install the Lua modules luaposix and inspect.lua. (luaposix is also available as the Debian package
lua-posix
.) MoonScript is optional.Install the mod like an ordinary Minetest mod.
Set the environment variables
MT_REPL_FIFO_REPL_TO_MT
andMT_REPL_FIFO_MT_TO_REPL
to the paths of a pair of named pipes. I recommend doing this by puttingexport MT_REPL_FIFO_REPL_TO_MT="$HOME/.minetest/mods/mt_repl/fifo_repl_to_mt" export MT_REPL_FIFO_MT_TO_REPL="$HOME/.minetest/mods/mt_repl/fifo_mt_to_repl"
in your .bashrc or whatever, then saying:
$ mkfifo "$MT_REPL_FIFO_REPL_TO_MT" $ mkfifo "$MT_REPL_FIFO_MT_TO_REPL"
When the mod is enabled, use the chat command /repl
in-game, then run the included Python script repl.py
in another terminal window, which should display a prompt.
To quit from the Python script, hit Control-D to signal EOF or enter the special input quit
. This will also terminate the REPL on the Minetest side, so you'll need to restart it (by saying /repl
) if you want to use it again.
If you put a Lua script named .mt_replrc
in your home directory, it will be run each time the REPL starts up. See rc-example.lua
.
To use MoonScript instead of Lua, set mt_repl_use_moonscript = true
in your .mt_replrc
(.mt_replrc
itself must still be in Lua). Here's a hint for writing MoonScript one-liners: you can squeeze multiple statements into a place where only one is allowed by abusing do
like so:
if 1 + 1 == 2 then do a = 1, do b = 2 else c = 3
This program is copyright 2013 Kodi Arfer.
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.