packages feed

hslua-cli 1.1.0 → 1.2.0

raw patch · 4 files changed

+54/−19 lines, 4 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ HsLua.CLI: ConsultEnvVars :: EnvBehavior
+ HsLua.CLI: IgnoreEnvVars :: EnvBehavior
+ HsLua.CLI: data EnvBehavior
+ HsLua.CLI: instance GHC.Classes.Eq HsLua.CLI.EnvBehavior
+ HsLua.CLI: instance GHC.Show.Show HsLua.CLI.EnvBehavior
- HsLua.CLI: Settings :: Text -> (LuaE e () -> IO ()) -> Settings e
+ HsLua.CLI: Settings :: Text -> (EnvBehavior -> LuaE e () -> IO ()) -> Settings e
- HsLua.CLI: [settingsRunner] :: Settings e -> LuaE e () -> IO ()
+ HsLua.CLI: [settingsRunner] :: Settings e -> EnvBehavior -> LuaE e () -> IO ()
- HsLua.CLI: runStandalone :: LuaError e => Settings e -> IO ()
+ HsLua.CLI: runStandalone :: LuaError e => Settings e -> String -> [String] -> IO ()

Files

CHANGELOG.md view
@@ -2,6 +2,13 @@  `hslua-cli` uses [PVP Versioning](https://pvp.haskell.org). +## hslua-cli-1.2.0++Released 2022-09-27.++-   The function `runStandalone` now takes two additional+    arguments, the program name and list command line args.+ ## hslua-cli-1.1.0  Released 2022-09-26.
app/hslua.hs view
@@ -9,16 +9,24 @@ Re-implementation of the standard Lua interpreter. -} module Main (main) where-import HsLua.Core  as Lua (Exception, openlibs, run)-import HsLua.CLI (Settings (..), runStandalone)+import Control.Monad (when)+import HsLua.Core  as Lua+  (Exception, openlibs, pushboolean, registryindex, run, setfield)+import HsLua.CLI (EnvBehavior (IgnoreEnvVars), Settings (..), runStandalone)+import System.Environment (getArgs, getProgName)  -- | Run a default Lua interpreter. main :: IO () main = do   let settings = Settings         { settingsVersionInfo = ""-        , settingsRunner = \action -> run $ do+        , settingsRunner = \envBehavior action -> run $ do+            when (envBehavior == IgnoreEnvVars) $ do+              pushboolean True+              setfield registryindex "LUA_NOENV"             openlibs             action         }-  runStandalone @Lua.Exception settings+  prg  <- getProgName+  args <- getArgs+  runStandalone @Lua.Exception settings prg args
hslua-cli.cabal view
@@ -1,6 +1,6 @@ cabal-version:       2.2 name:                hslua-cli-version:             1.1.0+version:             1.2.0 synopsis:            Command-line interface for Lua description:         Provides an embeddable command-line interface for Lua.                      The interface is compatible with the standard Lua@@ -52,8 +52,6 @@   if impl(ghc >= 8.4)     ghc-options:       -Wmissing-export-lists                        -Wpartial-fields-  if impl(ghc >= 8.8)-    ghc-options:       -Wmissing-deriving-strategies    default-language:    Haskell2010 
src/HsLua/CLI.hs view
@@ -13,6 +13,7 @@   ( -- * Run scripts as program     runStandalone   , Settings (..)+  , EnvBehavior (..)   ) where  import Control.Monad (unless, when, zipWithM_)@@ -25,7 +26,7 @@ import Foreign.Ptr (nullPtr) import HsLua.Core (LuaE, LuaError) import System.Console.GetOpt-import System.Environment (getArgs, getProgName, lookupEnv)+import System.Environment (lookupEnv) import System.IO (hPutStrLn, stderr) import qualified Lua.Auxiliary as Lua import qualified Lua.Constants as Lua@@ -38,17 +39,33 @@ import qualified HsLua.Core.Utf8 as UTF8  -- | Settings for the Lua command line interface.+--+-- If env vars should be ignored, and the interpreter invokes+-- @openlibs@, then the registry key @LUA_NOENV@ should be set to @true@+-- before that function is invoked. E.g.:+--+-- > runner envBehavior action = run $ do+-- >   when (envBehavior == IgnoreEnvVars) $ do+-- >     pushboolean True+-- >     setfield registryindex "LUA_NOENV"+-- >   openlibs+-- >   action+-- data Settings e = Settings   { settingsVersionInfo :: Text-  , settingsRunner      :: LuaE e () -> IO ()+  , settingsRunner      :: EnvBehavior -> LuaE e () -> IO ()+    -- ^ The Lua interpreter to be used; the first argument indicates+    -- whether environment variables should be consulted or ignored.   } +-- | Whether environment variables should be consulted or ignored.+data EnvBehavior = IgnoreEnvVars | ConsultEnvVars+  deriving (Eq, Show)+ -- | Get the Lua interpreter options from the command line. Throws an -- error with usage instructions if parsing fails.-getOptions :: IO Options-getOptions = do-  rawArgs <- getArgs-  progName <- getProgName+getOptions :: String -> [String] -> IO Options+getOptions progName rawArgs = do   let (actions, args, errs) = getOpt RequireOrder luaOptions rawArgs   unless (null errs) . ioError . userError $     let usageHead = "Usage: " ++ progName ++ " [options] [script [args]]"@@ -89,17 +106,22 @@ -- and tries to run that script in Lua. Falls back to stdin if no file -- is given. Any remaining args are passed to Lua via the global table -- @arg@.-runStandalone :: LuaError e => Settings e -> IO ()-runStandalone settings = do-  opts <- getOptions-  settingsRunner settings $ do+runStandalone :: LuaError e+              => Settings e   -- ^ interpreter configuration+              -> String       -- ^ program name (for error messages)+              -> [String]     -- ^ command line arguments+              -> IO ()+runStandalone settings progName args = do+  opts <- getOptions progName args+  let envVarOpt = if optNoEnv opts+                  then IgnoreEnvVars+                  else ConsultEnvVars+  settingsRunner settings envVarOpt $ do     let putErr = Lua.liftIO . hPutStrLn stderr     -- print version info     when (optVersion opts) (showVersion $ settingsVersionInfo settings)     when (optInteractive opts) $       putErr "[WARNING] Flag `-i` is not supported yet."-    when (optNoEnv opts) $-      putErr "[WARNING] Flag `-E` is not fully supported yet."      -- push `arg` table     case optScript opts of