Compare commits

..

No commits in common. "master" and "v7.0.0" have entirely different histories.

11 changed files with 20 additions and 347 deletions

View File

@ -1,13 +0,0 @@
# 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

@ -68,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
$(LUABIN) test_iconv.lua lua test_iconv.lua

View File

@ -55,29 +55,14 @@ call to load up the library (that, of course, must be installed in a directory f
## API documentation ## API documentation
```lua ```lua
cd, err = iconv.new(to, from) cd = iconv.new(to, from)
cd, err = iconv.open(to, from) cd = iconv.open(to, from)
``` ```
Opens a new conversion descriptor, from the 'from' charset to the 'to' charset. 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. 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: This function returns a new converter or nil on error.
* `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 ```lua

View File

@ -1,62 +0,0 @@
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"}
}
}
},
}
}

View File

@ -39,12 +39,6 @@
#define LIB_VERSION LIB_NAME " 7" #define LIB_VERSION LIB_NAME " 7"
#define ICONV_TYPENAME "iconv_t" #define ICONV_TYPENAME "iconv_t"
#ifdef _WIN32
#define LUAEXPORT __declspec(dllexport)
#else
#define LUAEXPORT __attribute__((visibility("default")))
#endif
#if LUA_VERSION_NUM < 501 #if LUA_VERSION_NUM < 501
#error "Unsupported Lua version. You must use Lua >= 5.1" #error "Unsupported Lua version. You must use Lua >= 5.1"
#endif #endif
@ -98,17 +92,11 @@ 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 */
return 1;
} else {
lua_pushnil(L); /* error */
if (errno == EINVAL)
lua_pushnumber(L, ERROR_INVALID);
else else
lua_pushnumber(L, ERROR_UNKNOWN); lua_pushnil(L); /* error */
return 2; return 1;
};
} }
/* Use a fixed-size buffer in the stack to avoid a lot of small mallocs /* Use a fixed-size buffer in the stack to avoid a lot of small mallocs
@ -128,7 +116,6 @@ static int Liconv(lua_State *L)
char *outbuf = outbufs; char *outbuf = outbufs;
size_t obleft = CONV_BUF_SIZE; size_t obleft = CONV_BUF_SIZE;
size_t ret = -1; size_t ret = -1;
luaL_Buffer b;
if (cd == NULL) { if (cd == NULL) {
lua_pushstring(L, ""); lua_pushstring(L, "");
@ -136,6 +123,7 @@ static int Liconv(lua_State *L)
return 2; return 2;
} }
luaL_Buffer b;
luaL_buffinit(L, &b); luaL_buffinit(L, &b);
do { do {
@ -219,7 +207,7 @@ static int Liconv_close(lua_State *L)
lua_pushboolean(L, 1); /* ok */ lua_pushboolean(L, 1); /* ok */
} }
else else
lua_pushnil(L); /* error, called from __gc, so no need for error messsage */ lua_pushnil(L); /* error */
return 1; return 1;
} }
@ -235,7 +223,7 @@ static const luaL_Reg iconv_funcs[] = {
}; };
LUAEXPORT int luaopen_iconv(lua_State *L) int luaopen_iconv(lua_State *L)
{ {
luaL_newlib(L, iconv_funcs); luaL_newlib(L, iconv_funcs);

View File

@ -1,52 +0,0 @@
-- 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

@ -1,51 +0,0 @@
-- 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

@ -1,50 +0,0 @@
-- 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

@ -1,62 +0,0 @@
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

@ -76,30 +76,20 @@ local ebcdic = "\193\150\64\147\150\149\135\133\107\64\129\150\64\147\164\129"
.. "\37" .. "\37"
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) 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, errno = iconv.new(to .. "//TRANSLIT", from) local cd = iconv.new(to .. "//TRANSLIT", from)
assert(cd, "Failed to create a converter object: " .. ErrMsg(errno)) assert(cd, "Failed to create a converter object.")
local ostr, err = cd:iconv(text) local ostr, err = cd:iconv(text)
if err then if err == iconv.ERROR_INCOMPLETE then
print("ERROR: " .. ErrMsg(err)) print("ERROR: Incomplete input.")
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