mirror of
https://github.com/lunarmodules/lua-iconv.git
synced 2025-06-22 20:24:36 +02:00
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).
This commit is contained in:
parent
e394f70df0
commit
ff90f3f75e
8
README
8
README
@ -11,8 +11,8 @@ 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 and later *requires* Lua 5.1. If you are using Lua 5.0, please
|
||||
use the first release (lua-iconv-r1).
|
||||
Lua-iconv 7 and later *requires* Lua 5.2. If you are using Lua 5.1, please
|
||||
use the release 6; 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).
|
||||
@ -39,7 +39,7 @@ untar the distribution package and, within the program directory, type:
|
||||
make install
|
||||
|
||||
as root. The library will be compiled and installed on the in the correct
|
||||
path (which is defined in lua5.1.pc). Compiling on systems without pkg-config
|
||||
path (which is defined in lua5.2.pc). Compiling on systems without pkg-config
|
||||
requires manual changes in the Makefile (this includes Windows).
|
||||
|
||||
|
||||
@ -49,7 +49,7 @@ requires manual changes in the Makefile (this includes Windows).
|
||||
Lua-iconv is a shared library that must be loaded in the Lua interpreter
|
||||
before use. From Lua 5.1 and later, you can simply do a
|
||||
|
||||
require "iconv"
|
||||
local iconv = require("iconv")
|
||||
|
||||
call to load up the library (that, of course, must be installed in a
|
||||
directory from package.cpath).
|
||||
|
30
luaiconv.c
30
luaiconv.c
@ -36,20 +36,9 @@
|
||||
#include <errno.h>
|
||||
|
||||
#define LIB_NAME "iconv"
|
||||
#define LIB_VERSION LIB_NAME " 6"
|
||||
#define LIB_VERSION LIB_NAME " 7"
|
||||
#define ICONV_TYPENAME "iconv_t"
|
||||
|
||||
|
||||
/* Compatibility between Lua 5.1+ and Lua 5.0 */
|
||||
#ifndef LUA_VERSION_NUM
|
||||
#define LUA_VERSION_NUM 0
|
||||
#endif
|
||||
#if LUA_VERSION_NUM < 501
|
||||
#define luaL_register(a, b, c) luaL_openlib((a), (b), (c), 0)
|
||||
#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 UNBOXPTR(L, i) (*(void**)(lua_touserdata(L, i)))
|
||||
|
||||
@ -101,7 +90,7 @@ static int Liconv_open(lua_State *L) {
|
||||
|
||||
static int Liconv(lua_State *L) {
|
||||
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 *outbuf;
|
||||
char *outbufs;
|
||||
@ -211,14 +200,8 @@ static const luaL_reg inconvFuncs[] = {
|
||||
};
|
||||
|
||||
|
||||
static const luaL_reg iconvMT[] = {
|
||||
{ "__gc", Liconv_close },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
|
||||
int luaopen_iconv(lua_State *L) {
|
||||
luaL_register(L, LIB_NAME, inconvFuncs);
|
||||
luaL_newlib(L, inconvFuncs);
|
||||
|
||||
TBL_SET_INT_CONST(L, "ERROR_NO_MEMORY", ERROR_NO_MEMORY);
|
||||
TBL_SET_INT_CONST(L, "ERROR_INVALID", ERROR_INVALID);
|
||||
@ -230,10 +213,15 @@ int luaopen_iconv(lua_State *L) {
|
||||
lua_settable(L, -3);
|
||||
|
||||
luaL_newmetatable(L, ICONV_TYPENAME);
|
||||
|
||||
lua_pushliteral(L, "__index");
|
||||
lua_pushvalue(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);
|
||||
|
||||
return 1;
|
||||
|
@ -1,4 +1,4 @@
|
||||
require "iconv"
|
||||
local iconv = require("iconv")
|
||||
|
||||
-- Set your terminal encoding here
|
||||
-- local termcs = "iso-8859-1"
|
||||
|
Loading…
x
Reference in New Issue
Block a user