public inbox archive for pandoc-discuss@googlegroups.com
 help / color / mirror / Atom feed
* Lua REPL for filters
@ 2022-05-12 15:38 Albert Krewinkel
  0 siblings, 0 replies; only message in thread
From: Albert Krewinkel @ 2022-05-12 15:38 UTC (permalink / raw)
  To: pandoc-discuss

Here's a piece of code that can be used for interactive Lua filter
development. It's crude, but should be usable nonetheless.

https://gist.github.com/tarleb/fc6718bcfc74fd68f324d938cdb6f350

Usage: the prompt can be used to evaluate arbitrary Lua code and can be
quit by typing `exit`, `quit`, `STOP = true`, or pressing `Ctrl-D`. The
argument given to the `interactive` function is available via the
variable `it`. The content of that variable will also be used as the
function's return value once the repl is terminated.

A second table can be passed to the function, the field of which will
then become available as variables in the REPL. This can be useful to
keep some global state.

Example:

    -- Ensure that, if the REPL is quit via `STOP = true`,
    -- processing is skipped for **all remaining** `Str` elements,
    -- but not for the main `Pandoc` element.
    local Str_env = {STOP = false}
    Str = function (str) return interactive(str, Str_env) end
    Pandoc = interactive

The REPL uses *readline* if readline.lua is available.

Something like this had been requested a number of times; I hope the
code will be useful.


-- 
Albert Krewinkel
GPG: 8eed e3e2 e8c5 6f18 81fe  e836 388d c0b2 1f63 1124


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-05-12 15:38 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-12 15:38 Lua REPL for filters Albert Krewinkel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).