Divert lua string.len to a multibyte aware implementation.

Signed-off-by: Pierre Habouzit <madcoder@debian.org>
This commit is contained in:
Pierre Habouzit 2008-06-25 11:42:06 +02:00
parent d3b030aa2c
commit 0f23ce88cb
1 changed files with 19 additions and 0 deletions

19
lua.c
View File

@ -453,6 +453,23 @@ luaA_openlib(lua_State *L, const char *name,
luaL_register(L, name, methods); luaL_register(L, name, methods);
} }
static int
luaA_mbstrlen(lua_State *L)
{
const char *cmd = luaL_checkstring(L, 1);
lua_pushnumber(L, mbstowcs(NULL, NONULL(cmd), 0));
return 1;
}
static void
luaA_fixups(lua_State *L)
{
lua_getglobal(L, "string");
lua_pushcfunction(L, luaA_mbstrlen);
lua_setfield(L, -2, "len");
lua_pop(L, 1);
}
/** Initialize the Lua VM /** Initialize the Lua VM
*/ */
void void
@ -497,6 +514,8 @@ luaA_init(void)
luaL_openlibs(L); luaL_openlibs(L);
luaA_fixups(L);
/* Export awesome lib */ /* Export awesome lib */
luaL_register(L, "awesome", awesome_lib); luaL_register(L, "awesome", awesome_lib);