mirror of
https://github.com/lunarmodules/lua-iconv.git
synced 2025-06-23 12:44:28 +02:00
Compare commits
47 Commits
lua-iconv-
...
master
Author | SHA1 | Date | |
---|---|---|---|
|
3c729ec869 | ||
|
5452834c16 | ||
|
dbdd9d9ab8 | ||
|
9eced53a8d | ||
|
1e6d024dc2 | ||
|
11545d0533 | ||
|
9e865ff345 | ||
|
8e19fde5f3 | ||
|
e4d200c102 | ||
|
ba4f3a4518 | ||
|
ac7f962b31 | ||
|
80e3266ced | ||
|
51c1d732ed | ||
|
939fc2901b | ||
|
c2ee26e1ef | ||
|
b761918588 | ||
|
2205a0fe27 | ||
|
d41e0d345d | ||
|
49eb7b534f | ||
|
6f265ded5d | ||
|
1876a6de19 | ||
|
e8d34024a6 | ||
|
6eb316bccc | ||
|
411ac9fe72 | ||
|
8bf1e80355 | ||
|
1fc031875f | ||
|
044877f838 | ||
|
32c7b20967 | ||
|
6b46ea5706 | ||
|
44af7c2835 | ||
|
266da128c5 | ||
|
30fdc3c192 | ||
|
e9f3a5e377 | ||
|
0879d77e1a | ||
|
1cbd622cef | ||
|
1a183d84c2 | ||
|
ff90f3f75e | ||
|
e394f70df0 | ||
|
fc22d5b632 | ||
|
9511e04e61 | ||
|
a80bed8045 | ||
|
a9b6a899a4 | ||
|
f80402c452 | ||
|
a46edb3206 | ||
|
f5ece25447 | ||
|
eb15cbb43f | ||
|
80bfe373a3 |
34
.github/workflows/deploy.yml
vendored
Normal file
34
.github/workflows/deploy.yml
vendored
Normal 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
13
.github/workflows/luacheck.yml
vendored
Normal 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
4
.gitignore
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
*.lo
|
||||||
|
*.o
|
||||||
|
*.so
|
||||||
|
*.tar.gz
|
13
CHANGELOG.md
Normal file
13
CHANGELOG.md
Normal 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
|
2
COPYING
2
COPYING
@ -1,4 +1,4 @@
|
|||||||
Lua-iconv is (c) 2005-06 Alexandre Erwin Ittner <aittner@gmail.com>
|
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
|
||||||
|
35
Makefile
35
Makefile
@ -1,5 +1,5 @@
|
|||||||
# luaiconv - Performs character set conversions in Lua
|
# luaiconv - Performs character set conversions in Lua
|
||||||
# (c) 2005-08 Alexandre Erwin Ittner <aittner@gmail.com>
|
# (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
|
||||||
@ -28,21 +28,28 @@
|
|||||||
|
|
||||||
# Gives a nice speedup, but also spoils debugging on x86. Comment out this
|
# Gives a nice speedup, but also spoils debugging on x86. Comment out this
|
||||||
# line when debugging.
|
# line when debugging.
|
||||||
OMIT_FRAME_POINTER = -fomit-frame-pointer
|
OMIT_FRAME_PTR = -fomit-frame-pointer
|
||||||
|
|
||||||
# Name of .pc file. "lua5.1" on Debian/Ubuntu
|
LUABIN = lua
|
||||||
LUAPKG = lua5.1
|
LUAPKG = lua5.2
|
||||||
CFLAGS = `pkg-config $(LUAPKG) --cflags` -fPIC -O3 -Wall
|
CFLAGS = `pkg-config $(LUAPKG) --cflags` -fPIC -O3 -Wall $(OMIT_FRAME_PTR)
|
||||||
LFLAGS = -shared $(OMIT_FRAME_POINTER)
|
LFLAGS = -shared
|
||||||
INSTALL_PATH = `pkg-config $(LUAPKG) --variable=INSTALL_CMOD`
|
|
||||||
|
|
||||||
## If your system doesn't have pkg-config, comment out the previous lines and
|
INSTALL_PATH = `$(LUABIN) -e' \
|
||||||
## uncomment and change the following ones according to your building
|
for dir in package.cpath:gmatch("(/[^?;]+)?") do \
|
||||||
## enviroment.
|
io.write(dir) \
|
||||||
|
os.exit(0) \
|
||||||
|
end \
|
||||||
|
os.exit(1) \
|
||||||
|
'`
|
||||||
|
|
||||||
#CFLAGS = -I/usr/include/lua5.1/ -fPIC -O3 -Wall
|
## If your system doesn't have pkg-config or if you do not want to get the
|
||||||
#LFLAGS = -shared $(OMIT_FRAME_POINTER)
|
## install path from Lua, comment out the previous lines and uncomment and
|
||||||
#INSTALL_PATH = /usr/lib/lua/5.1
|
## 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: iconv.so
|
all: iconv.so
|
||||||
@ -61,5 +68,5 @@ clean:
|
|||||||
$(RM) iconv.so iconv.lo
|
$(RM) iconv.so iconv.lo
|
||||||
|
|
||||||
test: iconv.so test_iconv.lua
|
test: iconv.so test_iconv.lua
|
||||||
lua test_iconv.lua
|
$(LUABIN) test_iconv.lua
|
||||||
|
|
||||||
|
127
README
127
README
@ -1,127 +0,0 @@
|
|||||||
|
|
||||||
Lua-iconv: performs character set conversions in Lua
|
|
||||||
(c) 2005-09 Alexandre Erwin Ittner <aittner@gmail.com>
|
|
||||||
Project page: http://lua-iconv.luaforge.net/
|
|
||||||
|
|
||||||
|
|
||||||
=== 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 6 *requires* Lua 5.1. If you are using Lua 5.0, please use the
|
|
||||||
first release (lua-iconv-r1).
|
|
||||||
|
|
||||||
Details regarding iconv may be obtained from:
|
|
||||||
http://www.opengroup.org/onlinepubs/007908799/xsh/iconv.h.html
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
=== LICENSE ===
|
|
||||||
|
|
||||||
Lua-iconv is (c) 2005-09 Alexandre Erwin Ittner <aittner@gmail.com>
|
|
||||||
|
|
||||||
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, COMPILATION 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 new module system in Lua 5.1.
|
|
||||||
|
|
||||||
If you are using a system with pkg-config (as many Linux distributions and
|
|
||||||
Unix flavors) 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 in the correct path (that
|
|
||||||
is defined in lua5.1.pc.
|
|
||||||
|
|
||||||
Compiling on systems without pkg-config requires manual changes on the
|
|
||||||
Makefile.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
=== 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. Lua 5.1
|
|
||||||
uses the new package system, so you can simply do a
|
|
||||||
|
|
||||||
require "iconv"
|
|
||||||
|
|
||||||
call to load up the library (that, of course, must be installed in a
|
|
||||||
directory from package.cpath).
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
=== 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.
|
|
||||||
|
|
||||||
|
|
||||||
=== EOF ===
|
|
||||||
|
|
145
README.md
Normal file
145
README.md
Normal 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).
|
||||||
|
|
34
debian/Makefile.Debian.conf
vendored
34
debian/Makefile.Debian.conf
vendored
@ -1,34 +0,0 @@
|
|||||||
PKG_NAME=iconv
|
|
||||||
|
|
||||||
### things relative to the C library part
|
|
||||||
CLIB_CFLAGS=
|
|
||||||
CLIB_LDFLAGS=
|
|
||||||
CLIB_OBJS=luaiconv.lo
|
|
||||||
VERSION_INFO=0:0:0
|
|
||||||
|
|
||||||
### things relative to the lua library part
|
|
||||||
LUA_HEADER=
|
|
||||||
LUA_SOURCES=
|
|
||||||
LUA_MODNAME=iconv
|
|
||||||
LUA_TEST=test_iconv.lua
|
|
||||||
|
|
||||||
### this part is relative to pkg-config
|
|
||||||
PKG_VERSION=$(shell dpkg-parsechangelog|grep ^Ver|cut -d ' ' -f 2|cut -d '-' -f 1)
|
|
||||||
PKG_LIBS_PRIVATE=
|
|
||||||
PKG_URL=http://lua-iconv.luaforge.net/
|
|
||||||
PKG_REQUIRES=
|
|
||||||
PKG_CONFLICTS=
|
|
||||||
|
|
||||||
### In addition, to gather flexibility, you can set these hooks
|
|
||||||
### (called in this order)
|
|
||||||
pre-all-hook::
|
|
||||||
post-all-hook::
|
|
||||||
pre-test-hook::
|
|
||||||
pre-lua-dynamic-test-hook::
|
|
||||||
pre-dynamic-link-hook::
|
|
||||||
pre-app-dynamic-test-hook::
|
|
||||||
pre-static-link-hook::
|
|
||||||
pre-app-static-test-hook::
|
|
||||||
post-test-hook::
|
|
||||||
pre-install-hook::
|
|
||||||
post-install-hook::
|
|
27
debian/changelog
vendored
27
debian/changelog
vendored
@ -1,13 +1,28 @@
|
|||||||
lua-iconv (0.r4-1) unstable; urgency=low
|
lua-iconv (7-1) unstable; urgency=low
|
||||||
|
|
||||||
* New Debian packages according to the Debian Lua policy.
|
* Update package for lua-iconv 7 + Lua-5.2
|
||||||
|
|
||||||
-- Alexandre Erwin Ittner <aittner@gmail.com> Sun, 11 May 2008 12:30:00 -0300
|
-- Alexandre Erwin Ittner <alexandre@ittner.com.br> Sun, 06 May 2012 22:35:22 -0300
|
||||||
|
|
||||||
|
lua-iconv (6-3) unstable; urgency=low
|
||||||
|
|
||||||
lua-iconv (0.r3-1) unstable; urgency=low
|
* debian/control: Conflicts, Provides, and Replaces lua-iconv
|
||||||
|
(Closes: #557052)
|
||||||
|
|
||||||
* First release in .deb format.
|
-- Jon Bernard <jbernard@debian.org> Fri, 20 Nov 2009 18:58:12 -0600
|
||||||
|
|
||||||
-- Alexandre Erwin Ittner <aittner@netuno.com.br> Wed, 3 Feb 2007 00:20:09 -0200
|
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
1
debian/compat
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
7
|
35
debian/control
vendored
35
debian/control
vendored
@ -1,26 +1,21 @@
|
|||||||
Source: lua-iconv
|
Source: lua-iconv
|
||||||
Section: interpreters
|
Section: interpreters
|
||||||
Priority: optional
|
Priority: optional
|
||||||
Maintainer: Alexandre Erwin Ittner <aittner@gmail.com>
|
Maintainer: Jon Bernard <jbernard@debian.org>
|
||||||
Build-Depends: cdbs (>= 0.4.23-1.1), debhelper (>= 5), dpatch, lua5.1-policy-dev (>= 8)
|
Build-Depends: debhelper (>= 7), liblua5.2-dev, lua5.2, pkg-config
|
||||||
Standards-Version: 3.7.2
|
Standards-Version: 3.8.2
|
||||||
XS-X-Vcs-svn: svn://svn.debian.org/pkg-lua/packages/lua-iconv
|
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.1-iconv
|
Package: liblua5.2-iconv0
|
||||||
Architecture: any
|
Architecture: any
|
||||||
Depends: ${shlibs:Depends}
|
Depends: ${shlibs:Depends}, ${misc:Depends}
|
||||||
Description: iconv bindings for the Lua Programming Language
|
Recommends: lua5.2
|
||||||
Lua-iconv is POSIX 'iconv' binding for the Lua Programming Language. It
|
Conflicts: lua-iconv
|
||||||
converts a sequence of characters from one codeset into a sequence of
|
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.
|
corresponding characters in another codeset.
|
||||||
Homepage: <http://lua-iconv.luaforge.net/>
|
|
||||||
|
|
||||||
Package: liblua5.1-iconv-dev
|
|
||||||
Architecture: any
|
|
||||||
Depends: liblua5.1-iconv (= ${Source-Version})
|
|
||||||
Description: iconv development files for the lua language version 5.1
|
|
||||||
This package contains the development files of the iconv lua5.1 bindings,
|
|
||||||
useful to create a statically linked binary (like a C application or a
|
|
||||||
standalone lua interpreter).
|
|
||||||
Documentation is also shipped within this package.
|
|
||||||
Homepage: <http://lua-iconv.luaforge.net/>
|
|
||||||
|
53
debian/copyright
vendored
53
debian/copyright
vendored
@ -1,23 +1,42 @@
|
|||||||
lua-iconv (c) 2005-2007 Alexandre Erwin Ittner
|
This package was debianized by Jon Bernard <jbernard@debian.org> on
|
||||||
|
Sun, 02 Aug 2009 13:50:50 -0400.
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining
|
It was downloaded from http://luaforge.net/frs/?group_id=131&release_id=1440
|
||||||
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
|
Upstream Author:
|
||||||
included in all copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
Alexandre Erwin Ittner <alexandre@ittner.com.br>
|
||||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
||||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
Copyright:
|
||||||
IN NO EVENT SHALL THE AUTHOR OR COPYRIGHT HOLDER BE LIABLE FOR ANY
|
|
||||||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
Copyright (C) 2005-09 Alexandre Erwin Ittner
|
||||||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
||||||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
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
|
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).
|
||||||
|
|
||||||
|
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/examples
vendored
Normal file
1
debian/examples
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
test_iconv.lua
|
16
debian/rules
vendored
Executable file → Normal file
16
debian/rules
vendored
Executable file → Normal file
@ -1,15 +1,3 @@
|
|||||||
#!/usr/bin/make -f
|
#!/usr/bin/make -f
|
||||||
|
%:
|
||||||
include /usr/share/cdbs/1/class/makefile.mk
|
dh $@
|
||||||
include /usr/share/cdbs/1/rules/debhelper.mk
|
|
||||||
include /usr/share/cdbs/1/rules/dpatch.mk
|
|
||||||
|
|
||||||
DEB_MAKE_BUILD_TARGET := all -f Makefile.Debian
|
|
||||||
DEB_MAKE_TEST_TARGET := test -f Makefile.Debian
|
|
||||||
DEB_MAKE_CLEAN_TARGET := clean -f Makefile.Debian
|
|
||||||
DEB_MAKE_INSTALL_TARGET := install -f Makefile.Debian DESTDIR=$(DEB_DESTDIR)
|
|
||||||
DEB_DH_INSTALL_SOURCEDIR := $(DEB_DESTDIR)
|
|
||||||
pre-build::
|
|
||||||
lua5.1-policy-apply
|
|
||||||
clean::
|
|
||||||
lua5.1-policy-apply --reverse
|
|
||||||
|
5
debian/watch
vendored
5
debian/watch
vendored
@ -1,5 +0,0 @@
|
|||||||
# test this watch file using:
|
|
||||||
# uscan --watchfile debian/watch --upstream-version 0.0.1 --package lua-iconv
|
|
||||||
#
|
|
||||||
version=3
|
|
||||||
http://luaforge.net/frs/download.php/\d+/lua-iconv-([\d\.]*).tar.gz
|
|
62
lua-iconv-dev-1.rockspec
Normal file
62
lua-iconv-dev-1.rockspec
Normal 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"}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
173
luaiconv.c
173
luaiconv.c
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* luaiconv - Performs character set conversions in Lua
|
* luaiconv - Performs character set conversions in Lua
|
||||||
* (c) 2005-09 Alexandre Erwin Ittner <aittner@gmail.com>
|
* (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,125 +36,143 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
#define LIB_NAME "iconv"
|
#define LIB_NAME "iconv"
|
||||||
#define LIB_VERSION LIB_NAME " 6"
|
#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) {
|
|
||||||
boxptr(L, cd);
|
static void push_iconv_t(lua_State *L, iconv_t cd)
|
||||||
|
{
|
||||||
|
BOXPTR(L, cd);
|
||||||
luaL_getmetatable(L, ICONV_TYPENAME);
|
luaL_getmetatable(L, ICONV_TYPENAME);
|
||||||
lua_setmetatable(L, -2);
|
lua_setmetatable(L, -2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
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);
|
||||||
if (cd == (iconv_t) NULL)
|
return cd; /* May be NULL. This must be checked by the caller. */
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int Liconv_open(lua_State *L) {
|
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
|
|
||||||
lua_pushnil(L); /* erro */
|
|
||||||
return 1;
|
return 1;
|
||||||
|
} else {
|
||||||
|
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;
|
|
||||||
|
luaL_buffinit(L, &b);
|
||||||
|
|
||||||
do {
|
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)) {
|
||||||
lua_pushlstring(L, outbufs, obsize - obleft);
|
luaL_addlstring(&b, outbufs, CONV_BUF_SIZE - obleft);
|
||||||
if (hasone == 1)
|
|
||||||
lua_concat(L, 2);
|
|
||||||
hasone = 1;
|
|
||||||
if (errno == EILSEQ) {
|
if (errno == EILSEQ) {
|
||||||
|
luaL_pushresult(&b);
|
||||||
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 = obsize;
|
obleft = CONV_BUF_SIZE;
|
||||||
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) 0);
|
} while (ret == (size_t) -1);
|
||||||
|
|
||||||
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 */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef HAS_ICONVLIST /* a GNU extension? */
|
#ifdef HAS_ICONVLIST /* a GNU extension? */
|
||||||
|
|
||||||
static int push_one(unsigned int cnt, char *names[], void *data) {
|
static int push_one(unsigned int cnt, char *names[], void *data)
|
||||||
|
{
|
||||||
lua_State *L = (lua_State*) data;
|
lua_State *L = (lua_State*) data;
|
||||||
int n = (int) lua_tonumber(L, -1);
|
int n = (int) lua_tonumber(L, -1);
|
||||||
int i;
|
int i;
|
||||||
@ -175,7 +192,8 @@ static int push_one(unsigned int cnt, char *names[], void *data) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int Liconvlist(lua_State *L) {
|
static int Liconvlist(lua_State *L)
|
||||||
|
{
|
||||||
lua_newtable(L);
|
lua_newtable(L);
|
||||||
lua_pushnumber(L, 1);
|
lua_pushnumber(L, 1);
|
||||||
|
|
||||||
@ -190,17 +208,23 @@ static int Liconvlist(lua_State *L) {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
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 },
|
||||||
@ -211,29 +235,30 @@ static const luaL_reg inconvFuncs[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
static const luaL_reg iconvMT[] = {
|
LUAEXPORT int luaopen_iconv(lua_State *L)
|
||||||
{ "__gc", Liconv_close },
|
{
|
||||||
{ NULL, NULL }
|
luaL_newlib(L, iconv_funcs);
|
||||||
};
|
|
||||||
|
|
||||||
|
TBL_SET_INT_CONST(L, ERROR_NO_MEMORY);
|
||||||
int luaopen_iconv(lua_State *L) {
|
TBL_SET_INT_CONST(L, ERROR_INVALID);
|
||||||
luaL_register(L, LIB_NAME, inconvFuncs);
|
TBL_SET_INT_CONST(L, ERROR_INCOMPLETE);
|
||||||
|
TBL_SET_INT_CONST(L, ERROR_FINALIZED);
|
||||||
tblseticons(L, "ERROR_NO_MEMORY", ERROR_NO_MEMORY);
|
TBL_SET_INT_CONST(L, ERROR_UNKNOWN);
|
||||||
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;
|
||||||
|
@ -3,8 +3,6 @@ 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 c = 0
|
|
||||||
local ostr = "local xxxxxxxxxxx = \""
|
local ostr = "local xxxxxxxxxxx = \""
|
||||||
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))
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
PACKAGE=lua-iconv
|
PACKAGE=lua-iconv
|
||||||
VERSION=6
|
VERSION=7
|
||||||
|
|
||||||
DIRNAME=$PACKAGE-$VERSION
|
DIRNAME=$PACKAGE-$VERSION
|
||||||
TGZNAME=$DIRNAME.tar.gz
|
TGZNAME=$DIRNAME.tar.gz
|
||||||
@ -9,7 +9,7 @@ TGZNAME=$DIRNAME.tar.gz
|
|||||||
rm -f $TGZNAME
|
rm -f $TGZNAME
|
||||||
mkdir $DIRNAME
|
mkdir $DIRNAME
|
||||||
|
|
||||||
#cp -r debian $DIRNAME/
|
cp -r debian $DIRNAME/
|
||||||
#rm -rf $DIRNAME/debian/.svn
|
#rm -rf $DIRNAME/debian/.svn
|
||||||
|
|
||||||
cp -r COPYING Makefile README luaiconv.c test_iconv.lua $DIRNAME
|
cp -r COPYING Makefile README luaiconv.c test_iconv.lua $DIRNAME
|
||||||
|
@ -32,7 +32,7 @@ external_dependencies = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
build = {
|
build = {
|
||||||
type = "module",
|
type = "builtin",
|
||||||
modules = {
|
modules = {
|
||||||
iconv = {
|
iconv = {
|
||||||
sources = {"luaiconv.c"},
|
sources = {"luaiconv.c"},
|
52
rockspecs/lua-iconv-7-1.rockspec
Normal file
52
rockspecs/lua-iconv-7-1.rockspec
Normal 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"}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
51
rockspecs/lua-iconv-7.0.0-2.rockspec
Normal file
51
rockspecs/lua-iconv-7.0.0-2.rockspec
Normal 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"}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
50
rockspecs/lua-iconv-7.0.0-4.rockspec
Normal file
50
rockspecs/lua-iconv-7.0.0-4.rockspec
Normal 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"}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
62
rockspecs/lua-iconv-7.1.0-1.rockspec
Normal file
62
rockspecs/lua-iconv-7.1.0-1.rockspec
Normal 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"}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,6 @@
|
|||||||
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"
|
||||||
@ -74,20 +76,30 @@ 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)
|
||||||
|
if errno == iconv.ERROR_INCOMPLETE then
|
||||||
|
return "Incomplete input."
|
||||||
|
elseif errno == iconv.ERROR_INVALID then
|
||||||
|
return "Invalid input."
|
||||||
|
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
|
||||||
|
return "Unknown error: "..tostring(errno)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
local function check_one(to, from, text)
|
||||||
print("\n-- Testing conversion from " .. from .. " to " .. to)
|
print("\n-- Testing conversion from " .. from .. " to " .. to)
|
||||||
local cd = iconv.new(to .. "//TRANSLIT", from)
|
local cd, errno = iconv.new(to .. "//TRANSLIT", from)
|
||||||
assert(cd, "Failed to create a converter object.")
|
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
|
||||||
@ -97,3 +109,27 @@ check_one(termcs, "utf8", utf8)
|
|||||||
check_one(termcs, "utf16", utf16)
|
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")
|
||||||
|
18
uniopen.lua
18
uniopen.lua
@ -1,16 +1,15 @@
|
|||||||
|
|
||||||
-- Simple (and incomplete) Unicode I/O layer.
|
-- Simple (and incomplete) Unicode I/O layer.
|
||||||
|
|
||||||
module("uniopen", package.seeall)
|
local iconv = require("iconv")
|
||||||
|
|
||||||
require "iconv"
|
local m = { }
|
||||||
|
local mti = { }
|
||||||
|
local mt = { __index = mti }
|
||||||
|
|
||||||
local mt = { __index = _M }
|
function m.open(fname, mode, tocharset, fromcharset)
|
||||||
|
|
||||||
function open(fname, mode, fromcharset, tocharset)
|
|
||||||
assert(mode == "r" or mode == "rb", "Only read modes are supported yet")
|
assert(mode == "r" or mode == "rb", "Only read modes are supported yet")
|
||||||
tocharset = tocharset or "utf8"
|
local cd = assert(iconv.new(tocharset, fromcharset), "Bad charset")
|
||||||
local cd = assert(iconv.new(fromcharset, tocharset), "Bad charset")
|
|
||||||
local fp = io.open(fname, mode)
|
local fp = io.open(fname, mode)
|
||||||
if not fp then
|
if not fp then
|
||||||
return nil
|
return nil
|
||||||
@ -20,7 +19,7 @@ function open(fname, mode, fromcharset, tocharset)
|
|||||||
return o;
|
return o;
|
||||||
end
|
end
|
||||||
|
|
||||||
function read(fp, mod)
|
function mti.read(fp, mod)
|
||||||
assert(fp and fp.fp and fp.cd, "Bad file descriptor")
|
assert(fp and fp.fp and fp.cd, "Bad file descriptor")
|
||||||
local ret = fp.fp:read(mod)
|
local ret = fp.fp:read(mod)
|
||||||
if ret then
|
if ret then
|
||||||
@ -30,8 +29,9 @@ function read(fp, mod)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function close(fp)
|
function mti.close(fp)
|
||||||
assert(fp and fp.fp, "Bad file descriptor")
|
assert(fp and fp.fp, "Bad file descriptor")
|
||||||
fp.fp:close()
|
fp.fp:close()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
return m
|
||||||
|
Loading…
x
Reference in New Issue
Block a user