packages feed

hslua-marshalling 2.0.0 → 2.0.1

raw patch · 4 files changed

+32/−4 lines, 4 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

Files

CHANGELOG.md view
@@ -2,9 +2,17 @@  `hslua-marshalling` uses [PVP Versioning](https://pvp.haskell.org). +### hslua-marshalling 2.0.1++Released 2021-11-04.++  - Allow `pushIterator` to skip values: If the function that+    pushes the values of a list item signals that it didn't push any+    values, then that value will be skipped.+ ### hslua-marshalling 2.0.0 -Release pending.+Released 2021-10-21.  - Initially created. Contains modules previously found in the   modules `Foreign.Lua.Peek` and `Foreign.Lua.Push` from
hslua-marshalling.cabal view
@@ -1,6 +1,6 @@ cabal-version:       2.2 name:                hslua-marshalling-version:             2.0.0+version:             2.0.1 synopsis:            Marshalling of values between Haskell and Lua. description:         Provides functions to marshal values from Haskell                      to Lua, and /vice versa/.
src/HsLua/Marshalling/Userdata.hs view
@@ -23,8 +23,12 @@ -- | Pushes three values to the stack that can be used in a generic for -- loop to lazily iterate over all values in the list. Keeps the -- remaining list in a userdata state.+--+-- If the values pusher function returns @'NumResults' 0@ for a list+-- item, then this item will be skipped and the values for the next item+-- will be pushed. pushIterator :: forall a e. LuaError e-             => (a -> LuaE e NumResults)  -- ^ the values to push+             => (a -> LuaE e NumResults)  -- ^ pusher for the values              -> [a]                       -- ^ list to iterate over lazily              -> LuaE e NumResults pushIterator pushValues xs = do@@ -45,7 +49,9 @@           success <- putuserdata @[a] (nthBottom 1) statename ys           if not success             then failLua "Error in iterator: could not update iterator state."-            else pushValues y+            else pushValues y >>= \case+              0 -> nextItem  -- keep going if nothing was pushed+              n -> return n      statename :: Name     statename = "HsLua iterator state"
test/HsLua/Marshalling/UserdataTests.hs view
@@ -36,5 +36,19 @@           ]         when (stat /= Lua.OK) Lua.throwErrorAsException         Lua.tostring Lua.top+    , "skip entry if value pusher returned 0" =:+      Just "1,3,4" `shouldBeResultOf` do+        let pushNoTwo 2 = return 0+            pushNoTwo i = 1 <$ Lua.pushinteger i+        Lua.openlibs+        Lua.pushHaskellFunction $ pushIterator pushNoTwo [1..4]+        Lua.setglobal "skip"+        stat <- Lua.dostring $ mconcat+          [ "local acc = {}\n"+          , "for n in skip() do table.insert(acc, n) end\n"+          , "return table.concat(acc, ',')\n"+          ]+        when (stat /= Lua.OK) Lua.throwErrorAsException+        Lua.tostring Lua.top     ]   ]