pandoc / lua-filters

A collection of lua filters for pandoc
MIT License
611 stars 166 forks source link

add a lua debug example filter #116

Closed iandol closed 4 years ago

iandol commented 4 years ago

Hi, this adds an example of how to use Zerobrane Studio / mobdebug to step-debug through a Lua filter run within Pandoc.

iandol commented 4 years ago

So, here is the error:

Error running filter lua-debug-example.lua:
lua-debug-example.lua:8: module 'mobdebug' not found:
    no file 'mobdebug.lua' in pandoc's datadir
    no field package.preload['mobdebug']
    no file '/usr/local/share/lua/5.3/mobdebug.lua'
    no file '/usr/local/share/lua/5.3/mobdebug/init.lua'
    no file '/usr/local/lib/lua/5.3/mobdebug.lua'
    no file '/usr/local/lib/lua/5.3/mobdebug/init.lua'
    no file './mobdebug.lua'
    no file './mobdebug/init.lua'
    no file '/usr/local/lib/lua/5.3/mobdebug.so'
    no file '/usr/local/lib/lua/5.3/loadall.so'
    no file './mobdebug.so'
stack traceback:
    [C]: in function 'require'
    lua-debug-example.lua:8: in main chunk

I can add mobdebug.lua to the folder and it should be used (the default search path includes ./ which I assume is the folder the filter and tests run in?), but the problem will be the dependency, luasocket. The search path should also work but this is a binary library so will have to be compiled on the system the tests run in I assume? Is that Ubuntu 18.04?

iandol commented 4 years ago

New error, as expected, missing socket.so:

Error running filter lua-debug-example.lua:
./mobdebug.lua:102: module 'socket' not found:
    no file 'socket.lua' in pandoc's datadir
    no field package.preload['socket']
    no file '/usr/local/share/lua/5.3/socket.lua'
    no file '/usr/local/share/lua/5.3/socket/init.lua'
    no file '/usr/local/lib/lua/5.3/socket.lua'
    no file '/usr/local/lib/lua/5.3/socket/init.lua'
    no file './socket.lua'
    no file './socket/init.lua'
    no file '/usr/local/lib/lua/5.3/socket.so'
    no file '/usr/local/lib/lua/5.3/loadall.so'
    no file './socket.so'
stack traceback:
    [C]: in function 'require'
    ./mobdebug.lua:102: in main chunk
    [C]: in function 'require'
    lua-debug-example.lua:8: in main chunk
iandol commented 4 years ago

Do we have to run the filter through a test, in this case the point for this filter is to stop the filter interactively which is not really compatible with automated tests...

alerque commented 4 years ago

I don't think I'd add the mobdebug dependency to this repository. It's a rabbit hole anyway. I would find some other way to test (or skip testing) this that makes sense, perhaps a dummy mode flag that skips the key parts for the sake of testing at least the overall syntax if not the actual function.

tarleb commented 4 years ago

I'm adjusting the CI pipelines so we can use luarocks to install dependencies.

tarleb commented 4 years ago

Ah, this doesn't work because we are using the statically compile pandoc binary on Travis. We cannot load C-based libraries installed with luarocks with that binary. Not sure about the best way forward here.

iandol commented 4 years ago

OK, I've removed mobdebug.lua

jgm commented 4 years ago

We can just disable testing for this filter. There's no way to do that currently, but it can be added.

jgm commented 4 years ago

Oh, I guess there is an easy way: just make the test target return success without doing anything.

iandol commented 4 years ago

OK, I've forced the testcase to pass just by comparing the expected output with itself:

test:
    @cat expected.html | diff --strip-trailing-cr -u expected.html -

Is that OK?

jgm commented 4 years ago

Fine with me!

tarleb commented 4 years ago

Same. The only remaining thing is the long lines in README. If you are using an editor which supports it, then I can wholeheartedly recommend editorconfig. It can be a convenient method to follow a general style automatically.

iandol commented 4 years ago

OK, thanks for the tip (I needed to install an extension for VSCode). Wrapped at 66 chars.

tarleb commented 4 years ago

Great, thanks!