mirror of
https://github.com/lunarmodules/lua-iconv.git
synced 2025-06-23 04:34:33 +02:00
*** empty log message ***
git-svn-id: file:///var/svn/lua-iconv/trunk@15 9538949d-8f27-0410-946f-ce01ef448559
This commit is contained in:
parent
37c7cd2fda
commit
c4709924a3
42
luaiconv.c
42
luaiconv.c
@ -150,6 +150,45 @@ static int Liconv(lua_State *L)
|
|||||||
return 1; /* Done */
|
return 1; /* Done */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef HAS_ICONVLIST
|
||||||
|
|
||||||
|
static int push_one(unsigned int cnt, char *names[], void *data)
|
||||||
|
{
|
||||||
|
lua_State *L = (lua_State*) data;
|
||||||
|
int n = (int) lua_tonumber(L, -1);
|
||||||
|
int i;
|
||||||
|
|
||||||
|
/* Stack: <tbl> n */
|
||||||
|
lua_remove(L, -1);
|
||||||
|
for(i = 0; i < cnt; i++)
|
||||||
|
{
|
||||||
|
/* Stack> <tbl> */
|
||||||
|
lua_pushnumber(L, n++);
|
||||||
|
lua_pushstring(L, names[i]);
|
||||||
|
/* Stack: <tbl> n <str> */
|
||||||
|
lua_settable(L, -3);
|
||||||
|
}
|
||||||
|
lua_pushnumber(L, n);
|
||||||
|
/* Stack: <tbl> n */
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int Liconvlist(lua_State *L)
|
||||||
|
{
|
||||||
|
lua_newtable(L);
|
||||||
|
lua_pushnumber(L, 1);
|
||||||
|
|
||||||
|
/* Stack: <tbl> 1 */
|
||||||
|
iconvlist(push_one, (void*) L);
|
||||||
|
|
||||||
|
/* Stack: <tbl> n */
|
||||||
|
lua_remove(L, -1);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
static int Liconv_close(lua_State *L)
|
static int Liconv_close(lua_State *L)
|
||||||
{
|
{
|
||||||
@ -167,6 +206,9 @@ static const luaL_reg inconvFuncs[] =
|
|||||||
{ "open", Liconv_open },
|
{ "open", Liconv_open },
|
||||||
{ "new", Liconv_open },
|
{ "new", Liconv_open },
|
||||||
{ "iconv", Liconv },
|
{ "iconv", Liconv },
|
||||||
|
#ifdef HAS_ICONVLIST
|
||||||
|
{ "list", Liconvlist },
|
||||||
|
#endif
|
||||||
{ NULL, NULL }
|
{ NULL, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
assert(loadlib("./libluaiconv.so", "luaopen_iconv"))()
|
assert(loadlib("./libluaiconv.so", "luaopen_iconv"))()
|
||||||
|
|
||||||
cd = iconv.new("utf-8", "iso-8859-1")
|
cd = iconv.new("utf-8", "iso-8859-1")
|
||||||
@ -8,7 +7,7 @@ cd = iconv.new("utf-8", "iso-8859-1")
|
|||||||
assert(cd, "Invalid conversion")
|
assert(cd, "Invalid conversion")
|
||||||
|
|
||||||
--ret, err = cd:iconv("Isso é um teste com acentuação")
|
--ret, err = cd:iconv("Isso é um teste com acentuação")
|
||||||
ret, err = cd:iconv("ç")
|
ret, err = cd:iconv("ÃÁÉÍÓÚÇÑÝÔÕ")
|
||||||
|
|
||||||
if err == iconv.ERROR_INCOMPLETE then
|
if err == iconv.ERROR_INCOMPLETE then
|
||||||
print("Error: Incomplete input.")
|
print("Error: Incomplete input.")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user