packages feed

hslua-list 1.1.0.1 → 1.1.1

raw patch · 7 files changed

+65/−9 lines, 7 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

Files

CHANGELOG.md view
@@ -2,6 +2,14 @@  `hslua-list` uses [PVP Versioning](https://pvp.haskell.org). +## hslua-list-1.1.1++Released 2023-03-17.++-   Conversion to strings: added a `__tostring` that lists all+    elements separated by commas and a space, surrounded by braces+    and prefixed with the metatable's name.+ ## hslua-list-1.1.0.1  Released 2023-01-23.@@ -11,7 +19,7 @@  ## hslua-list-1.1.0 -Release pending.+Released 2023-03-13.  -   Removed `pushPandocList`. The function was a left-over from     pandoc-lua-marshal, the place where this package originated.
LICENSE view
@@ -1,4 +1,4 @@-Copyright © 2021-2022 Albert Krewinkel+Copyright © 2021-2023 Albert Krewinkel  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the
cbits/listmod.c view
@@ -264,7 +264,40 @@   return 1; } ++static void addfield (lua_State *L, luaL_Buffer *b, lua_Integer i) {+  lua_geti(L, 1, i);+  luaL_tolstring(L, -1, NULL);+  lua_remove(L, -2);  /* element */+  luaL_addvalue(b);+}+ /*+** Convert the list to a string.+*/+static int list_tostring(lua_State *L) {+  luaL_Buffer b;+  lua_Integer len = luaL_len(L, 1);+  luaL_buffinit(L, &b);+  /* Prefix the string with name from metatable */+  if (luaL_getmetafield(L, 1, "__name") != LUA_TNIL) {+    luaL_addvalue(&b);+    luaL_addchar(&b, ' ');+  }+  luaL_addchar(&b, '{');+  lua_Integer i = 1;+  for (; i < len; i++) {+    addfield(L, &b, i);+    luaL_addstring(&b, ", ");+  }+  if (i == len)  /* add last value (if interval was not empty) */+    addfield(L, &b, i);+  luaL_addchar(&b, '}');+  luaL_pushresult(&b);+  return 1;+}++/* ** Pushes the standard `table` module to the stack. */ static void pushtablemodule (lua_State *L) {@@ -309,6 +342,7 @@ static const luaL_Reg list_funcs[] = {   {"__concat", list_concat},   {"__eq", list_eq},+  {"__tostring", list_tostring},   {"clone", list_clone},   {"extend", list_extend},   {"filter", list_filter},
hslua-list.cabal view
@@ -1,6 +1,6 @@ cabal-version:       2.2 name:                hslua-list-version:             1.1.0.1+version:             1.1.1 synopsis:            Opinionated, but extensible Lua list type. description:         List type for Lua, with a Haskell interface. homepage:            https://hslua.org/@@ -8,8 +8,8 @@ license:             MIT license-file:        LICENSE author:              Albert Krewinkel-maintainer:          Albert Krewinkel <albert@hslua.org>-copyright:           © 2022 Albert Krewinkel+maintainer:          Albert Krewinkel <tarleb@hslua.org>+copyright:           © 2022-2023 Albert Krewinkel category:            Foreign build-type:          Simple extra-doc-files:     README.md
src/HsLua/List.hs view
@@ -1,8 +1,8 @@ {-# LANGUAGE LambdaCase           #-} {- |-Copyright  : © 2021-2022 Albert Krewinkel+Copyright  : © 2021-2023 Albert Krewinkel License    : MIT-Maintainer : Albert Krewinkel <tarleb+pandoc@moltkeplatz.de>+Maintainer : Albert Krewinkel <tarleb@hslua.org>  Lua lists with additional methods. -}
test/test-hslua-list.hs view
@@ -3,9 +3,9 @@ {-# LANGUAGE TypeApplications    #-} {-| Module      : Main-Copyright   : © 2021-2022 Albert Krewinkel+Copyright   : © 2021-2023 Albert Krewinkel License     : MIT-Maintainer  : Albert Krewinkel <albert@hslua.org>+Maintainer  : Albert Krewinkel <tarleb@hslua.org>  Tests for the list type. -}
test/test-list.lua view
@@ -312,6 +312,20 @@           "abc"         )       end),+    },+    group 'tostring' {+      test('lists all elements', function ()+        assert.are_equal(+          tostring(List {5, 23, 42}),+          'List {5, 23, 42}'+        )+      end),+      test('empty list', function ()+        assert.are_equal(+          tostring(List {}),+          'List {}'+        )+      end),     }   }, }