packages feed

hslua-module-text 0.1.2.1 → 0.2.0

raw patch · 4 files changed

+36/−32 lines, 4 filesdep +bytestringdep ~hsluaPVP ok

version bump matches the API change (PVP)

Dependencies added: bytestring

Dependency ranges changed: hslua

API changes (from Hackage documentation)

- Foreign.Lua.Module.Text: instance Foreign.Lua.Types.FromLuaStack.FromLuaStack a => Foreign.Lua.Types.FromLuaStack.FromLuaStack (Foreign.Lua.Module.Text.OrNil a)

Files

ChangeLog.md view
@@ -1,5 +1,15 @@ # Revision history for hslua-module-text +## 0.2.0 -- 2018-09-24++- Use hslua 1.0.+++## 0.1.2.2  -- 2018-03-09++- Relax upper bound for base.++ ## 0.1.2.1  -- 2017-11-24  - Add missing test file in the sources archive. This oversight had
hslua-module-text.cabal view
@@ -1,13 +1,13 @@ name:                hslua-module-text-version:             0.1.2.1+version:             0.2.0 synopsis:            Lua module for text description:         UTF-8 aware subset of Lua's `string` module.-homepage:            https://github.com/hslua/hslua-module-test+homepage:            https://github.com/hslua/hslua-module-text license:             MIT license-file:        LICENSE author:              Albert Krewinkel maintainer:          albert+hslua@zeitkraut.de-copyright:           © 2017 Albert Krewinkel+copyright:           © 2017–2018 Albert Krewinkel category:            Foreign build-type:          Simple extra-source-files:  ChangeLog.md@@ -20,11 +20,13 @@  library   exposed-modules:     Foreign.Lua.Module.Text-  build-depends:       base  >= 4.7 && < 4.11-                     , hslua >= 0.9 && < 0.10-                     , text  >= 1   && < 1.3+  build-depends:       base       >= 4.7    && < 5+                     , bytestring >= 0.10.2 && < 0.11+                     , hslua      >= 1.0    && < 1.1+                     , text       >= 1      && < 1.3   hs-source-dirs:      src   default-language:    Haskell2010+  other-extensions:    OverloadedStrings  test-suite test-hslua   default-language:    Haskell2010
src/Foreign/Lua/Module/Text.hs view
@@ -1,5 +1,5 @@ {--Copyright © 2017 Albert Krewinkel+Copyright © 2017–2018 Albert Krewinkel  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal@@ -19,10 +19,10 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -}-+{-# LANGUAGE OverloadedStrings #-} {-| Module      : Foreign.Lua.Module.Text-Copyright   : © 2017 Albert Krewinkel+Copyright   : © 2017–2018 Albert Krewinkel License     : MIT Maintainer  : Albert Krewinkel <tarleb+hslua@zeitkraut.de> Stability   : alpha@@ -36,10 +36,10 @@   )where  import Control.Applicative ((<$>))+import Data.ByteString (ByteString) import Data.Text (Text) import Data.Maybe (fromMaybe)-import Foreign.Lua (FromLuaStack, NumResults, Lua, LuaInteger, ToLuaStack)-import Foreign.Lua.FunctionCalling (ToHaskellFunction, newCFunction)+import Foreign.Lua (NumResults, Lua, Peekable, Pushable, ToHaskellFunction) import qualified Foreign.Lua as Lua import qualified Data.Text as T @@ -50,7 +50,7 @@   addFunction "lower" (return . T.toLower :: Text -> Lua Text)   addFunction "upper" (return . T.toUpper :: Text -> Lua Text)   addFunction "reverse" (return . T.reverse :: Text -> Lua Text)-  addFunction "len" (return . fromIntegral . T.length :: Text -> Lua LuaInteger)+  addFunction "len" (return . fromIntegral . T.length :: Text -> Lua Lua.Integer)   addFunction "sub" sub   return 1 @@ -63,8 +63,8 @@ -- which produces the package. addPackagePreloader :: String -> Lua NumResults -> Lua () addPackagePreloader name modulePusher = do-  Lua.getglobal' "package.preload"-  Lua.pushcfunction =<< newCFunction modulePusher+  Lua.getfield Lua.registryindex Lua.preloadTableRegistryField+  Lua.pushHaskellFunction modulePusher   Lua.setfield (-2) name   Lua.pop 1 @@ -77,20 +77,10 @@   Lua.rawset (-3)  -- | Returns a substring, using Lua's string indexing rules.-sub :: Text -> LuaInteger -> OrNil LuaInteger -> Lua Text+sub :: Text -> Lua.Integer -> Lua.Optional Lua.Integer -> Lua Text sub s i j =   let i' = fromIntegral i-      j' = fromIntegral . fromMaybe (-1) $ toMaybe j+      j' = fromIntegral . fromMaybe (-1) $ Lua.fromOptional j       fromStart = if i' >= 0 then  i' - 1 else T.length s + i'       fromEnd   = if j' <  0 then -j' - 1 else T.length s - j'   in return . T.dropEnd fromEnd . T.drop fromStart $ s---- A lua value or nil-newtype OrNil a = OrNil { toMaybe :: Maybe a }--instance FromLuaStack a => FromLuaStack (OrNil a) where-  peek idx = do-    noValue <- Lua.isnoneornil idx-    if noValue-      then return (OrNil Nothing)-      else OrNil . Just <$> Lua.peek idx
test/test-hslua-module-text.hs view
@@ -1,5 +1,5 @@ {--Copyright © 2017 Albert Krewinkel+Copyright © 2017–2018 Albert Krewinkel  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal@@ -19,8 +19,10 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -}+{-# LANGUAGE OverloadedStrings #-}+ import Control.Monad (void, when)-import Foreign.Lua (Lua, runLua)+import Foreign.Lua (Lua) import Foreign.Lua.Module.Text (preloadTextModule, pushModuleText) import Test.Tasty (TestTree, defaultMain, testGroup) import Test.Tasty.HUnit (assertEqual, testCase)@@ -34,22 +36,22 @@ tests :: TestTree tests = testGroup "FromLuaStack"   [ testCase "text module can be pushed to the stack" $-      runLua (void pushModuleText)+      Lua.run (void pushModuleText) -  , testCase "text module can be added to the preloader" . runLua $ do+  , testCase "text module can be added to the preloader" . Lua.run $ do       Lua.openlibs       preloadTextModule "hstext"       assertEqual' "function not added to preloader" Lua.TypeFunction =<< do         Lua.getglobal' "package.preload.hstext"         Lua.ltype (-1) -  , testCase "text module can be loaded as hstext" . runLua $ do+  , testCase "text module can be loaded as hstext" . Lua.run $ do       Lua.openlibs       preloadTextModule "hstext"       assertEqual' "loading the module fails " Lua.OK =<<         Lua.dostring "require 'hstext'" -  , testCase "Lua tests pass" . runLua $ do+  , testCase "Lua tests pass" . Lua.run $ do       Lua.openlibs       preloadTextModule "hstext"       assertEqual' "error while running lua tests" Lua.OK =<< do