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)
local history_index = history_items(history_path) + 1
-- 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.
local ncomp = 1
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
end
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
if key:len() == 1 then
if key:wlen() == 1 then
if args.selectall then command = "" end
command = command:sub(1, cur_pos - 1) .. key .. command:sub(cur_pos)
cur_pos = cur_pos + #key

4
luaa.c
View File

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