lua 2.0.1 → 2.0.2
raw patch · 6 files changed
+83/−6 lines, 6 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- CHANGELOG.md +8/−0
- cbits/hslua/hslua.c +15/−3
- lua.cabal +5/−2
- src/Lua/Primary.hs +1/−1
- test/Lua/ErsatzTests.hs +52/−0
- test/test-lua.hs +2/−0
CHANGELOG.md view
@@ -2,6 +2,14 @@ `lua` uses [PVP Versioning][1]. +## lua 2.0.2++Released 2021-11-26.++- Make sure lualib.h is available through this package. The header+ file contains info on how and under which name the standard+ library is loaded.+ ## lua 2.0.1 Released 2021-11-03.
cbits/hslua/hslua.c view
@@ -76,7 +76,11 @@ lua_pushcfunction(L, hslua__getglobal); lua_pushglobaltable(L); lua_pushlstring(L, name, len);- *status = lua_pcall(L, 2, 1, 0);+ if (status == NULL) {+ lua_pcall(L, 2, 1, 0);+ } else {+ *status = lua_pcall(L, 2, 1, 0);+ } return lua_type(L, -1); } @@ -96,7 +100,11 @@ lua_pushvalue(L, index); lua_pushcfunction(L, hslua__gettable); lua_insert(L, -3);- *status = lua_pcall(L, 2, 1, 0);+ if (status == NULL) {+ lua_pcall(L, 2, 1, 0);+ } else {+ *status = lua_pcall(L, 2, 1, 0);+ } return lua_type(L, -1); } @@ -121,7 +129,11 @@ lua_pushlstring(L, name, len); lua_pushcfunction(L, hslua__setglobal); lua_insert(L, -4);- *status = lua_pcall(L, 3, 0, 0);+ if (status == NULL) {+ lua_pcall(L, 3, 0, 0);+ } else {+ *status = lua_pcall(L, 3, 0, 0);+ } }
lua.cabal view
@@ -1,6 +1,6 @@ cabal-version: 2.2 name: lua-version: 2.0.1+version: 2.0.2 synopsis: Lua, an embeddable scripting language description: This package provides bindings and types to bridge Haskell and <https://www.lua.org/ Lua>.@@ -144,6 +144,7 @@ includes: lua.h , luaconf.h , lauxlib.h+ , lualib.h if flag(system-lua) || flag(pkg-config) if flag(pkg-config) pkgconfig-depends: lua5.3@@ -154,6 +155,7 @@ install-includes: lua.h , luaconf.h , lauxlib.h+ , lualib.h c-sources: cbits/lua-5.3.6/lapi.c , cbits/lua-5.3.6/lcode.c , cbits/lua-5.3.6/lctype.c@@ -207,7 +209,8 @@ type: exitcode-stdio-1.0 main-is: test-lua.hs hs-source-dirs: test- other-modules: Lua.UnsafeTests+ other-modules: Lua.ErsatzTests+ , Lua.UnsafeTests build-depends: lua , tasty >= 0.11 , tasty-hunit >= 0.9
src/Lua/Primary.hs view
@@ -438,7 +438,7 @@ -- table at the given index (the \"next\" pair after the given key). If -- there are no more elements in the table, then -- <https://www.lua.org/manual/5.3/manual.html#lua_next lua_next>--- returns 'FALSE' (and pushes nothing).+-- returns 'Lua.FALSE' (and pushes nothing). -- -- A typical traversal looks like this: --
+ test/Lua/ErsatzTests.hs view
@@ -0,0 +1,52 @@+{-|+Module : Lua.ErsatzTests+Copyright : © 2021 Albert Krewinkel+License : MIT+Maintainer : Albert Krewinkel <tarleb+hslua@zeitkraut.de>+Stability : beta++Tests for Lua bindings.+-}+module Lua.ErsatzTests (tests) where++import Control.Monad (void)+import Foreign.C.String (withCStringLen)+import Foreign.Ptr (nullPtr)+import Lua+import Test.Tasty (TestTree, testGroup)+import Test.Tasty.HUnit (Assertion, HasCallStack, testCase, (@=?) )++-- | Tests for unsafe methods.+tests :: TestTree+tests = testGroup "ersatz"+ [ testGroup "global"+ [ "set and get global field" =: do+ (42, LUA_TNUMBER) `shouldBeResultOf` \l -> do+ lua_pushinteger l 42+ tp <- withCStringLen "ups" $ \(name, nameLen) -> do+ hslua_setglobal l name (fromIntegral nameLen) nullPtr+ hslua_getglobal l name (fromIntegral nameLen) nullPtr+ i <- lua_tointegerx l top nullPtr+ return (i, tp)++ , "get value from table" =: do+ (-23, LUA_TNUMBER) `shouldBeResultOf` \l -> do+ withCStringLen "return {[5] = -23}" $ \(name, len) -> void $+ luaL_loadbuffer l name (fromIntegral len) name+ LUA_OK <- lua_pcall l 0 1 0+ lua_pushinteger l 5+ ty <- hslua_gettable l (nth 2) nullPtr+ i <- lua_tointegerx l top nullPtr+ return (i, ty)+ ]+ ]++infix 3 =:+(=:) :: String -> Assertion -> TestTree+(=:) = testCase++shouldBeResultOf :: (HasCallStack, Eq a, Show a)+ => a -> (State -> IO a) -> Assertion+shouldBeResultOf expected luaOp = do+ result <- withNewState luaOp+ expected @=? result
test/test-lua.hs view
@@ -24,6 +24,7 @@ import Lua import Test.Tasty (TestTree, defaultMain, testGroup) import Test.Tasty.HUnit (Assertion, HasCallStack, assertBool, testCase, (@=?))+import qualified Lua.ErsatzTests import qualified Lua.UnsafeTests -- | Runs tests.@@ -390,6 +391,7 @@ ] , Lua.UnsafeTests.tests+ , Lua.ErsatzTests.tests ] infix 3 =: