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.
This commit is contained in:
Albert Krewinkel
2017-03-24 21:31:35 +01:00
parent 14e7d3dbff
commit 1e13e98ecf
7 changed files with 53 additions and 7 deletions
+2 -1
View File
@@ -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,
+40
View File
@@ -0,0 +1,40 @@
{-
Copyright © 2017 Albert Krewinkel <tarleb+pandoc@moltkeplatz.de>
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 <tarleb+pandoc@moltkeplatz.de>
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
+3 -2
View File
@@ -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
+2 -1
View File
@@ -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) $
+2 -1
View File
@@ -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
+2 -1
View File
@@ -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
+2 -1
View File
@@ -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