Compare commits

..

83 Commits

Author SHA1 Message Date
Egor
3c729ec869
fix: lua export (#19)
* fix: lua export
2025-01-19 19:12:55 +01:00
paulobaggio
5452834c16
fix: lua-iconv test at Rockylinux 9 fail using lua 5.1 version (#15) 2024-11-13 21:31:59 +01:00
Thijs Schreijer
dbdd9d9ab8 release 7.1.0
Updates the dev rockspec to pin to a tag, such that new rockspecs
generated from it will not point to `master` but to the version
tag.
2023-10-30 15:56:22 +01:00
Thijs Schreijer
9eced53a8d fix(open): return an error on open/new
The method would not return an error message, now it does,
typically if a conversion is not supported.
2023-10-30 14:49:22 +01:00
Thijs Schreijer
1e6d024dc2 chore(dev): add a 'dev' rockspec to build from the source tree 2023-10-30 14:49:22 +01:00
Alexey Melnichuk
11545d0533
fix: Enable compiling with MSVC (#4) 2023-10-17 08:54:21 +03:00
Caleb Maclennan
9e865ff345
Bump rockrel high enough luarocks considers v7.0.0 newer than v7 2023-10-17 08:39:15 +03:00
Caleb Maclennan
8e19fde5f3
Use source URL format such that LuaRocks can infer source.dir from source.url 2023-10-07 22:23:34 +03:00
Matthieu Coudron
e4d200c102
Merge pull request #11 from lunarmodules/fix-rockspec 2023-10-07 20:57:28 +02:00
Matthieu Coudron
ba4f3a4518 build: added 6.1 rockspec 2023-10-07 14:52:13 +02:00
Matthieu Coudron
ac7f962b31 fix rockspec url 2023-10-07 00:41:15 +02:00
Caleb Maclennan
80e3266ced
Merge pull request #9 from lunarmodules/retool 2023-10-07 00:42:33 +03:00
Caleb Maclennan
51c1d732ed
chore: Fix lint issues, mostly with proper variable scopes 2023-10-05 20:48:51 +03:00
Caleb Maclennan
939fc2901b
docs: Format README as Markdown 2023-10-04 23:41:10 +03:00
Caleb Maclennan
c2ee26e1ef
ci: Add lunarmodules lint, test, and deploy workflows 2023-10-04 23:33:53 +03:00
Jonathan Ringer
b761918588
Update ittner homepage 2021-12-28 11:12:49 -08:00
Alexandre Erwin Ittner
2205a0fe27 Some code style changes and typo fixes 2013-10-23 00:12:24 -02:00
Alexandre Erwin Ittner
d41e0d345d Optimize memory handling in conversion function
Handling memory in this function is almost a Catch-22 between too many
mallocs and frees fragmenting memory in systems with bad allocators and
string concatenations abusing the Lua garbage collector. To avoid this,
now it uses a static buffer in the stack and a luaL_Buffer to handle
the concatenations. This remove all direct calls to memory allocators
from the library and lets Lua use its own.
2013-10-23 00:08:28 -02:00
Alexandre Erwin Ittner
49eb7b534f Add two new test cases 2012-05-22 00:58:48 -03:00
Alexandre Erwin Ittner
6f265ded5d Fix invalid error report
cd:iconv returned an invalid ERROR_UNKNOW code instead of 'nil' on
successful conversions. This usually passes unnoticed since the return
string is what the user actually expects.
2012-05-22 00:39:41 -03:00
Alexandre Erwin Ittner
1876a6de19 Add revision number to the rockspec
Thanks Hisham.
2012-05-20 23:24:48 -03:00
Alexandre Erwin Ittner
e8d34024a6 Update tarball checksum 2012-05-06 23:27:38 -03:00
Alexandre Erwin Ittner
6eb316bccc Update download URL in the README 2012-05-06 23:10:36 -03:00
Alexandre Erwin Ittner
411ac9fe72 Update rockspec 2012-05-06 22:59:17 -03:00
Alexandre Erwin Ittner
8bf1e80355 Update package information for version 7 and Lua 5.2 2012-05-06 22:47:54 -03:00
Alexandre Erwin Ittner
1fc031875f Make the library comptible with both Lua 5.1 and Lua 5.2 2011-12-05 19:40:34 -02:00
Alexandre Erwin Ittner
044877f838 Replace deprecated 'luaL_reg' by 'luaL_Reg'
'luaL_reg' was deprecated in Lua 5.1; Ensures that this version is
free of deprecated constructions.
2010-11-20 10:41:47 -02:00
Alexandre Erwin Ittner
32c7b20967 Merge branch 'fix-double-free'
Conflicts:
	luaiconv.c
2010-11-18 16:06:45 -02:00
Alexandre Erwin Ittner
6b46ea5706 Prevent crashes with double-freed conversion descriptors
It was possible to crash the interpreter by forcefully calling the
__gc metamethod twice. This commit fixes the bug.
2010-11-18 16:03:08 -02:00
Alexandre Erwin Ittner
44af7c2835 Put the switch 'omit-frame-pointer' in the right place 2010-11-17 19:32:54 -02:00
Alexandre Erwin Ittner
266da128c5 Get the installation path from package.cpath instead of pkg-config
This commit ensures some portability, since INSTALL_CMOD is no longer
present in the .pc files generated from 'make pc' in Lua 5.2.0
2010-11-17 14:39:15 -02:00
Alexandre Erwin Ittner
30fdc3c192 Fix order of arguments in 'open'
Since they were wrong in two places, there is no API changes, just a
readability fix.
2010-11-17 12:43:33 -02:00
Alexandre Erwin Ittner
e9f3a5e377 Make module usage cleaner, removing all global symbols
The 'module' function was also deprecated in Lua 5.2.0.
2010-11-17 12:37:49 -02:00
Alexandre Erwin Ittner
0879d77e1a Some cosmetic changes to improve the code readability 2010-11-17 10:13:58 -02:00
Alexandre Erwin Ittner
1cbd622cef Update Makefile
Currently, Lua 5.2.0-alpha do not provides a pkg-config file. I hope it
will change in the final release, so we have an automated Makefile for
free.
2010-11-17 01:57:40 -02:00
Alexandre Erwin Ittner
1a183d84c2 Put the conversion buffer size in a macro 2010-11-17 01:44:41 -02:00
Alexandre Erwin Ittner
ff90f3f75e Convert library to Lua 5.2
Lua 5.2 brings some API changes; This commit converts the library to
the new version and removes the backward compatibility code between
Lua 5.0 and 5.1 (which makes no sense anymore).
2010-11-17 01:28:02 -02:00
Alexandre Erwin Ittner
e394f70df0 Replace call to luaL_typerror with a custom error message
The function luaL_typerror was removed from public API in Lua 5.2. This
commit replaces it with calls to luaL_argerror and a custom error
message.
2010-11-16 23:45:44 -02:00
Alexandre Erwin Ittner
fc22d5b632 Put all macros in uppercase 2010-11-16 23:36:24 -02:00
Alexandre Erwin Ittner
9511e04e61 Update build instructions and formatting of the API section 2010-09-05 23:38:41 -03:00
Alexandre Erwin Ittner
a80bed8045 Update project URL 2010-09-05 22:25:37 -03:00
Alexandre Erwin Ittner
a9b6a899a4 Update README
Put some small changes to style, typo fixes, and better organization.
2010-09-05 19:58:50 -03:00
Alexandre Erwin Ittner
f80402c452 Update email address 2010-09-05 13:58:36 -03:00
Alexandre Erwin Ittner
a46edb3206 Merge branch 'debian-packages-r6' 2010-08-17 06:03:23 -03:00
Alexandre Erwin Ittner
f5ece25447 Put Debian package information into the final tarball 2010-08-17 05:55:34 -03:00
Alexandre Erwin Ittner
eb15cbb43f Fix Debian package with patch from http://packages.debian.org/
Recreating debian directory according to a patch provided in
http://ftp.de.debian.org/debian/pool/main/l/lua-iconv/lua-iconv_6-3.diff.gz
2010-08-17 05:48:15 -03:00
Alexandre Erwin Ittner
80bfe373a3 Repository converted to Git
Adding ignore file and removing revision tags.
2010-02-19 20:40:44 -02:00
Alexandre Erwin Ittner
adb92aeec2 Release 6
git-svn-id: file:///var/svn/lua-iconv/tags/r6@69 9538949d-8f27-0410-946f-ce01ef448559
2009-08-06 16:46:31 +00:00
Alexandre Erwin Ittner
2d7dd61c4b Updating rock
git-svn-id: file:///var/svn/lua-iconv/trunk@68 9538949d-8f27-0410-946f-ce01ef448559
2009-08-06 16:45:10 +00:00
Alexandre Erwin Ittner
5fdb4e6ebe Fixing makefile and version bump
git-svn-id: file:///var/svn/lua-iconv/trunk@65 9538949d-8f27-0410-946f-ce01ef448559
2009-08-06 16:30:06 +00:00
Alexandre Erwin Ittner
746bd38b96 Updating rockspec
git-svn-id: file:///var/svn/lua-iconv/trunk@64 9538949d-8f27-0410-946f-ce01ef448559
2009-08-03 22:01:49 +00:00
Alexandre Erwin Ittner
f250397346 Changing versioning scheme to avoid problems with Debian packages
git-svn-id: file:///var/svn/lua-iconv/trunk@62 9538949d-8f27-0410-946f-ce01ef448559
2009-08-03 21:43:21 +00:00
Alexandre Erwin Ittner
8631b8453e Adding patch by David Manura and Hisham
git-svn-id: file:///var/svn/lua-iconv/trunk@61 9538949d-8f27-0410-946f-ce01ef448559
2008-09-03 23:04:00 +00:00
Alexandre Erwin Ittner
5f448d6ed1 Updating rockspeck. Thanks Amadeu A. Barbosa Jr
git-svn-id: file:///var/svn/lua-iconv/trunk@59 9538949d-8f27-0410-946f-ce01ef448559
2008-08-31 02:08:33 +00:00
Alexandre Erwin Ittner
a918b0109a Adding sample Unicode I/O library
git-svn-id: file:///var/svn/lua-iconv/trunk@58 9538949d-8f27-0410-946f-ce01ef448559
2008-06-08 16:31:47 +00:00
Alexandre Erwin Ittner
1e2ee8d113 Fixing file url
git-svn-id: file:///var/svn/lua-iconv/trunk@56 9538949d-8f27-0410-946f-ce01ef448559
2008-05-19 00:48:13 +00:00
Alexandre Erwin Ittner
e126253925 Changing reference to version number
git-svn-id: file:///var/svn/lua-iconv/trunk@55 9538949d-8f27-0410-946f-ce01ef448559
2008-05-19 00:39:27 +00:00
Alexandre Erwin Ittner
9fba6938b2 Version r5. Fixes a bad linking option that makes lua-iconv unstable when used across different virtual machines
git-svn-id: file:///var/svn/lua-iconv/trunk@54 9538949d-8f27-0410-946f-ce01ef448559
2008-05-19 00:37:56 +00:00
Alexandre Erwin Ittner
bb7c2ad7e6 Fixing a bad linking to Lua core libs in the makefile
git-svn-id: file:///var/svn/lua-iconv/trunk@53 9538949d-8f27-0410-946f-ce01ef448559
2008-05-19 00:31:13 +00:00
Alexandre Erwin Ittner
893cb11189 Fixing paths in rockspec
git-svn-id: file:///var/svn/lua-iconv/trunk@51 9538949d-8f27-0410-946f-ce01ef448559
2008-05-17 03:54:34 +00:00
Alexandre Erwin Ittner
424a37d206 Removing buggy debian package specs for now
git-svn-id: file:///var/svn/lua-iconv/trunk@49 9538949d-8f27-0410-946f-ce01ef448559
2008-05-17 03:40:50 +00:00
Alexandre Erwin Ittner
8e31748caa E-mail changes
git-svn-id: file:///var/svn/lua-iconv/trunk@48 9538949d-8f27-0410-946f-ce01ef448559
2008-05-11 15:27:11 +00:00
Alexandre Erwin Ittner
60ea9d756d Fixing install rule
git-svn-id: file:///var/svn/lua-iconv/trunk@47 9538949d-8f27-0410-946f-ce01ef448559
2008-05-11 15:12:05 +00:00
Alexandre Erwin Ittner
f4bd6bed27 Adding rockspec
git-svn-id: file:///var/svn/lua-iconv/trunk@46 9538949d-8f27-0410-946f-ce01ef448559
2008-05-11 15:01:11 +00:00
Alexandre Erwin Ittner
49ea4854ff Changing e-mail address
git-svn-id: file:///var/svn/lua-iconv/trunk@45 9538949d-8f27-0410-946f-ce01ef448559
2008-05-11 14:15:54 +00:00
Alexandre Erwin Ittner
26d609d7be Makefile improvements
git-svn-id: file:///var/svn/lua-iconv/trunk@44 9538949d-8f27-0410-946f-ce01ef448559
2008-05-11 14:15:40 +00:00
Alexandre Erwin Ittner
cb9c689d48 Fixing according to a mail from Enrico Tassi.
git-svn-id: file:///var/svn/lua-iconv/trunk@43 9538949d-8f27-0410-946f-ce01ef448559
2007-04-24 01:14:29 +00:00
Alexandre Erwin Ittner
a4a7dd739a Some fixes. Debian packeges still not working.
git-svn-id: file:///var/svn/lua-iconv/trunk@42 9538949d-8f27-0410-946f-ce01ef448559
2007-04-22 18:06:06 +00:00
Alexandre Erwin Ittner
b9b790cee8 Adding Debian files in the tarball.
git-svn-id: file:///var/svn/lua-iconv/trunk@41 9538949d-8f27-0410-946f-ce01ef448559
2007-02-23 02:50:40 +00:00
Alexandre Erwin Ittner
5e3148e4bc r4
git-svn-id: file:///var/svn/lua-iconv/trunk@40 9538949d-8f27-0410-946f-ce01ef448559
2007-02-22 22:33:08 +00:00
Alexandre Erwin Ittner
4909aa5f80 Changes to fix Debian packaging.
git-svn-id: file:///var/svn/lua-iconv/trunk@39 9538949d-8f27-0410-946f-ce01ef448559
2007-02-22 22:32:11 +00:00
Alexandre Erwin Ittner
b5b90d436c Making Deb packages acording to the Debian Lua Policy
git-svn-id: file:///var/svn/lua-iconv/trunk@38 9538949d-8f27-0410-946f-ce01ef448559
2007-02-22 02:41:13 +00:00
Alexandre Erwin Ittner
bccfc233fe Better indentation.
git-svn-id: file:///var/svn/lua-iconv/trunk@37 9538949d-8f27-0410-946f-ce01ef448559
2007-02-08 23:46:58 +00:00
Alexandre Erwin Ittner
533727d3b9 Fixes for Debian
git-svn-id: file:///var/svn/lua-iconv/trunk@34 9538949d-8f27-0410-946f-ce01ef448559
2007-02-08 01:43:01 +00:00
Alexandre Erwin Ittner
2d5eba1ba5 Some updates for r3
git-svn-id: file:///var/svn/lua-iconv/trunk@33 9538949d-8f27-0410-946f-ce01ef448559
2007-02-08 00:49:58 +00:00
Alexandre Erwin Ittner
48ca55c30f Control directory for Debian packages.
git-svn-id: file:///var/svn/lua-iconv/trunk@32 9538949d-8f27-0410-946f-ce01ef448559
2007-02-07 22:21:41 +00:00
Alexandre Erwin Ittner
4db2fdaa3f Moving Luaforge site to a better place.
git-svn-id: file:///var/svn/lua-iconv/trunk@31 9538949d-8f27-0410-946f-ce01ef448559
2007-02-07 22:01:28 +00:00
Alexandre Erwin Ittner
9d904bf09f ...
git-svn-id: file:///var/svn/lua-iconv/trunk@29 9538949d-8f27-0410-946f-ce01ef448559
2006-04-21 17:58:08 +00:00
Alexandre Erwin Ittner
32537eb4c5 ...
git-svn-id: file:///var/svn/lua-iconv/trunk@28 9538949d-8f27-0410-946f-ce01ef448559
2006-04-21 17:57:25 +00:00
Alexandre Erwin Ittner
6c16cc18f7 ...
git-svn-id: file:///var/svn/lua-iconv/trunk@27 9538949d-8f27-0410-946f-ce01ef448559
2006-04-21 15:14:20 +00:00
Alexandre Erwin Ittner
ec5bf22d3a Updating for Lua 5.1
git-svn-id: file:///var/svn/lua-iconv/trunk@26 9538949d-8f27-0410-946f-ce01ef448559
2006-04-21 14:34:44 +00:00
Alexandre Erwin Ittner
4ed127ac23 *** empty log message ***
git-svn-id: file:///var/svn/lua-iconv/trunk@25 9538949d-8f27-0410-946f-ce01ef448559
2005-09-18 22:05:12 +00:00
Alexandre Erwin Ittner
b543d39e67 *** empty log message ***
git-svn-id: file:///var/svn/lua-iconv/trunk@24 9538949d-8f27-0410-946f-ce01ef448559
2005-09-18 21:55:52 +00:00
30 changed files with 1090 additions and 444 deletions

34
.github/workflows/deploy.yml vendored Normal file
View File

@ -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 }}

13
.github/workflows/luacheck.yml vendored Normal file
View File

@ -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

4
.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
*.lo
*.o
*.so
*.tar.gz

13
CHANGELOG.md Normal file
View File

@ -0,0 +1,13 @@
# Changelog
### 7.1.0 released 30-Oct-2023
* fix: rockspecs for MacOS
* feat: `iconv.new` now returns a second value in case of errors
---
### 7.0.0 released 17-Oct-2023
* First release from its new Lunar Modules home

View File

@ -1,4 +1,4 @@
Lua-iconv is (c) 2005 Alexandre Erwin Ittner <aittner@netuno.com.br> Lua-iconv is (c) 2005-10 Alexandre Erwin Ittner <alexandre@ittner.com.br>
Lua-iconv is copyrighted free software: it can be used for both academic Lua-iconv is copyrighted free software: it can be used for both academic
and commercial purposes at absolutely no cost. There are no royalties and commercial purposes at absolutely no cost. There are no royalties

View File

@ -1,5 +1,5 @@
# luaiconv - Performs character set conversions in Lua # luaiconv - Performs character set conversions in Lua
# (c) 2005 Alexandre Erwin Ittner <aittner@netuno.com.br> # (c) 2005-10 Alexandre Erwin Ittner <alexandre@ittner.com.br>
# #
# Permission is hereby granted, free of charge, to any person obtaining # Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the # a copy of this software and associated documentation files (the
@ -23,24 +23,50 @@
# If you use this package in a product, an acknowledgment in the product # If you use this package in a product, an acknowledgment in the product
# documentation would be greatly appreciated (but it is not required). # documentation would be greatly appreciated (but it is not required).
#CC = gcc
#RM = rm
CC=gcc # Gives a nice speedup, but also spoils debugging on x86. Comment out this
OUTFILE=libluaiconv.so # line when debugging.
CFLAGS=-Wall OMIT_FRAME_PTR = -fomit-frame-pointer
LFLAGS=-shared -llua
#WLFLAGS=-liconv LUABIN = lua
LUAPKG = lua5.2
CFLAGS = `pkg-config $(LUAPKG) --cflags` -fPIC -O3 -Wall $(OMIT_FRAME_PTR)
LFLAGS = -shared
INSTALL_PATH = `$(LUABIN) -e' \
for dir in package.cpath:gmatch("(/[^?;]+)?") do \
io.write(dir) \
os.exit(0) \
end \
os.exit(1) \
'`
## If your system doesn't have pkg-config or if you do not want to get the
## install path from Lua, comment out the previous lines and uncomment and
## change the following ones according to your building environment.
#CFLAGS = -I/usr/local/include/ -fPIC -O3 -Wall $(OMIT_FRAME_PTR)
#LFLAGS = -shared
#INSTALL_PATH = /usr/local/lib/lua/5.2/
all: $(OUTFILE) all: iconv.so
$(OUTFILE): luaiconv.c iconv.lo: luaiconv.c
$(CC) -o $(OUTFILE) $(CFLAGS) $(LFLAGS) $(WLFLAGS) luaiconv.c $(CC) -o iconv.lo -c $(CFLAGS) luaiconv.c
install: $(OUTFILE) iconv.so: iconv.lo
cp $(OUTFILE) /usr/lib/ $(CC) -o iconv.so $(LFLAGS) $(LIBS) iconv.lo
install51: $(OUTFILE) install: iconv.so
lua install51.lua $(OUTFILE) iconv make test
install -D -s iconv.so $(DESTDIR)/$(INSTALL_PATH)/iconv.so
clean: clean:
rm -f $(OUTFILE) *.o $(RM) iconv.so iconv.lo
test: iconv.so test_iconv.lua
$(LUABIN) test_iconv.lua

135
README
View File

@ -1,135 +0,0 @@
Lua-iconv: performs character set conversions in Lua
(c) 2005 Alexandre Erwin Ittner <aittner@netuno.com.br>
Project page: http://lua-iconv.luaforge.net/
=== INTRODUCTION ===
Lua-iconv is a Lua binding to the POSIX 'iconv' library. 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.
Details regarding iconv may be obtained from:
http://www.opengroup.org/onlinepubs/007908799/xsh/iconv.h.html
=== LICENSE ===
Lua-iconv is (c) 2005 Alexandre Erwin Ittner <aittner@netuno.com.br>
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:
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).
=== DOWNLOAD AND INSTALLATION ===
Lua-iconv can be obtained from its Luaforge project page:
http://lua-iconv.luaforge.net/
Lua-iconv must be compiled as a shared object and loaded by the Lua
interpreter using the 'loadlib' facility (or the new module system in
Lua 5.1). To compile the library, just fire up your favourite shell, untar
the distribution package and type, as root, within the program directory:
make install
The library will be compiled and installed on the /usr/lib/ directory.
To install the library with Lua 5.1 and above just type
make install51
This will cause the Makefile to run a Lua script that will install the
library into a directory from package.cpath, allowing you to use the
package system to load the library.
=== LOADING AND INITIALIZATION ===
Lua-iconv is a shared library that exports a single function called
luaopen_iconv that must be called by the Lua interpreter. You must
use loadlib function to for that. Using Lua 5.0, under Unix and with
libluaiconv.so on your LUA_PATH (or also your LD_PATH) you can just do:
assert(loadlib("libluaiconv.so", "luaopen_iconv"))()
And, under Windows and with libluaiconv.dll on your path, you can do
assert(loadlib("libluaiconv.dll", "luaopen_iconv"))()
On the Lua 5.1, Lua-iconv uses the new package system that allows you
to simply do a
require "gd"
call to load up the library (that was installed on the right place by
install51.lua).
=== USAGE ===
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 succeful.
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_UNKNOWN
There was an unknown error.

145
README.md Normal file
View File

@ -0,0 +1,145 @@
# Lua-iconv
Perform character set conversions in Lua
(c) 2005-11 Alexandre Erwin Ittner <alexandre@ittner.com.br>
## 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, err = iconv.new(to, from)
cd, err = 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.
The error code, may have any of the following values:
* `nil`
No error. Creation was successful.
* `iconv.ERROR_INVALID`
The conversion from `from` to `to` is not supported by the implementation.
* `iconv.ERROR_UNKNOWN`
There was an unknown error.
This function returns a new converter or nil+err 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).

28
debian/changelog vendored Normal file
View File

@ -0,0 +1,28 @@
lua-iconv (7-1) unstable; urgency=low
* Update package for lua-iconv 7 + Lua-5.2
-- Alexandre Erwin Ittner <alexandre@ittner.com.br> Sun, 06 May 2012 22:35:22 -0300
lua-iconv (6-3) unstable; urgency=low
* debian/control: Conflicts, Provides, and Replaces lua-iconv
(Closes: #557052)
-- Jon Bernard <jbernard@debian.org> Fri, 20 Nov 2009 18:58:12 -0600
lua-iconv (6-2) unstable; urgency=low
* debian/control: update package name to conform to lua standard
(Closes: #544958)
* debian/control: add Vcs fields
* debian/control: update package description
* debian/watch: look for new upstream releases on luaforge (Closes: #544960)
-- Jon Bernard <jbernard@debian.org> Wed, 28 Oct 2009 11:58:00 -0400
lua-iconv (6-1) unstable; urgency=low
* Initial release (Closes: #540298)
-- Jon Bernard <jbernard@debian.org> Sun, 02 Aug 2009 13:50:50 -0400

1
debian/compat vendored Normal file
View File

@ -0,0 +1 @@
7

21
debian/control vendored Normal file
View File

@ -0,0 +1,21 @@
Source: lua-iconv
Section: interpreters
Priority: optional
Maintainer: Jon Bernard <jbernard@debian.org>
Build-Depends: debhelper (>= 7), liblua5.2-dev, lua5.2, pkg-config
Standards-Version: 3.8.2
Vcs-Git: https://github.com/ittner/lua-iconv.git
Vcs-Browser: https://github.com/ittner/lua-iconv.git
Homepage: http://ittner.github.com/lua-iconv/
Package: liblua5.2-iconv0
Architecture: any
Depends: ${shlibs:Depends}, ${misc:Depends}
Recommends: lua5.2
Conflicts: lua-iconv
Provides: lua-iconv
Replaces: lua-iconv
Description: iconv bindings for the Lua programming language
This package provides POSIX 'iconv' bindings for the Lua programming language.
It converts a sequence of characters from one codeset into a sequence of
corresponding characters in another codeset.

42
debian/copyright vendored Normal file
View File

@ -0,0 +1,42 @@
This package was debianized by Jon Bernard <jbernard@debian.org> on
Sun, 02 Aug 2009 13:50:50 -0400.
It was downloaded from http://luaforge.net/frs/?group_id=131&release_id=1440
Upstream Author:
Alexandre Erwin Ittner <alexandre@ittner.com.br>
Copyright:
Copyright (C) 2005-09 Alexandre Erwin Ittner
License:
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).
The Debian packaging is:
Copyright (C) 2009 Jon Bernard <jbernard@debian.org>
and is licensed under the GPL version 3,
see `/usr/share/common-licenses/GPL-3'.

1
debian/docs vendored Normal file
View File

@ -0,0 +1 @@
README

1
debian/examples vendored Normal file
View File

@ -0,0 +1 @@
test_iconv.lua

3
debian/rules vendored Normal file
View File

@ -0,0 +1,3 @@
#!/usr/bin/make -f
%:
dh $@

16
fp.txt
View File

@ -1,16 +0,0 @@
Ao longe, ao luar
No rio uma vela
Serena a passar,
Que é que me revela
Não sei, mas mue ser
Tornou-se-me estranho,
E eu sonho sem ver
Os sonhos que tenho.
Que angústia me enlaça?
Que amor não se explica?
É a vela que passa
Na noite que fica
-- Fernando Pessoa

View File

@ -1,52 +0,0 @@
-- Common locations (add new ones if needed).
local locs = {
-- Unices
"libluaiconv.so",
"./libluaiconv.so",
"/usr/lib/libluaiconv.so",
"/usr/local/lib/libluaiconv.so",
"/usr/local/lib/lua/5.0/lib/libluaiconv.so",
-- Windows
"libluaiconv.dll",
"luaiconv.dll",
".\\luaiconv.dll",
".\\libluaiconv.dll",
"c:\\lua\\lib\\libluaiconv.dll"
}
local loadiconv, fname, ndx
for ndx, fname in ipairs(locs) do
loadiconv = loadlib(fname, "luaopen_iconv")
if loadiconv then
break
end
end
assert(loadiconv, "Can't load Lua-iconv")
loadiconv()
-- An useful extension: Detects automatically the charset of the string
-- and returns it on the chosen one.
iconv.commoncharsets = {
"ascii", "iso-8859-1", "utf-8", "utf-16", "windows-1252"
}
iconv.autoconvert = function(tocode, str)
local _, fromcode, cd, ret, err
for _, fromcode in pairs(iconv.commoncharsets) do
cd = iconv.new(tocode, fromcode)
ret, err = cd:iconv(str)
if not err then
return ret
end
end
return nil
end

View File

@ -1,92 +0,0 @@
#!/usr/bin/env lua
-- Easy way to put a library on the path. For Lua >= 5.1 only.
-- (c) 2005 Alexandre Erwin Ittner < aittner{at}netuno.com.br >
--
-- This file is distributed under the same license that Lua 5.1 itself.
--
-- $Id$
--
-- Splits a package.cpath into a table.
function splitpath(str)
local t = {}
local v
for v in string.gfind(str, "([^;]+);") do
table.insert(t, v)
end
return t
end
-- Checks if a given file exists. DUMB. Do not distinguish files from
-- symlinks, pipes, sockets, device drivers, etc.
function fileexists(fname)
local fp = io.open(fname, "r")
if fp then
fp:close()
return true
end
return false
end
-- Finds the first absolute path on the list. Works with *nix (MacOS X
-- included) and Windows paths.
function findplace(tbl)
local k, v
for k, v in ipairs(tbl) do
if v:sub(1, 1) == "/"
or v:sub(2, 3) == ":\\" then
return v
end
end
end
-- It's REALLY stupid, but also it's REALLY cross-platform.
function dumbcopy(from, to)
local bufsize = 512*1024 -- 512K at once
local ifp = io.open(from, "rb")
assert(ifp, "Can't open file for reading. File not found?")
local ofp = io.open(to, "wb")
assert(ofp, "Can't open file for writing. Permission denied?")
local buf
repeat
buf = ifp:read(bufsize)
if buf then
ofp:write(buf)
end
until not buf
ifp:close()
ofp:close()
end
-- Copies the file. 'to' MUST be an absolute path!
function copy(from, to)
if to:sub(1, 1) == "/" then -- Cool! We are on Unix, guys!
ret = os.execute('install -D "' .. from .. '" "' .. to .. '"')
if ret == 0 and fileexists(to) then
return
end
end
-- Let's try some violence.
dumbcopy(from, to)
end
-- Installs one file. Simple. Perfect.
function installfile(fname, name)
local tpath = splitpath(package.cpath)
local path = findplace(tpath)
assert(path, "Can't find a place to install")
local dest = path:gsub("%?", name)
print("Install:", dest)
copy(fname, dest)
end
assert(package, "No package module found. Are you REALLY using Lua >= 5.1?")
assert(arg[1] and arg[2], "No arguments provided")
installfile(arg[1], arg[2])
os.exit(0)

62
lua-iconv-dev-1.rockspec Normal file
View File

@ -0,0 +1,62 @@
local package_name = "lua-iconv"
local package_version = "dev"
local rockspec_revision = "1"
local github_account_name = "lunarmodules"
local github_repo_name = package_name
package = package_name
version = package_version.."-"..rockspec_revision
source = {
url = "git+https://github.com/"..github_account_name.."/"..github_repo_name..".git",
branch = (package_version == "dev") and "master" or nil,
tag = (package_version ~= "dev") and ("v" .. package_version) or nil,
}
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/"..github_account_name.."/"..github_repo_name,
}
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"}
}
}
},
macosx = {
modules = {
iconv = {
libraries = {"iconv"}
}
}
},
}
}

210
lua-iconv-logo.ps Normal file
View File

@ -0,0 +1,210 @@
%!PS-Adobe-2.0 EPSF-2.0
%%Title: Lua logo
%%Creator: lua@tecgraf.puc-rio.br
%%CreationDate: Wed Nov 29 19:04:04 EDT 2000
%%BoundingBox: -45 0 1035 1080
%%Pages: 1
%%EndComments
%%EndProlog
%------------------------------------------------------------------------------
%
% Copyright (C) 1998-2000. All rights reserved.
% Graphic design by Alexandre Nakonechnyj (nako@openlink.com.br).
% PostScript programming by the Lua team (lua@tecgraf.puc-rio.br).
%
% Permission is hereby granted, without written agreement and without license
% or royalty fees, to use, copy, and distribute this logo for any purpose,
% including commercial applications, subject to the following conditions:
%
% * The origin of this logo must not be misrepresented; you must not
% claim that you drew the original logo. We recommend that you give credit
% to the graphics designer in all printed matter that includes the logo.
%
% * The only modification you can make is to adapt the orbiting text to
% your product name.
%
% * The logo can be used in any scale as long as the relative proportions
% of its elements are maintained.
%
%------------------------------------------------------------------------------
/LABEL (iconv) def
%-- DO NOT CHANGE ANYTHING BELOW THIS LINE ------------------------------------
/PLANETCOLOR {0 0 0.5 setrgbcolor} bind def
/HOLECOLOR {1.0 setgray} bind def
/ORBITCOLOR {0.5 setgray} bind def
/LOGOFONT {/Helvetica 0.90} def
/LABELFONT {/Helvetica 0.36} def
%------------------------------------------------------------------------------
/MOONCOLOR {PLANETCOLOR} bind def
/LOGOCOLOR {HOLECOLOR} bind def
/LABELCOLOR {ORBITCOLOR} bind def
/LABELANGLE 125 def
/LOGO (Lua) def
/DASHANGLE 10 def
/HALFDASHANGLE DASHANGLE 2 div def
% moon radius. planet radius is 1.
/r 1 2 sqrt 2 div sub def
/D {0 360 arc fill} bind def
/F {exch findfont exch scalefont setfont} bind def
% place it nicely on the paper
/RESOLUTION 1024 def
RESOLUTION 2 div dup translate
RESOLUTION 2 div 2 sqrt div dup scale
%-------------------------------------------------------------------- planet --
PLANETCOLOR
0 0 1 D
%---------------------------------------------------------------------- hole --
HOLECOLOR
1 2 r mul sub dup r D
%---------------------------------------------------------------------- moon --
MOONCOLOR
1 1 r D
%---------------------------------------------------------------------- logo --
LOGOCOLOR
LOGOFONT
F
LOGO stringwidth pop 2 div neg
-0.5 moveto
LOGO show
%------------------------------------------------------------------------------
% based on code from Blue Book Program 10, on pages 167--169
% available at ftp://ftp.adobe.com/pub/adobe/displaypostscript/bluebook.shar
% str ptsize centerangle radius outsidecircletext --
/outsidecircletext {
circtextdict begin
/radius exch def
/centerangle exch def
/ptsize exch def
/str exch def
gsave
str radius ptsize findhalfangle
centerangle
add rotate
str
{ /charcode exch def
( ) dup 0 charcode put outsideplacechar
} forall
grestore
end
} def
% string radius ptsize findhalfangle halfangle
/findhalfangle {
4 div add
exch
stringwidth pop 2 div
exch
2 mul 3.1415926535 mul div 360 mul
} def
/circtextdict 16 dict def
circtextdict begin
/outsideplacechar {
/char exch def
/halfangle char radius ptsize findhalfangle def
gsave
halfangle neg rotate
radius 0 translate
-90 rotate
char stringwidth pop 2 div neg 0 moveto
char show
grestore
halfangle 2 mul neg rotate
} def
end
%--------------------------------------------------------------------- label --
LABELFONT
F
/LABELSIZE LABELFONT exch pop def
/LABELRADIUS LABELSIZE 3 div 1 r add sub neg 1.02 mul def
/HALFANGLE
LABEL LABELRADIUS LABELSIZE findhalfangle
HALFDASHANGLE div ceiling HALFDASHANGLE mul
def
/LABELANGLE
60 LABELANGLE HALFANGLE sub
lt
{
HALFANGLE
HALFANGLE DASHANGLE div floor DASHANGLE mul
eq
{LABELANGLE DASHANGLE div ceiling DASHANGLE mul}
{LABELANGLE HALFDASHANGLE sub DASHANGLE div round DASHANGLE mul HALFDASHANGLE add}
ifelse
}
{HALFANGLE 60 add}
ifelse
def
LABELCOLOR
LABEL
LABELSIZE
LABELANGLE
LABELRADIUS
outsidecircletext
%--------------------------------------------------------------------- orbit --
ORBITCOLOR
0.03 setlinewidth
[1 r add 3.1415926535 180 div HALFDASHANGLE mul mul] 0 setdash
newpath
0 0
1 r add
3 copy
30
LABELANGLE HALFANGLE add
arcn
stroke
60
LABELANGLE HALFANGLE sub
2 copy
lt {arc stroke} {4 {pop} repeat} ifelse
%------------------------------------------------------------------ copyright --
/COPYRIGHT
(Graphic design by A. Nakonechnyj. Copyright (c) 1998, All rights reserved.)
def
LABELCOLOR
LOGOFONT
32 div
F
2 sqrt 0.99 mul
dup
neg
moveto
COPYRIGHT
90 rotate
%show
%---------------------------------------------------------------------- done --
showpage
%%Trailer
%%EOF

View File

@ -1,6 +1,6 @@
/* /*
* luaiconv - Performs character set conversions in Lua * luaiconv - Performs character set conversions in Lua
* (c) 2005 Alexandre Erwin Ittner <aittner@netuno.com.br> * (c) 2005-11 Alexandre Erwin Ittner <alexandre@ittner.com.br>
* *
* Permission is hereby granted, free of charge, to any person obtaining * Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the * a copy of this software and associated documentation files (the
@ -24,7 +24,6 @@
* If you use this package in a product, an acknowledgment in the product * If you use this package in a product, an acknowledgment in the product
* documentation would be greatly appreciated (but it is not required). * documentation would be greatly appreciated (but it is not required).
* *
* $Id$
* *
*/ */
@ -37,40 +36,46 @@
#include <errno.h> #include <errno.h>
#define LIB_NAME "iconv" #define LIB_NAME "iconv"
#define LIB_VERSION LIB_NAME " r1" #define LIB_VERSION LIB_NAME " 7"
#define ICONV_TYPENAME "iconv_t" #define ICONV_TYPENAME "iconv_t"
#ifdef _WIN32
/* Compatibility between Lua 5.1+ and Lua 5.0 */ #define LUAEXPORT __declspec(dllexport)
#ifndef LUA_VERSION_NUM #else
#define LUA_VERSION_NUM 0 #define LUAEXPORT __attribute__((visibility("default")))
#endif #endif
#if LUA_VERSION_NUM < 501 #if LUA_VERSION_NUM < 501
#define luaL_register(a, b, c) luaL_openlib((a), (b), (c), 0) #error "Unsupported Lua version. You must use Lua >= 5.1"
#endif
#if LUA_VERSION_NUM < 502
#define luaL_newlib(L, f) { lua_newtable(L); luaL_register(L, NULL, f); }
#define lua_rawlen(L, i) lua_objlen(L, i)
#endif #endif
/* Emulates lua_(un)boxpointer from Lua 5.0 (don't exists on Lua 5.1) */ #define BOXPTR(L, p) (*(void**)(lua_newuserdata(L, sizeof(void*))) = (p))
#define boxptr(L, p) (*(void**)(lua_newuserdata(L, sizeof(void*))) = (p)) #define UNBOXPTR(L, i) (*(void**)(lua_touserdata(L, i)))
#define unboxptr(L, i) (*(void**)(lua_touserdata(L, i)))
/* Table assumed on top */
#define tblseticons(L, c, v) \
lua_pushliteral(L, c); \
lua_pushnumber(L, v); \
lua_settable(L, -3);
/* Set a integer constant. Assumes a table in the top of the stack */
#define TBL_SET_INT_CONST(L, c) { \
lua_pushliteral(L, #c); \
lua_pushnumber(L, c); \
lua_settable(L, -3); \
}
#define ERROR_NO_MEMORY 1 #define ERROR_NO_MEMORY 1
#define ERROR_INVALID 2 #define ERROR_INVALID 2
#define ERROR_INCOMPLETE 3 #define ERROR_INCOMPLETE 3
#define ERROR_UNKNOWN 4 #define ERROR_UNKNOWN 4
#define ERROR_FINALIZED 5
static void push_iconv_t(lua_State *L, iconv_t cd) static void push_iconv_t(lua_State *L, iconv_t cd)
{ {
boxptr(L, cd); BOXPTR(L, cd);
luaL_getmetatable(L, ICONV_TYPENAME); luaL_getmetatable(L, ICONV_TYPENAME);
lua_setmetatable(L, -2); lua_setmetatable(L, -2);
} }
@ -78,14 +83,12 @@ static void push_iconv_t(lua_State *L, iconv_t cd)
static iconv_t get_iconv_t(lua_State *L, int i) static iconv_t get_iconv_t(lua_State *L, int i)
{ {
if(luaL_checkudata(L, i, ICONV_TYPENAME) != NULL) if (luaL_checkudata(L, i, ICONV_TYPENAME) != NULL) {
{ iconv_t cd = UNBOXPTR(L, i);
iconv_t cd = unboxptr(L, i); return cd; /* May be NULL. This must be checked by the caller. */
if(cd == (iconv_t) NULL)
luaL_error(L, "attempt to use an invalid " ICONV_TYPENAME);
return cd;
} }
luaL_typerror(L, i, ICONV_TYPENAME); luaL_argerror(L, i, lua_pushfstring(L, ICONV_TYPENAME " expected, got %s",
luaL_typename(L, i)));
return NULL; return NULL;
} }
@ -95,76 +98,73 @@ static int Liconv_open(lua_State *L)
const char *tocode = luaL_checkstring(L, 1); const char *tocode = luaL_checkstring(L, 1);
const char *fromcode = luaL_checkstring(L, 2); const char *fromcode = luaL_checkstring(L, 2);
iconv_t cd = iconv_open(tocode, fromcode); iconv_t cd = iconv_open(tocode, fromcode);
if(cd != (iconv_t)(-1)) if (cd != (iconv_t)(-1)) {
push_iconv_t(L, cd); /* ok */ push_iconv_t(L, cd); /* ok */
else return 1;
lua_pushnil(L); /* erro */ } else {
return 1; lua_pushnil(L); /* error */
if (errno == EINVAL)
lua_pushnumber(L, ERROR_INVALID);
else
lua_pushnumber(L, ERROR_UNKNOWN);
return 2;
};
} }
/* Use a fixed-size buffer in the stack to avoid a lot of small mallocs
* and prevent memory fragmentation. This should not be a problem in any
* contemporary general purpose system but, if you are running in a very
* limited stack system you may use a smaller buffer, but the luaL_Buffer
* will compensate this with more reallocs and memcpys.
*/
#define CONV_BUF_SIZE 256
static int Liconv(lua_State *L) static int Liconv(lua_State *L)
{ {
iconv_t cd = get_iconv_t(L, 1); iconv_t cd = get_iconv_t(L, 1);
size_t ibleft = lua_strlen(L, 2); size_t ibleft = lua_rawlen(L, 2);
char *inbuf = (char*) luaL_checkstring(L, 2); char *inbuf = (char*) luaL_checkstring(L, 2);
char *outbuf; char outbufs[CONV_BUF_SIZE];
char *outbufs; char *outbuf = outbufs;
size_t obsize = (ibleft > 256) ? ibleft : 256; size_t obleft = CONV_BUF_SIZE;
size_t obleft = obsize;
size_t ret = -1; size_t ret = -1;
int hasone = 0; luaL_Buffer b;
outbuf = (char*) malloc(obsize * sizeof(char)); if (cd == NULL) {
if(outbuf == NULL)
{
lua_pushstring(L, ""); lua_pushstring(L, "");
lua_pushnumber(L, ERROR_NO_MEMORY); lua_pushnumber(L, ERROR_FINALIZED);
return 2; return 2;
} }
outbufs = outbuf;
do luaL_buffinit(L, &b);
{
do {
ret = iconv(cd, &inbuf, &ibleft, &outbuf, &obleft); ret = iconv(cd, &inbuf, &ibleft, &outbuf, &obleft);
if(ret == (size_t)(-1)) if (ret == (size_t)(-1)) {
{ luaL_addlstring(&b, outbufs, CONV_BUF_SIZE - obleft);
lua_pushlstring(L, outbufs, obsize - obleft); if (errno == EILSEQ) {
if(hasone == 1) luaL_pushresult(&b);
lua_concat(L, 2);
hasone = 1;
if(errno == EILSEQ)
{
lua_pushnumber(L, ERROR_INVALID); lua_pushnumber(L, ERROR_INVALID);
free(outbufs);
return 2; /* Invalid character sequence */ return 2; /* Invalid character sequence */
} } else if (errno == EINVAL) {
else if(errno == EINVAL) luaL_pushresult(&b);
{
lua_pushnumber(L, ERROR_INCOMPLETE); lua_pushnumber(L, ERROR_INCOMPLETE);
free(outbufs);
return 2; /* Incomplete character sequence */ return 2; /* Incomplete character sequence */
} } else if (errno == E2BIG) {
else if(errno == E2BIG) obleft = CONV_BUF_SIZE;
{
obleft = obsize;
outbuf = outbufs; outbuf = outbufs;
} } else {
else luaL_pushresult(&b);
{
lua_pushnumber(L, ERROR_UNKNOWN); lua_pushnumber(L, ERROR_UNKNOWN);
free(outbufs);
return 2; /* Unknown error */ return 2; /* Unknown error */
} }
} }
} } while (ret == (size_t) -1);
while(ret != (size_t) 0);
lua_pushlstring(L, outbufs, obsize - obleft); luaL_addlstring(&b, outbufs, CONV_BUF_SIZE - obleft);
if(hasone == 1) luaL_pushresult(&b);
lua_concat(L, 2); lua_pushnil(L);
free(outbufs); return 2; /* Done */
return 1; /* Done */
} }
@ -179,8 +179,7 @@ static int push_one(unsigned int cnt, char *names[], void *data)
/* Stack: <tbl> n */ /* Stack: <tbl> n */
lua_remove(L, -1); lua_remove(L, -1);
for(i = 0; i < cnt; i++) for (i = 0; i < cnt; i++) {
{
/* Stack> <tbl> */ /* Stack> <tbl> */
lua_pushnumber(L, n++); lua_pushnumber(L, n++);
lua_pushstring(L, names[i]); lua_pushstring(L, names[i]);
@ -212,16 +211,20 @@ static int Liconvlist(lua_State *L)
static int Liconv_close(lua_State *L) static int Liconv_close(lua_State *L)
{ {
iconv_t cd = get_iconv_t(L, 1); iconv_t cd = get_iconv_t(L, 1);
if(iconv_close(cd) == 0) if (cd != NULL && iconv_close(cd) == 0) {
/* Mark the pointer as freed, preventing interpreter crashes
if the user forces __gc to be called twice. */
void **ptr = lua_touserdata(L, 1);
*ptr = NULL;
lua_pushboolean(L, 1); /* ok */ lua_pushboolean(L, 1); /* ok */
}
else else
lua_pushnil(L); /* erro */ lua_pushnil(L); /* error, called from __gc, so no need for error messsage */
return 1; return 1;
} }
static const luaL_reg inconvFuncs[] = static const luaL_Reg iconv_funcs[] = {
{
{ "open", Liconv_open }, { "open", Liconv_open },
{ "new", Liconv_open }, { "new", Liconv_open },
{ "iconv", Liconv }, { "iconv", Liconv },
@ -232,31 +235,30 @@ static const luaL_reg inconvFuncs[] =
}; };
static const luaL_reg iconvMT[] = LUAEXPORT int luaopen_iconv(lua_State *L)
{ {
{ "__gc", Liconv_close }, luaL_newlib(L, iconv_funcs);
{ NULL, NULL }
};
TBL_SET_INT_CONST(L, ERROR_NO_MEMORY);
int luaopen_iconv(lua_State *L) TBL_SET_INT_CONST(L, ERROR_INVALID);
{ TBL_SET_INT_CONST(L, ERROR_INCOMPLETE);
luaL_register(L, LIB_NAME, inconvFuncs); TBL_SET_INT_CONST(L, ERROR_FINALIZED);
TBL_SET_INT_CONST(L, ERROR_UNKNOWN);
tblseticons(L, "ERROR_NO_MEMORY", ERROR_NO_MEMORY);
tblseticons(L, "ERROR_INVALID", ERROR_INVALID);
tblseticons(L, "ERROR_INCOMPLETE", ERROR_INCOMPLETE);
tblseticons(L, "ERROR_UNKNOWN", ERROR_UNKNOWN);
lua_pushliteral(L, "VERSION"); lua_pushliteral(L, "VERSION");
lua_pushstring(L, LIB_VERSION); lua_pushstring(L, LIB_VERSION);
lua_settable(L, -3); lua_settable(L, -3);
luaL_newmetatable(L, ICONV_TYPENAME); luaL_newmetatable(L, ICONV_TYPENAME);
lua_pushliteral(L, "__index"); lua_pushliteral(L, "__index");
lua_pushvalue(L, -3); lua_pushvalue(L, -3);
lua_settable(L, -3); lua_settable(L, -3);
luaL_openlib(L, NULL, iconvMT, 0);
lua_pushliteral(L, "__gc");
lua_pushcfunction(L, Liconv_close);
lua_settable(L, -3);
lua_pop(L, 1); lua_pop(L, 1);
return 1; return 1;

View File

@ -3,12 +3,10 @@ local fp = assert(io.open(arg[1], "rb"))
local str = assert(fp:read("*a")) local str = assert(fp:read("*a"))
fp:close() fp:close()
local i local ostr = "local xxxxxxxxxxx = \""
local c = 0
local ostr = "local xxxxx = \""
for i = 1, string.len(str) do for i = 1, string.len(str) do
ostr = ostr .. "\\" .. string.byte(string.sub(str, i, i+1)) ostr = ostr .. "\\" .. string.byte(string.sub(str, i, i+1))
if string.len(ostr) > 74 then if string.len(ostr) > 72 then
io.write(ostr .. "\"\n") io.write(ostr .. "\"\n")
ostr = ".. \"" ostr = ".. \""
end end

View File

@ -1,7 +1,7 @@
#!/bin/sh #!/bin/sh
PACKAGE=lua-iconv PACKAGE=lua-iconv
VERSION=r1 VERSION=7
DIRNAME=$PACKAGE-$VERSION DIRNAME=$PACKAGE-$VERSION
TGZNAME=$DIRNAME.tar.gz TGZNAME=$DIRNAME.tar.gz
@ -9,9 +9,15 @@ TGZNAME=$DIRNAME.tar.gz
rm -f $TGZNAME rm -f $TGZNAME
mkdir $DIRNAME mkdir $DIRNAME
cp COPYING Makefile README luaiconv.c iconv.lua test_iconv.lua \ cp -r debian $DIRNAME/
install51.lua $DIRNAME #rm -rf $DIRNAME/debian/.svn
cp -r COPYING Makefile README luaiconv.c test_iconv.lua $DIRNAME
tar -czf $TGZNAME $DIRNAME tar -czf $TGZNAME $DIRNAME
#cd $DIRNAME dpkg-buildpackage -rfakeroot
#cd ..
rm -rf $DIRNAME rm -rf $DIRNAME
tar -tzf $TGZNAME tar -tzf $TGZNAME

View File

@ -0,0 +1,52 @@
-- Packs lua-iconv into a LuaRock
-- rockspec based uppon the file provided by DarkGod <darkgod at net-core.org>
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"}
}
}
}
}
}

View File

@ -0,0 +1,52 @@
-- Packs lua-iconv into a LuaRock
-- rockspec based uppon the file provided by DarkGod <darkgod at net-core.org>
package = "lua-iconv"
version = "7-1"
source = {
url = "https://github.com/downloads/ittner/lua-iconv/lua-iconv-7.tar.gz",
md5 = "8a38b4e6ac8a9290093898793d16fe4b"
}
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/ittner/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"}
}
}
}
}
}

View File

@ -0,0 +1,51 @@
-- Packs lua-iconv into a LuaRock
-- rockspec based uppon the file provided by DarkGod <darkgod at net-core.org>
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"}
}
}
}
}
}

View File

@ -0,0 +1,50 @@
-- Packs lua-iconv into a LuaRock
-- rockspec based uppon the file provided by DarkGod <darkgod at net-core.org>
package = "lua-iconv"
version = "7.0.0-4"
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"}
}
}
}
}
}

View File

@ -0,0 +1,62 @@
local package_name = "lua-iconv"
local package_version = "7.1.0"
local rockspec_revision = "1"
local github_account_name = "lunarmodules"
local github_repo_name = package_name
package = package_name
version = package_version.."-"..rockspec_revision
source = {
url = "git+https://github.com/"..github_account_name.."/"..github_repo_name..".git",
branch = (package_version == "dev") and "master" or nil,
tag = (package_version ~= "dev") and ("v" .. package_version) or nil,
}
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/"..github_account_name.."/"..github_repo_name,
}
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"}
}
}
},
macosx = {
modules = {
iconv = {
libraries = {"iconv"}
}
}
},
}
}

View File

@ -1,27 +1,25 @@
require "iconv" -- -*- coding: utf-8 -*-
local iconv = require("iconv")
-- Set your terminal encoding here -- Set your terminal encoding here
local termcs = "iso-8859-1" -- local termcs = "iso-8859-1"
local termcs = "utf-8"
local iso88591 = [[
Ao longe, ao luar
No rio uma vela
Serena a passar,
Que é que me revela
Não sei, mas mue ser
Tornou-se-me estranho,
E eu sonho sem ver
Os sonhos que tenho.
Que angústia me enlaça?
Que amor não se explica?
É a vela que passa
Na noite que fica
-- Fernando Pessoa]]
local iso88591 = "\65\111\32\108\111\110\103\101\44\32\97\111\32\108\117"
.. "\97\114\10\78\111\32\114\105\111\32\117\109\97\32\118\101\108\97\10\83"
.. "\101\114\101\110\97\32\97\32\112\97\115\115\97\114\44\10\81\117\101\32"
.. "\233\32\113\117\101\32\109\101\32\114\101\118\101\108\97\10\10\78\227"
.. "\111\32\115\101\105\44\32\109\97\115\32\109\117\101\32\115\101\114\10"
.. "\84\111\114\110\111\117\45\115\101\45\109\101\32\101\115\116\114\97\110"
.. "\104\111\44\10\69\32\101\117\32\115\111\110\104\111\32\115\101\109\32"
.. "\118\101\114\10\79\115\32\115\111\110\104\111\115\32\113\117\101\32\116"
.. "\101\110\104\111\46\10\10\81\117\101\32\97\110\103\250\115\116\105\97"
.. "\32\109\101\32\101\110\108\97\231\97\63\10\81\117\101\32\97\109\111\114"
.. "\32\110\227\111\32\115\101\32\101\120\112\108\105\99\97\63\10\201\32\97"
.. "\32\118\101\108\97\32\113\117\101\32\112\97\115\115\97\10\78\97\32\110"
.. "\111\105\116\101\32\113\117\101\32\102\105\99\97\10\10\32\32\32\32\45"
.. "\45\32\70\101\114\110\97\110\100\111\32\80\101\115\115\111\97\10"
local utf8 = "\65\111\32\108\111\110\103\101\44\32\97\111\32\108\117\97\114" local utf8 = "\65\111\32\108\111\110\103\101\44\32\97\111\32\108\117\97\114"
.. "\10\78\111\32\114\105\111\32\117\109\97\32\118\101\108\97\10\83\101\114" .. "\10\78\111\32\114\105\111\32\117\109\97\32\118\101\108\97\10\83\101\114"
@ -78,25 +76,31 @@ local ebcdic = "\193\150\64\147\150\149\135\133\107\64\129\150\64\147\164\129"
.. "\37" .. "\37"
function check_one(to, from, text) local function ErrMsg(errno)
print("\n-- Testing conversion from " .. from .. " to " .. to) if errno == iconv.ERROR_INCOMPLETE then
local cd = iconv.new(to .. "//TRANSLIT", from) return "Incomplete input."
if not cd then elseif errno == iconv.ERROR_INVALID then
printf("FAILED!") return "Invalid input."
return elseif errno == iconv.ERROR_NO_MEMORY then
return "Failed to allocate memory."
elseif errno == iconv.ERROR_UNKNOWN then
return "There was an unknown error."
elseif errno == iconv.FINALIZED then
return "Handle was already finalized."
end end
return "Unknown error: "..tostring(errno)
end
local function check_one(to, from, text)
print("\n-- Testing conversion from " .. from .. " to " .. to)
local cd, errno = iconv.new(to .. "//TRANSLIT", from)
assert(cd, "Failed to create a converter object: " .. ErrMsg(errno))
local ostr, err = cd:iconv(text) local ostr, err = cd:iconv(text)
if err == iconv.ERROR_INCOMPLETE then if err then
print("ERROR: Incomplete input.") print("ERROR: " .. ErrMsg(err))
elseif err == iconv.ERROR_INVALID then
print("ERROR: Invalid input.")
elseif err == iconv.ERROR_NO_MEMORY then
print("ERROR: Failed to allocate memory.")
elseif err == iconv.ERROR_UNKNOWN then
print("ERROR: There was an unknown error.")
end end
print(ostr) print(ostr)
end end
@ -106,3 +110,26 @@ check_one(termcs, "utf16", utf16)
check_one(termcs, "EBCDIC-CP-ES", ebcdic) 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 _, e, cd, s, gc
cd = iconv.new("iso-8859-1", "utf-8")
_, e = cd:iconv("atenção")
assert(e == nil, "Unexpected conversion error")
gc = getmetatable(cd).__gc
gc(cd)
_, e = cd:iconv("atenção")
assert(e == iconv.ERROR_FINALIZED, "Failed to detect double-freed objects")
gc(cd)
-- Test expected return values
cd = iconv.new("ascii", "utf-8")
_, e = cd:iconv("atenção")
assert(e == iconv.ERROR_INVALID, "Unexpected return value for invalid conversion")
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")

37
uniopen.lua Normal file
View File

@ -0,0 +1,37 @@
-- Simple (and incomplete) Unicode I/O layer.
local iconv = require("iconv")
local m = { }
local mti = { }
local mt = { __index = mti }
function m.open(fname, mode, tocharset, fromcharset)
assert(mode == "r" or mode == "rb", "Only read modes are supported yet")
local cd = assert(iconv.new(tocharset, fromcharset), "Bad charset")
local fp = io.open(fname, mode)
if not fp then
return nil
end
local o = { fp = fp, cd = cd }
setmetatable(o, mt)
return o;
end
function mti.read(fp, mod)
assert(fp and fp.fp and fp.cd, "Bad file descriptor")
local ret = fp.fp:read(mod)
if ret then
return fp.cd:iconv(ret) -- returns: string, error code
else
return nil
end
end
function mti.close(fp)
assert(fp and fp.fp, "Bad file descriptor")
fp.fp:close()
end
return m