git.iko.soy/typeable/pandoc
on master help sign in
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.

commit1e13e98ecfba2d78a88ba42bb54c8cdc15929e2d authorAlbert Krewinkel <albert@zeitkraut.de> dateFri 24 Mar 2017, 21:19 (10 years ago) parent14e7d3d
7 files changed+53−7
pandoc.cabal+2−1 src/Text/Pandoc/Lua/Compat.hs+40 src/Text/Pandoc/Lua/PandocModule.hs+3−2 src/Text/Pandoc/Writers/Custom.hs+2−1 stack.full.yaml+2−1 stack.pkg.yaml+2−1 stack.yaml+2−1
pandoc.cabal+2−1
@@ -303,7 +303,7 @@ Library
303303 yaml >= 0.8.8.2 && < 0.9,
304304 scientific >= 0.2 && < 0.4,
305305 vector >= 0.10 && < 0.13,
306− hslua >= 0.3 && < 0.5,
306+ hslua >= 0.4 && < 0.6,
307307 binary >= 0.5 && < 0.9,
308308 SHA >= 1.6 && < 1.7,
309309 haddock-library >= 1.1 && < 1.5,
@@ -446,6 +446,7 @@ Library
446446 Text.Pandoc.Readers.Org.ParserState,
447447 Text.Pandoc.Readers.Org.Parsing,
448448 Text.Pandoc.Readers.Org.Shared,
449+ Text.Pandoc.Lua.Compat,
449450 Text.Pandoc.Lua.PandocModule,
450451 Text.Pandoc.CSS,
451452 Text.Pandoc.UUID,
src/Text/Pandoc/Lua/Compat.hsnew file+40
@@ -0,0 +1,40 @@
1+{-
2+Copyright © 2017 Albert Krewinkel <tarleb+pandoc@moltkeplatz.de>
3+
4+This program is free software; you can redistribute it and/or modify
5+it under the terms of the GNU General Public License as published by
6+the Free Software Foundation; either version 2 of the License, or
7+(at your option) any later version.
8+
9+This program is distributed in the hope that it will be useful,
10+but WITHOUT ANY WARRANTY; without even the implied warranty of
11+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+GNU General Public License for more details.
13+
14+You should have received a copy of the GNU General Public License
15+along with this program; if not, write to the Free Software
16+Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17+-}
18+{-# LANGUAGE CPP #-}
19+{- |
20+ Module : Text.Pandoc.Lua.Compat
21+ Copyright : Copyright © 2017 Albert Krewinkel
22+ License : GNU GPL, version 2 or above
23+
24+ Maintainer : Albert Krewinkel <tarleb+pandoc@moltkeplatz.de>
25+ Stability : alpha
26+
27+Compatibility helpers for hslua
28+-}
29+module Text.Pandoc.Lua.Compat ( loadstring ) where
30+
31+import Scripting.Lua ( LuaState )
32+import qualified Scripting.Lua as Lua
33+
34+-- | Interpret string as lua code and load into the lua environment.
35+loadstring :: LuaState -> String -> String -> IO Int
36+#if MIN_VERSION_hslua(0,5,0)
37+loadstring lua script _ = Lua.loadstring lua script
38+#else
39+loadstring lua script cn = Lua.loadstring lua script cn
40+#endif
src/Text/Pandoc/Lua/PandocModule.hs+3−2
@@ -28,7 +28,8 @@ Pandoc module for lua.
2828module Text.Pandoc.Lua.PandocModule ( pushPandocModule ) where
2929
3030import Data.ByteString.Char8 ( unpack )
31−import Scripting.Lua ( LuaState, loadstring, call)
31+import Scripting.Lua ( LuaState, call)
32+import Text.Pandoc.Lua.Compat ( loadstring )
3233import Text.Pandoc.Shared ( readDataFile )
3334
3435
@@ -36,7 +37,7 @@ import Text.Pandoc.Shared ( readDataFile )
3637pushPandocModule :: LuaState -> IO ()
3738pushPandocModule lua = do
3839 script <- pandocModuleScript
39− status <- loadstring lua script "cn"
40+ status <- loadstring lua script "pandoc.lua"
4041 if (status /= 0)
4142 then return ()
4243 else do
src/Text/Pandoc/Writers/Custom.hs+2−1
@@ -47,6 +47,7 @@ import Data.Typeable
4747import GHC.IO.Encoding (getForeignEncoding, setForeignEncoding, utf8)
4848import Scripting.Lua (LuaState, StackValue, callfunc)
4949import qualified Scripting.Lua as Lua
50+import Text.Pandoc.Lua.Compat ( loadstring )
5051import Text.Pandoc.Definition
5152import Text.Pandoc.Options
5253import Text.Pandoc.Templates
@@ -186,7 +187,7 @@ writeCustom luaFile opts doc@(Pandoc meta _) = do
186187 setForeignEncoding utf8
187188 lua <- Lua.newstate
188189 Lua.openlibs lua
189− status <- Lua.loadstring lua luaScript luaFile
190+ status <- loadstring lua luaScript luaFile
190191 -- check for error in lua script (later we'll change the return type
191192 -- to handle this more gracefully):
192193 when (status /= 0) $
stack.full.yaml+2−1
@@ -23,5 +23,6 @@ packages:
2323extra-deps:
2424- doctemplates-0.1.0.2
2525- skylighting-0.3.1
26−- hslua-aeson-0.1.0.2
26+- hslua-0.5.0
27+- hslua-aeson-0.1.0.3
2728resolver: lts-8.4
stack.pkg.yaml+2−1
@@ -18,7 +18,8 @@ packages:
1818 commit: a824c8f3187302cad0fb815471499a18857ecc38
1919 extra-dep: false
2020extra-deps:
21−- hslua-aeson-0.1.0.2
21+- hslua-0.5.0
22+- hslua-aeson-0.1.0.3
2223- skylighting-0.3.1
2324- texmath-0.9.4
2425resolver: lts-8.4
stack.yaml+2−1
@@ -8,7 +8,8 @@ flags:
88packages:
99- '.'
1010extra-deps:
11−- hslua-aeson-0.1.0.2
11+- hslua-0.5.0
12+- hslua-aeson-0.1.0.3
1213- skylighting-0.3.1
1314- texmath-0.9.4
1415resolver: lts-8.4