luaa: do not replace string.len(), export wlen()

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2008-12-15 14:06:22 +01:00
parent ba6f5e42bb
commit 13787c0ba8
2 changed files with 5 additions and 5 deletions

View File

@ -151,7 +151,7 @@ function run(args, textbox, exe_callback, completion_callback, history_path, his
history_check_load(history_path, history_max) history_check_load(history_path, history_max)
local history_index = history_items(history_path) + 1 local history_index = history_items(history_path) + 1
-- The cursor position -- The cursor position
local cur_pos = (args.selectall and 1) or text:len() + 1 local cur_pos = (args.selectall and 1) or text:wlen() + 1
-- The completion element to use on completion request. -- The completion element to use on completion request.
local ncomp = 1 local ncomp = 1
if not textbox or not exe_callback then if not textbox or not exe_callback then
@ -288,9 +288,9 @@ function run(args, textbox, exe_callback, completion_callback, history_path, his
cur_pos = 1 cur_pos = 1
end end
else else
-- len() is UTF-8 aware but #key is not, -- wlen() is UTF-8 aware but #key is not,
-- so check that we have one UTF-8 char but advance the cursor of # position -- so check that we have one UTF-8 char but advance the cursor of # position
if key:len() == 1 then if key:wlen() == 1 then
if args.selectall then command = "" end if args.selectall then command = "" end
command = command:sub(1, cur_pos - 1) .. key .. command:sub(cur_pos) command = command:sub(1, cur_pos - 1) .. key .. command:sub(cur_pos)
cur_pos = cur_pos + #key cur_pos = cur_pos + #key

4
luaa.c
View File

@ -319,10 +319,10 @@ CHECK_TYPE(widget);
static void static void
luaA_fixups(lua_State *L) luaA_fixups(lua_State *L)
{ {
/* replace string.len */ /* export string.wlen */
lua_getglobal(L, "string"); lua_getglobal(L, "string");
lua_pushcfunction(L, luaA_mbstrlen); lua_pushcfunction(L, luaA_mbstrlen);
lua_setfield(L, -2, "len"); lua_setfield(L, -2, "wlen");
lua_pop(L, 1); lua_pop(L, 1);
/* replace next */ /* replace next */
lua_pushliteral(L, "next"); lua_pushliteral(L, "next");