|
| 1 | +# Debugging Lua filters |
| 2 | + |
| 3 | +You can debug Pandoc Lua filters using [Zerobrane |
| 4 | +Studio](https://studio.zerobrane.com). This GUI debugger requires |
| 5 | +`luasocket` and `mobdebug`, both are bundled in Zerobrane, or you |
| 6 | +can use your Lua installed versions. |
| 7 | + |
| 8 | +## Without Lua Installed: |
| 9 | +If you don't have Lua installed on your system, you must update |
| 10 | +the environment search path to use `mobdebug.lua` and `luasocket` |
| 11 | +from Zerobrane's install location. See |
| 12 | +[documentation](https://studio.zerobrane.com/doc-remote-debugging) |
| 13 | +for details. For example, on macOS this would be: |
| 14 | + |
| 15 | +```bash |
| 16 | +export ZBS=/Applications/ZeroBraneStudio.app/Contents/ZeroBraneStudio |
| 17 | +export LUA_PATH="./?.lua;$ZBS/lualibs/?/?.lua;$ZBS/lualibs/?.lua" |
| 18 | +export LUA_CPATH="$ZBS/bin/?.dylib;$ZBS/bin/clibs53/?.dylib;$ZBS/bin/clibs53/?/?.dylib" |
| 19 | +``` |
| 20 | + |
| 21 | +## With Lua Installed: |
| 22 | +If you have installed Lua v5.3 and added `mobdebug` + `luasocket` |
| 23 | +using `luarocks` then they should be available in the default path |
| 24 | +locations (at least for POSIX systems), and you shouldn't need to |
| 25 | +set any path variables. |
| 26 | + |
| 27 | +## How to Trigger the Debugger: |
| 28 | +Ensure the `lua-debug-example.lua` file is opened in the Zerobrane |
| 29 | +editor; Project > Start Debugger Server is turned ON; and |
| 30 | +editor.autoactivate = true is enabled in your `user.lua` settings |
| 31 | +file. |
| 32 | + |
| 33 | +Then run `pandoc` from a terminal with the filter that is open in |
| 34 | +the editor (here we use STDIN to give `pandoc` some input, press |
| 35 | +<kbd>ctrl</kbd>+<kbd>d</kbd> to finish entering text): |
| 36 | + |
| 37 | +``` |
| 38 | +> pandoc --lua-filter lua-debug-example.lua |
| 39 | +Here is a *test* for **REPL** debugging. |
| 40 | +
|
| 41 | +``` |
| 42 | + |
| 43 | +Zerobrane's debugging interface will activate. Use the stack |
| 44 | +window and remote console to examine the environment and execute |
| 45 | +Lua commands while stepping through the code. |
| 46 | + |
| 47 | +## Command-line Use: |
| 48 | +With mobdebug and luasocket installed alongside Lua, you can also |
| 49 | +debug directly from your terminal without running the IDE: |
| 50 | + |
| 51 | +```bash |
| 52 | +> lua -e "require('mobdebug').listen()" |
| 53 | +``` |
| 54 | + |
| 55 | +But Zerobrane Studio offers much richer functionality… |
0 commit comments