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. --- src/Text/Pandoc/Lua/Compat.hs | 40 +++++++++++++++++++++++++++++++++++++ src/Text/Pandoc/Lua/PandocModule.hs | 5 +++-- src/Text/Pandoc/Writers/Custom.hs | 3 ++- 3 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 src/Text/Pandoc/Lua/Compat.hs (limited to 'src/Text') 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) $ -- cgit v1.2.3