hslua-repl 0.1.0 → 0.1.1
raw patch · 3 files changed
+29/−7 lines, 3 filesdep ~hslua-corePVP ok
version bump matches the API change (PVP)
Dependency ranges changed: hslua-core
API changes (from Hackage documentation)
+ HsLua.REPL: replWithEnv :: LuaError e => Maybe Reference -> LuaE e NumResults
Files
- CHANGELOG.md +9/−1
- hslua-repl.cabal +3/−3
- src/HsLua/REPL.hs +17/−3
CHANGELOG.md view
@@ -4,7 +4,15 @@ ## hslua-repl-0.1.0 -Release pending.+Released 2023-03-17.++- Running the REPL in specific environments: the new+ `replWithEnv` function allows to load all inputs in an+ environment that's specified by a *Reference* value.++## hslua-repl-0.1.0++Released 2023-03-16. - A new package begins its way into the undiscovered land. May it live long and prosper.
hslua-repl.cabal view
@@ -1,6 +1,6 @@ cabal-version: 2.2 name: hslua-repl-version: 0.1.0+version: 0.1.1 synopsis: Isocline-based Lua REPL description: An embeddable Lua REPL built with Isocline and HsLua. homepage: https://hslua.org/@@ -9,7 +9,7 @@ license-file: LICENSE author: Albert Krewinkel maintainer: Albert Krewinkel <tarleb@hslua.org>-copyright: © lbert Krewinkel+copyright: © 2023 Albert Krewinkel category: Foreign build-type: Simple extra-doc-files: README.md@@ -33,7 +33,7 @@ common common-options build-depends: base >= 4.9.1 && < 5- , hslua-core >= 2.3 && < 2.4+ , hslua-core >= 2.3.1 && < 2.4 , text >= 1.2 && < 2.1 ghc-options: -Wall
src/HsLua/REPL.hs view
@@ -14,6 +14,7 @@ module HsLua.REPL ( -- * Run scripts as program repl+ , replWithEnv , setup , Config (..) , defaultConfig@@ -90,9 +91,14 @@ else throwErrorAsException _ -> throwErrorAsException --- | Run a Lua repl.+-- | Run a Lua REPL. repl :: LuaError e => LuaE e NumResults-repl = try repl' >>= \case+repl = replWithEnv Nothing++-- | Run a Lua REPL, using the table in the given upvalue as the load+-- environment.+replWithEnv :: LuaError e => Maybe Reference -> LuaE e NumResults+replWithEnv mEnvRef = try repl' >>= \case Right n -> pure n -- Ctrl-D or Ctrl-C Left err -> do -- something went wrong: report error, reset stack and try again@@ -100,7 +106,7 @@ pushException err call 1 0 settop 0- repl+ replWithEnv mEnvRef where repl' :: LuaError e => LuaE e NumResults repl' = liftIO (readlineMaybe "") >>= \case@@ -111,6 +117,14 @@ settop 0 -- reset stack let input = UTF8.fromString inputStr loadExpression input <|> loadStatement [input]+ -- take env (if any) and set it as the first upvalue of the loaded+ -- thunk.+ case mEnvRef of+ Nothing -> pure ()+ Just envRef -> do+ getref registryindex envRef >>= \case+ TypeTable -> void $ setupvalue (nth 2) 1+ _ -> pop 1 -- run loaded input callTrace 0 multret nvalues <- gettop