From 1e13e98ecfba2d78a88ba42bb54c8cdc15929e2d Mon Sep 17 00:00:00 2001 From: Albert Krewinkel Date: Fri, 24 Mar 2017 21:19:55 +0100 Subject: Ensure compatibility with hslua 0.5.* The 0.5.0 release of hslua fixes problems with lua C modules on linux. The signature of the `loadstring` function changed, so a compatibility wrapper is introduced to allow both 0.4.* and 0.5.* versions to be used. --- pandoc.cabal | 3 ++- src/Text/Pandoc/Lua/Compat.hs | 40 +++++++++++++++++++++++++++++++++++++ src/Text/Pandoc/Lua/PandocModule.hs | 5 +++-- src/Text/Pandoc/Writers/Custom.hs | 3 ++- stack.full.yaml | 3 ++- stack.pkg.yaml | 3 ++- stack.yaml | 3 ++- 7 files changed, 53 insertions(+), 7 deletions(-) create mode 100644 src/Text/Pandoc/Lua/Compat.hs diff --git a/pandoc.cabal b/pandoc.cabal index b56f29b48..4e3edf008 100644 --- a/pandoc.cabal +++ b/pandoc.cabal @@ -303,7 +303,7 @@ Library yaml >= 0.8.8.2 && < 0.9, scientific >= 0.2 && < 0.4, vector >= 0.10 && < 0.13, - hslua >= 0.3 && < 0.5, + hslua >= 0.4 && < 0.6, binary >= 0.5 && < 0.9, SHA >= 1.6 && < 1.7, haddock-library >= 1.1 && < 1.5, @@ -446,6 +446,7 @@ Library Text.Pandoc.Readers.Org.ParserState, Text.Pandoc.Readers.Org.Parsing, Text.Pandoc.Readers.Org.Shared, + Text.Pandoc.Lua.Compat, Text.Pandoc.Lua.PandocModule, Text.Pandoc.CSS, Text.Pandoc.UUID, diff --git a/src/Text/Pandoc/Lua/Compat.hs b/src/Text/Pandoc/Lua/Compat.hs new file mode 100644 index 000000000..998d8d032 --- /dev/null +++ b/src/Text/Pandoc/Lua/Compat.hs @@ -0,0 +1,40 @@ +{- +Copyright © 2017 Albert Krewinkel + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +-} +{-# LANGUAGE CPP #-} +{- | + Module : Text.Pandoc.Lua.Compat + Copyright : Copyright © 2017 Albert Krewinkel + License : GNU GPL, version 2 or above + + Maintainer : Albert Krewinkel + Stability : alpha + +Compatibility helpers for hslua +-} +module Text.Pandoc.Lua.Compat ( loadstring ) where + +import Scripting.Lua ( LuaState ) +import qualified Scripting.Lua as Lua + +-- | Interpret string as lua code and load into the lua environment. +loadstring :: LuaState -> String -> String -> IO Int +#if MIN_VERSION_hslua(0,5,0) +loadstring lua script _ = Lua.loadstring lua script +#else +loadstring lua script cn = Lua.loadstring lua script cn +#endif diff --git a/src/Text/Pandoc/Lua/PandocModule.hs b/src/Text/Pandoc/Lua/PandocModule.hs index 5b2e82103..87d1fa6b9 100644 --- a/src/Text/Pandoc/Lua/PandocModule.hs +++ b/src/Text/Pandoc/Lua/PandocModule.hs @@ -28,7 +28,8 @@ Pandoc module for lua. module Text.Pandoc.Lua.PandocModule ( pushPandocModule ) where import Data.ByteString.Char8 ( unpack ) -import Scripting.Lua ( LuaState, loadstring, call) +import Scripting.Lua ( LuaState, call) +import Text.Pandoc.Lua.Compat ( loadstring ) import Text.Pandoc.Shared ( readDataFile ) @@ -36,7 +37,7 @@ import Text.Pandoc.Shared ( readDataFile ) pushPandocModule :: LuaState -> IO () pushPandocModule lua = do script <- pandocModuleScript - status <- loadstring lua script "cn" + status <- loadstring lua script "pandoc.lua" if (status /= 0) then return () else do diff --git a/src/Text/Pandoc/Writers/Custom.hs b/src/Text/Pandoc/Writers/Custom.hs index d7374b68b..9bed1dcd3 100644 --- a/src/Text/Pandoc/Writers/Custom.hs +++ b/src/Text/Pandoc/Writers/Custom.hs @@ -47,6 +47,7 @@ import Data.Typeable import GHC.IO.Encoding (getForeignEncoding, setForeignEncoding, utf8) import Scripting.Lua (LuaState, StackValue, callfunc) import qualified Scripting.Lua as Lua +import Text.Pandoc.Lua.Compat ( loadstring ) import Text.Pandoc.Definition import Text.Pandoc.Options import Text.Pandoc.Templates @@ -186,7 +187,7 @@ writeCustom luaFile opts doc@(Pandoc meta _) = do setForeignEncoding utf8 lua <- Lua.newstate Lua.openlibs lua - status <- Lua.loadstring lua luaScript luaFile + status <- loadstring lua luaScript luaFile -- check for error in lua script (later we'll change the return type -- to handle this more gracefully): when (status /= 0) $ diff --git a/stack.full.yaml b/stack.full.yaml index 44d5afe5a..bf1d1581d 100644 --- a/stack.full.yaml +++ b/stack.full.yaml @@ -23,5 +23,6 @@ packages: extra-deps: - doctemplates-0.1.0.2 - skylighting-0.3.1 -- hslua-aeson-0.1.0.2 +- hslua-0.5.0 +- hslua-aeson-0.1.0.3 resolver: lts-8.4 diff --git a/stack.pkg.yaml b/stack.pkg.yaml index a0ca9f52c..88170abc2 100644 --- a/stack.pkg.yaml +++ b/stack.pkg.yaml @@ -18,7 +18,8 @@ packages: commit: a824c8f3187302cad0fb815471499a18857ecc38 extra-dep: false extra-deps: -- hslua-aeson-0.1.0.2 +- hslua-0.5.0 +- hslua-aeson-0.1.0.3 - skylighting-0.3.1 - texmath-0.9.4 resolver: lts-8.4 diff --git a/stack.yaml b/stack.yaml index d32fdf30d..be3b5e99d 100644 --- a/stack.yaml +++ b/stack.yaml @@ -8,7 +8,8 @@ flags: packages: - '.' extra-deps: -- hslua-aeson-0.1.0.2 +- hslua-0.5.0 +- hslua-aeson-0.1.0.3 - skylighting-0.3.1 - texmath-0.9.4 resolver: lts-8.4 -- cgit v1.2.3