-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lua filters #3514
Lua filters #3514
Conversation
Allows to run a very basic lua script.
I'm excited about this!
Also, it would be good to add the |
Have you done any benchmarks with a realistic filter on a realistic document, comparing python and lua, say? |
I forgot about documentation; I'll amend the PR tomorrow. The performance tests that I did are very rough. I didn't get around yet to implement lazy-loading of element content, so filtering blocks with a lot of content is rather slow. Here are my comparisons with panflute, using a real-world Markdown manuscript as input:
For comparison: filtering this document with Performance suffers for elements containing a lot of content (lazy serialization should fix this) and if elements are serialized repeatedly. Converting to and from lua through the lua stack is rather slow. The performance advantage of lua filters stems from the fact that elements can be serialized selectively. |
I should also mention the things that would be nice-to-have but haven't been implemented yet:
I don't think any of these are blockers, but all of them impact usability. |
The new version fixes compatibility problems with older GHC versions.
e1bf5f3
to
0f771ed
Compare
Started playing with this a bit. First thing I tried to do was create a return {
{ Str = function (inline)
return pandoc.Str(string.upper(inline.c))
end,
}
} This failed when I ran it on a Markdown file with non-ascii characters.
First reaction: too bad hslua packages lua 5.1, not 5.2 which has a built-in utf8 library. (Is there a reason for that?) Second reaction: no problem, I'll just install luautf8 with luarocks and use this: local utf8 = require("lua-utf8")
return {
{ Str = function (inline)
return pandoc.Str(utf8.upper(inline.c))
end,
}
} But this didn't work.
If I open a lua repl, I can |
I'll need to look deeper into this. Regarding the lua version: the reason hslua ships with 5.1 is that this is the last version compatible with LuaJIT. I'd like to see a new hslua release that's using 5.3, but this would make hslua unusable for people who rely on LuaJIT. On the other hand, pandoc seems to be the only active project on hackage that is using hslua. Citing osa1:
See also the previously mentioned road map proposal hslua/hslua#46. I did a quick test requiring penlight (as I had that installed), and it worked after running |
* Add `--lua-filter` option. This works like `--filter` but takes pathnames of special lua filters and uses the lua interpreter baked into pandoc, so that no external interpreter is needed. Note that lua filters are all applied after regular filters, regardless of their position on the command line. * Add Text.Pandoc.Lua, exporting `runLuaFilter`. Add `pandoc.lua` to data files. * Add private module Text.Pandoc.Lua.PandocModule to supply the default lua module. * Add Tests.Lua to tests. * Add data/pandoc.lua, the lua module pandoc imports when processing its lua filters. * Document in MANUAL.txt.
Pure lua modules seem to work find, but C modules cause problems. I was able to load slnunicode and identified some potential problems along the way:
I'll have to figure out a way of compiling hslua such that no symbols get lost in the process. |
The alternative might be to replicate the |
It would be great to make it possible to use C modules.
utf8 support is crucial, but it would also be fantastic
to be able to use lpeg in filters!
|
Ok, found the compiler flags to get it working on linux. Not sure if the same approach also works for windows and OSX, I need to do more testing. I hope for the fix to become available later this week. Do you plan on distributing slnunicode as part of pandoc, compile it into the binary, or should users get it separately? |
Provide basic support for lua filters.
This needs more work, but is already usable in its current state.
Closes: #3395