From 8204558c513dd3e7c0b3d754435539a941bdee8e Mon Sep 17 00:00:00 2001 From: ruki Date: Sat, 22 Aug 2026 00:07:00 +0800 Subject: improve core --- core/src/xmake/utf8/width.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'core/src') diff --git a/core/src/xmake/utf8/width.c b/core/src/xmake/utf8/width.c index 615572462..fb79ee198 100644 --- a/core/src/xmake/utf8/width.c +++ b/core/src/xmake/utf8/width.c @@ -33,7 +33,11 @@ * utf8.width(codepoint) */ tb_int_t xm_utf8_width(lua_State* lua) { - if (lua_isnumber(lua, 1)) { + /* we must not use lua_isnumber() here: it also accepts a numeric string, + * so utf8.width("9") would return the width of the code point 9 (a tab) + * instead of the width of the string "9" + */ + if (lua_type(lua, 1) == LUA_TNUMBER) { xm_utf8_int_t val = (xm_utf8_int_t)lua_tointeger(lua, 1); lua_pushinteger(lua, xm_utf8_charwidth(val)); } else { -- cgit v1.3.1