diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..36a39b0 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,34 @@ +name: Deploy + +on: [ push, workflow_dispatch ] + +jobs: + + affected: + uses: lunarmodules/.github/.github/workflows/list_affected_rockspecs.yml@main + + build: + needs: affected + if: ${{ needs.affected.outputs.rockspecs }} + uses: lunarmodules/.github/.github/workflows/test_build_rock.yml@main + with: + rockspecs: ${{ needs.affected.outputs.rockspecs }} + + upload: + needs: [ affected, build ] + # Only run upload if: + # 1. We are on the canonical repository (no uploads from forks) + # 2. The current commit is either tagged or on the default branch (the workflow will upload dev/scm rockspecs any + # time they are touched, tagged ones whenever the edited rockspec and tag match) + # 3. Some rockspecs were changed — this implies the commit changing the rockspec is the same one that gets tagged + if: >- + ${{ + github.repository == 'lunarmodules/lua-iconv' && + ( github.ref_name == 'master' || startsWith(github.ref, 'refs/tags/') ) && + needs.affected.outputs.rockspecs + }} + uses: lunarmodules/.github/.github/workflows/upload_to_luarocks.yml@main + with: + rockspecs: ${{ needs.affected.outputs.rockspecs }} + secrets: + apikey: ${{ secrets.LUAROCKS_APIKEY }} diff --git a/.github/workflows/luacheck.yml b/.github/workflows/luacheck.yml new file mode 100644 index 0000000..9cb784c --- /dev/null +++ b/.github/workflows/luacheck.yml @@ -0,0 +1,13 @@ +name: Luacheck + +on: [push, pull_request] + +jobs: + + luacheck: + runs-on: ubuntu-22.04 + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Luacheck + uses: lunarmodules/luacheck@v1 diff --git a/README b/README deleted file mode 100644 index 0756352..0000000 --- a/README +++ /dev/null @@ -1,129 +0,0 @@ -Lua-iconv: performs character set conversions in Lua -(c) 2005-11 Alexandre Erwin Ittner -Project page: http://ittner.github.com/lua-iconv/ - - -=== Introduction === - -Lua-iconv is POSIX 'iconv' binding for the Lua Programming Language. The -iconv library converts a sequence of characters from one codeset into a -sequence of corresponding characters in another codeset. The codesets -are those specified in the iconv.new() call that returned the conversion -descriptor, cd. - -Lua-iconv 7 *requires* Lua 5.1 or Lua 5.2. For Lua 5.0, use the first -release (lua-iconv-r1). - -Details on iconv may be obtained in the Open Group's interface definition -(http://www.opengroup.org/onlinepubs/007908799/xsh/iconv.h.html). - - - -=== Download and installation === - -Lua-iconv can be obtained from its GitHub project page -(https://github.com/ittner/lua-iconv/downloads), from a LuaRocks server or -from some Linux distributions which already provide it (eg. Debian). - -Unless you downloaded a compiled package, you must build the library for -your system. If you have LuaRocks installed, all the process is automatic; -just fire up your favourite shell and type, as root: - - luarocks install lua-iconv - -and the package will be downloaded from a rock server, installed and -configured. Otherwise, you must compile and install the package. In a system -with pkg-config (as many Linux distributions and Unix flavors) open a shell, -untar the distribution package and, within the program directory, type: - - make install - -as root. The library will be compiled and installed on the in the correct -path (which is defined in lua5.x.pc). Compiling on systems without pkg-config -requires manual changes in the Makefile (this includes Windows). - - - -=== Loading and initialization === - -Lua-iconv is a shared library that must be loaded in the Lua interpreter -before use. You can simply do a - - local iconv = require("iconv") - -call to load up the library (that, of course, must be installed in a -directory from package.cpath). - - - -=== API documentation === - - cd = iconv.new(to, from) - cd = iconv.open(to, from) - - Opens a new conversion descriptor, from the 'from' charset to the - 'to' charset. Concatenating "//TRANSLIT" to the first argument will - enable character transliteration and concatenating "//IGNORE" to - the first argument will cause iconv to ignore any invalid characters - found in the input string. - - This function returns a new converter or nil on error. - - - nstr, err = cd:iconv(str) - - Converts the 'str' string to the desired charset. This method always - returns two arguments: the converted string and an error code, which - may have any of the following values: - - nil - No error. Conversion was successful. - - iconv.ERROR_NO_MEMORY - Failed to allocate enough memory in the conversion process. - - iconv.ERROR_INVALID - An invalid character was found in the input sequence. - - iconv.ERROR_INCOMPLETE - An incomplete character was found in the input sequence. - - iconv.ERROR_FINALIZED - Trying to use an already-finalized converter. This usually means - that the user was tweaking the garbage collector private methods. - - iconv.ERROR_UNKNOWN - There was an unknown error. - - -=== License === - -Lua-iconv is copyrighted free software: it can be used for both academic -and commercial purposes at absolutely no cost. There are no royalties -or GNU-like "copyleft" restrictions. The legal details are below: - - Lua-iconv is (c) 2005-11 Alexandre Erwin Ittner - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject - to the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - IN NO EVENT SHALL THE AUTHOR OR COPYRIGHT HOLDER BE LIABLE FOR ANY - CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - - If you use this package in a product, an acknowledgment in the product - documentation would be greatly appreciated (but it is not required). - - diff --git a/README.md b/README.md new file mode 100644 index 0000000..a975d2f --- /dev/null +++ b/README.md @@ -0,0 +1,130 @@ +# Lua-iconv + +Perform character set conversions in Lua + +(c) 2005-11 Alexandre Erwin Ittner + + +## Introduction + +Lua-iconv provides POSIX 'iconv' bindings for the Lua Programming Language. +The iconv library converts a sequence of characters from one codeset into a sequence of corresponding characters in another codeset. +The codesets are those specified in the `iconv.new()` call that returned the conversion descriptor, `cd`. + +Lua-iconv 7 *requires* Lua 5.1 or Lua 5.2. For Lua 5.0, use the first release (lua-iconv-r1). + +Details on iconv may be obtained in the [Open Group's interface definition](http://www.opengroup.org/onlinepubs/007908799/xsh/iconv.h.html). + + +## Download and installation + +Lua-iconv can be obtained from [its GitHub project page](https://github.com/lunarmodules/lua-iconv), from a LuaRocks server, or from some Linux distributions which already provide it (eg. Debian). + +Unless you downloaded a compiled package, you must build the library for your system. +If you have LuaRocks installed, all the process is automatic; just fire up your favourite shell and type, as root: + +```console +luarocks install lua-iconv +``` + +and the package will be downloaded from a rock server, installed and configured. +Otherwise, you must compile and install the package. +In a system with pkg-config (as many Linux distributions and Unix flavors) open a shell, untar the distribution package and, within the program directory, type: + +```console +make install +``` + +as root. +The library will be compiled and installed on the in the correct path (which is defined in lua5.x.pc). +Compiling on systems without pkg-config requires manual changes in the Makefile (this includes Windows). + + +## Loading and initialization + +Lua-iconv is a shared library that must be loaded in the Lua interpreter before use. +You can simply do a + +```lua +local iconv = require("iconv") +``` + +call to load up the library (that, of course, must be installed in a directory from `package.cpath`). + + +## API documentation + +```lua +cd = iconv.new(to, from) +cd = iconv.open(to, from) +``` + +Opens a new conversion descriptor, from the 'from' charset to the 'to' charset. +Concatenating "//TRANSLIT" to the first argument will enable character transliteration and concatenating "//IGNORE" to the first argument will cause iconv to ignore any invalid characters found in the input string. + +This function returns a new converter or nil on error. + + +```lua +nstr, err = cd:iconv(str) +``` + +Converts the 'str' string to the desired charset. +This method always returns two arguments: the converted string and an error code, which may have any of the following values: + +* `nil` + + No error. Conversion was successful. + +* `iconv.ERROR_NO_MEMORY` + + Failed to allocate enough memory in the conversion process. + +* `iconv.ERROR_INVALID` + + An invalid character was found in the input sequence. + +* `iconv.ERROR_INCOMPLETE` + + An incomplete character was found in the input sequence. + +* `iconv.ERROR_FINALIZED` + + Trying to use an already-finalized converter. This usually means + that the user was tweaking the garbage collector private methods. + +* `iconv.ERROR_UNKNOWN` + + There was an unknown error. + + +## License + +Lua-iconv is copyrighted free software: it can be used for both academic +and commercial purposes at absolutely no cost. There are no royalties +or GNU-like "copyleft" restrictions. The legal details are below: + + Lua-iconv is (c) 2005-11 Alexandre Erwin Ittner + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject + to the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE AUTHOR OR COPYRIGHT HOLDER BE LIABLE FOR ANY + CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + If you use this package in a product, an acknowledgment in the product + documentation would be greatly appreciated (but it is not required). + diff --git a/makestr.lua b/makestr.lua index 1b47409..d725936 100644 --- a/makestr.lua +++ b/makestr.lua @@ -3,8 +3,6 @@ local fp = assert(io.open(arg[1], "rb")) local str = assert(fp:read("*a")) fp:close() -local i -local c = 0 local ostr = "local xxxxxxxxxxx = \"" for i = 1, string.len(str) do ostr = ostr .. "\\" .. string.byte(string.sub(str, i, i+1)) diff --git a/rockspecs/lua-iconv-6-1.rockspec b/rockspecs/lua-iconv-6-1.rockspec new file mode 100644 index 0000000..69b1dfd --- /dev/null +++ b/rockspecs/lua-iconv-6-1.rockspec @@ -0,0 +1,52 @@ + +-- Packs lua-iconv into a LuaRock +-- rockspec based uppon the file provided by DarkGod + +package = "lua-iconv" +version = "6-1" + +source = { + url = "http://luaforge.net/frs/download.php/4181/lua-iconv-6.tar.gz", + md5 = "2cec334c5786d7c420a53003d6cb93d4" +} + +description = { + summary = "Lua binding to the iconv", + detailed = [[ + Lua binding to the POSIX 'iconv' library, which converts a sequence of + characters from one codeset into a sequence of corresponding characters + in another codeset. + ]], + license = "MIT/X11", + homepage = "http://luaforge.net/projects/lua-iconv/" +} + +dependencies = { + "lua >= 5.1", +} + +external_dependencies = { + ICONV = { + header = "iconv.h" + } +} + +build = { + type = "builtin", + modules = { + iconv = { + sources = {"luaiconv.c"}, + incdirs = {"$(ICONV_INCDIR)"}, + libdirs = {"$(ICONV_LIBDIR)"} + } + }, + platforms = { + cygwin = { + modules = { + iconv = { + libraries = {"iconv"} + } + } + } + } +} diff --git a/lua-iconv-7-1.rockspec b/rockspecs/lua-iconv-7-1.rockspec similarity index 95% rename from lua-iconv-7-1.rockspec rename to rockspecs/lua-iconv-7-1.rockspec index 9555cb5..4a1f57e 100644 --- a/lua-iconv-7-1.rockspec +++ b/rockspecs/lua-iconv-7-1.rockspec @@ -18,7 +18,7 @@ description = { in another codeset. ]], license = "MIT/X11", - homepage = "http://ittner.github.com/lua-iconv/" + homepage = "https://github.com/ittner/lua-iconv/" } dependencies = { diff --git a/rockspecs/lua-iconv-7.0.0-2.rockspec b/rockspecs/lua-iconv-7.0.0-2.rockspec new file mode 100644 index 0000000..3956a4f --- /dev/null +++ b/rockspecs/lua-iconv-7.0.0-2.rockspec @@ -0,0 +1,51 @@ + +-- Packs lua-iconv into a LuaRock +-- rockspec based uppon the file provided by DarkGod + +package = "lua-iconv" +version = "7.0.0-2" + +source = { + url = "https://github.com/lunarmodules/lua-iconv/archive/v7.0.0/lua-iconv-7.0.0.tar.gz", +} + +description = { + summary = "Lua binding to the iconv", + detailed = [[ + Lua binding to the POSIX 'iconv' library, which converts a sequence of + characters from one codeset into a sequence of corresponding characters + in another codeset. + ]], + license = "MIT/X11", + homepage = "https://github.com/lunarmodules/lua-iconv/" +} + +dependencies = { + "lua >= 5.1", +} + +external_dependencies = { + ICONV = { + header = "iconv.h" + } +} + +build = { + type = "builtin", + modules = { + iconv = { + sources = {"luaiconv.c"}, + incdirs = {"$(ICONV_INCDIR)"}, + libdirs = {"$(ICONV_LIBDIR)"} + } + }, + platforms = { + cygwin = { + modules = { + iconv = { + libraries = {"iconv"} + } + } + } + } +} diff --git a/test_iconv.lua b/test_iconv.lua index a0fa097..b38e22f 100644 --- a/test_iconv.lua +++ b/test_iconv.lua @@ -76,7 +76,7 @@ local ebcdic = "\193\150\64\147\150\149\135\133\107\64\129\150\64\147\164\129" .. "\37" -function check_one(to, from, text) +local function check_one(to, from, text) print("\n-- Testing conversion from " .. from .. " to " .. to) local cd = iconv.new(to .. "//TRANSLIT", from) assert(cd, "Failed to create a converter object.") @@ -102,23 +102,24 @@ check_one(termcs, "EBCDIC-CP-ES", ebcdic) -- The library must never crash the interpreter, even if the user tweaks -- with the garbage collector methods. -local cd = iconv.new("iso-8859-1", "utf-8") -local _, e = cd:iconv("atenção") +local _, e, cd, s, gc +cd = iconv.new("iso-8859-1", "utf-8") +_, e = cd:iconv("atenção") assert(e == nil, "Unexpected conversion error") -local gc = getmetatable(cd).__gc +gc = getmetatable(cd).__gc gc(cd) -local _, e = cd:iconv("atenção") +_, e = cd:iconv("atenção") assert(e == iconv.ERROR_FINALIZED, "Failed to detect double-freed objects") gc(cd) -- Test expected return values -local cd = iconv.new("ascii", "utf-8") -local _, e = cd:iconv("atenção") +cd = iconv.new("ascii", "utf-8") +_, e = cd:iconv("atenção") assert(e == iconv.ERROR_INVALID, "Unexpected return value for invalid conversion") -local cd = iconv.new("iso-8859-1", "utf-8") -local s, e = cd:iconv("atenção") +cd = iconv.new("iso-8859-1", "utf-8") +s, e = cd:iconv("atenção") assert(s == "aten\231\227o", "Unexpected result for valid conversion") assert(e == nil, "Unexpected return value for valid conversion")