packages feed

pandoc-lua-marshal 0.1.4 → 0.1.5

raw patch · 8 files changed

+82/−12 lines, 8 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

Files

CHANGELOG.md view
@@ -2,6 +2,18 @@  `pandoc-lua-marshal` uses [PVP Versioning][]. +## 0.1.5++Released 2022-02-17.++-   Allow any type of callable object as argument to List+    functions `filter`, `map`, and `find_if`. These previously+    required the argument to be of type `function`, which was too+    restrictive.+    +-   Inline: the type of Image captions is now `Inlines` instead+    of `List`.+ ## 0.1.4  Released 2022-01-29.
cbits/listmod.c view
@@ -29,6 +29,18 @@ }  /*+** Check that 'arg' is either a function or a different callable object.+*/+static void checkcallable (lua_State *L, int arg) {+  if (lua_type(L, arg) != LUA_TFUNCTION) { /* is it not a function? */+    if (luaL_getmetafield(L, arg, "__call"))+      lua_pop(L, 1); /* pop metamethod */+    else+      luaL_checktype(L, arg, LUA_TFUNCTION); /* force an error */+  }+}++/* ** Creates a List from a table; uses a fresh, empty table if none is ** given. */@@ -147,7 +159,7 @@ static int list_filter (lua_State *L) {   lua_settop(L, 2);   luaL_checktype(L, 1, LUA_TTABLE);-  luaL_checktype(L, 2, LUA_TFUNCTION);+  checkcallable(L, 2);   luaL_checkstack(L, 4, NULL);   lua_Integer len = luaL_len(L, 1);   lua_createtable(L, len, 0);  /* create new table */@@ -197,7 +209,7 @@ static int list_find_if (lua_State *L) {   lua_settop(L, 3);   luaL_checktype(L, 1, LUA_TTABLE);-  luaL_checktype(L, 2, LUA_TFUNCTION);+  checkcallable(L, 2);   lua_Integer len = luaL_len(L, 1);   lua_Integer start = posrelat(luaL_optinteger(L, 3, 1), len);   for (lua_Integer i = start; i <= len; i++) {@@ -237,7 +249,7 @@ static int list_map(lua_State *L) {   lua_settop(L, 2);   luaL_checktype(L, 1, LUA_TTABLE);-  luaL_checktype(L, 2, LUA_TFUNCTION);+  checkcallable(L, 2);   lua_Integer len = luaL_len(L, 1);   lua_createtable(L, len, 0);  /* create new table */   luaL_getmetatable(L, LIST_T);  /* make result a generic list */
pandoc-lua-marshal.cabal view
@@ -1,6 +1,6 @@ cabal-version:       2.4 name:                pandoc-lua-marshal-version:             0.1.4+version:             0.1.5 synopsis:            Use pandoc types in Lua description:         This package provides functions to marshal and unmarshal                      pandoc document types to and from Lua.
src/Text/Pandoc/Lua/Marshal/Citation.hs view
@@ -17,9 +17,10 @@ import Control.Applicative (optional) import Data.Maybe (fromMaybe) import HsLua as Lua-import Text.Pandoc.Lua.Marshal.CitationMode (peekCitationMode, pushCitationMode)-import {-# SOURCE #-} Text.Pandoc.Lua.Marshal.Inline (peekInlinesFuzzy, pushInlines) import Text.Pandoc.Definition (Citation (..))+import Text.Pandoc.Lua.Marshal.CitationMode (peekCitationMode, pushCitationMode)+import {-# SOURCE #-} Text.Pandoc.Lua.Marshal.Inline+  ( peekInlinesFuzzy, pushInlines )  -- | Pushes a Citation value as userdata object. pushCitation :: LuaError e
src/Text/Pandoc/Lua/Marshal/Inline.hs view
@@ -127,7 +127,7 @@           _               -> const Absent)    , possibleProperty "caption" "image caption"-      (pushPandocList pushInline, \case+      (pushInlines, \case           Image _ capt _ -> Actual capt           _              -> Absent)       (peekInlinesFuzzy, \case
src/Text/Pandoc/Lua/Marshal/Inline.hs-boot view
@@ -1,4 +1,9 @@ {-# LANGUAGE FlexibleContexts     #-}+{-# LANGUAGE LambdaCase           #-}+{-# LANGUAGE OverloadedStrings    #-}+{-# LANGUAGE ScopedTypeVariables  #-}+{-# LANGUAGE TypeApplications     #-}+{-# LANGUAGE TupleSections        #-} module Text.Pandoc.Lua.Marshal.Inline   ( -- * Single Inline elements     peekInline
test/test-inline.lua view
@@ -60,12 +60,16 @@       end)     },     group 'Image' {-      test('has property `caption`', function ()+      test('has property `caption` of type Inlines', function ()         local img = Image('example', 'a.png')         assert.are_same(img.caption, {Str 'example'})          img.caption = 'A'         assert.are_equal(img, Image({'A'}, 'a.png'))+        assert.are_equal(+          Image('example', 'a.png').caption,+          Inlines('example')+        )       end),       test('has property `src`', function ()         local img = Image('example', 'sample.png')
test/test-list.lua view
@@ -59,7 +59,21 @@           args,           List{{0, 1}, {1, 2}, {1, 3}, {2, 4}, {3, 5}, {5, 6}, {8, 7}}         )-      end)+      end),+      test('accepts callable table as function', function ()+        local always_true = function (t, x) return true end+        local callable = setmetatable({}, {__call = always_true})+        assert.are_same(+          List{0},+          List{0}:filter(callable)+        )+      end),+      test('fails on non-callable table', function ()+        assert.error_matches(+          function () List{1}:filter({}) end,+          'bad argument %#1 to \'filter\' %(function expected, got table%)'+        )+      end),     },      group 'find' {@@ -85,7 +99,7 @@           function () List:new{}:find(0, 'NaN') end,           'number expected, got string'         )-      end)+      end),     },      group 'find_if' {@@ -117,7 +131,18 @@           function () List:new{}:find(0, 'NaN') end,           'number expected, got string'         )-      end)+      end),+      test('accepts callable table', function ()+        local always_true = function (t, x) return true end+        local callable = setmetatable({}, {__call = always_true})+        assert.are_equal(List{1}:find_if(callable), 1)+      end),+      test('fails on non-callable table', function ()+         assert.error_matches(+           function () List():find_if({}) end,+           'bad argument %#1 to \'find_if\' %(function expected, got table%)'+         )+      end),     },      group 'includes' {@@ -176,7 +201,18 @@           debug.getmetatable(custom:map(tostring)).__name,           'List'         )-      end)+      end),+      test('accepts callable table', function ()+        local plus_length = function (t, x) return x + #t end+        local callable = setmetatable({1, 2}, {__call = plus_length})+        assert.are_equal(List{1, 3}:map(callable), List{3, 5})+      end),+      test('fails on non-callable table', function ()+        assert.error_matches(+          function () List{1}:map({}) end,+          'bad argument %#1 to \'map\' %(function expected, got table%)'+        )+      end),     },      group 'new' {