diff options
| author | Albert Krewinkel <[email protected]> | 2022-09-29 13:19:20 +0200 |
|---|---|---|
| committer | John MacFarlane <[email protected]> | 2022-09-30 08:33:40 -0700 |
| commit | 4d365ca3ff740c5f574271a86c164d8c04daa83d (patch) | |
| tree | d9662a575e6c490560b81f3b2b90cf662e852d41 /src | |
| parent | 04902d26dade413c91dd098b1659f3f817d0adcb (diff) | |
[API Change] Lua: export new function T.P.Lua.getEngine
The function returns the Lua scripting engine.
Diffstat (limited to 'src')
| -rw-r--r-- | src/Text/Pandoc/Lua.hs | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/Text/Pandoc/Lua.hs b/src/Text/Pandoc/Lua.hs index 085526cb7..d6134fc01 100644 --- a/src/Text/Pandoc/Lua.hs +++ b/src/Text/Pandoc/Lua.hs @@ -21,11 +21,32 @@ module Text.Pandoc.Lua , setGlobals , runLua , runLuaNoEnv + -- * Engine + , getEngine ) where +import Control.Monad.IO.Class (MonadIO (liftIO)) +import HsLua.Core (getglobal, openlibs, run, top, tostring) +import Text.Pandoc.Error (PandocError) import Text.Pandoc.Lua.Filter (applyFilter) import Text.Pandoc.Lua.Global (Global (..), setGlobals) import Text.Pandoc.Lua.Init (runLua, runLuaNoEnv) import Text.Pandoc.Lua.Reader (readCustom) import Text.Pandoc.Lua.Writer (writeCustom) import Text.Pandoc.Lua.Orphans () +import Text.Pandoc.Scripting (ScriptingEngine (..)) +import qualified Text.Pandoc.UTF8 as UTF8 + +-- | Constructs the Lua scripting engine. +getEngine :: MonadIO m => m ScriptingEngine +getEngine = do + versionName <- liftIO . run @PandocError $ do + openlibs + getglobal "_VERSION" + tostring top + pure $ ScriptingEngine + { engineName = maybe "Lua (unknown version)" UTF8.toText versionName + , engineApplyFilter = applyFilter + , engineReadCustom = readCustom + , engineWriteCustom = writeCustom + } |
