mirror of
https://github.com/jgm/pandoc.git
synced 2026-09-24 15:44:59 +08:00
[API Change] Lua: export new function T.P.Lua.getEngine
The function returns the Lua scripting engine.
This commit is contained in:
committed by
John MacFarlane
parent
04902d26da
commit
4d365ca3ff
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user