Skip to content

Commit 3ff4a52

Browse files
iandolIandoliandol
authored
Add a Lua debug example filter (#116)
* add a lua debug example filter * add mobdebug.lua dependency * removing mobdebug.lua * make test always pass * hard-wrap README.md at 66 chars Co-authored-by: Iandol <ian@diogenes> Co-authored-by: iandol <iandol@aristotle>
1 parent 2d8bbdc commit 3ff4a52

File tree

5 files changed

+89
-0
lines changed

5 files changed

+89
-0
lines changed

lua-debug-example/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
test:
2+
@cat expected.html | diff --strip-trailing-cr -u expected.html -
3+
4+
.PHONY: test

lua-debug-example/README.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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…

lua-debug-example/expected.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<h1 id="lua-debug-example">Lua Debug Example</h1>
2+
<p>Lorem ipsum dolor sit amet, <span class="smallcaps">consectetuer</span> adipiscing elit. Donec hendrerit tempor tellus. Donec pretium posuere tellus.</p>
3+
<p>Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. <span class="smallcaps">Nulla posuere</span>. Donec vitae dolor.</p>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
--[[
2+
# Lua Debug Example
3+
This filter demonstrates how to add mobdebug commands to stop execution within
4+
the filter functions, see README.md for details how to install and set up
5+
Zerobrane Studio.
6+
]]
7+
8+
md = require("mobdebug")
9+
md.start()
10+
11+
function Emph(elem)
12+
md.pause() --breakpoint
13+
return elem.content
14+
end
15+
16+
function Strong(elem)
17+
md.pause() --breakpoint
18+
return pandoc.SmallCaps(elem.content)
19+
end

lua-debug-example/sample.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Lua Debug Example
2+
3+
Lorem *ipsum* dolor sit amet, **consectetuer** adipiscing elit. Donec
4+
hendrerit tempor tellus. Donec pretium posuere tellus.
5+
6+
Cum sociis natoque *penatibus* et magnis dis parturient montes,
7+
nascetur ridiculus mus. **Nulla posuere**. Donec vitae dolor.
8+

0 commit comments

Comments
 (0)