summaryrefslogtreecommitdiff
path: root/core/src
diff options
context:
space:
mode:
authorruki <[email protected]>2026-01-20 23:26:43 +0800
committerruki <[email protected]>2026-01-20 23:26:43 +0800
commita22dc9398d5323bf6c4c636915be836de3d1d850 (patch)
tree13c5498224b1f21b288accc67a1980fee4107aed /core/src
parentf8ab0100d040c5b96f52062caa9b912fe08cc9b6 (diff)
improve code styles
Diffstat (limited to 'core/src')
-rw-r--r--core/src/xmake/prefix.h9
-rw-r--r--core/src/xmake/utf8/codepoint.c7
-rw-r--r--core/src/xmake/utf8/codes.c12
-rw-r--r--core/src/xmake/utf8/utf8.h13
4 files changed, 25 insertions, 16 deletions
diff --git a/core/src/xmake/prefix.h b/core/src/xmake/prefix.h
index 4b159741e..7cd2ea418 100644
--- a/core/src/xmake/prefix.h
+++ b/core/src/xmake/prefix.h
@@ -43,6 +43,15 @@
#endif
/* //////////////////////////////////////////////////////////////////////////////////////
+ * types
+ */
+
+// define lua_Unsigned for luajit/lua5.1
+#if defined(USE_LUAJIT) || LUA_VERSION_NUM < 503
+typedef size_t lua_Unsigned;
+#endif
+
+/* //////////////////////////////////////////////////////////////////////////////////////
* private interfaces
*/
diff --git a/core/src/xmake/utf8/codepoint.c b/core/src/xmake/utf8/codepoint.c
index f4c9544f2..7d2f0de24 100644
--- a/core/src/xmake/utf8/codepoint.c
+++ b/core/src/xmake/utf8/codepoint.c
@@ -25,15 +25,18 @@
#include "utf8.h"
/* //////////////////////////////////////////////////////////////////////////////////////
- * implementation
+ * private implementation
*/
-
static tb_bool_t xm_utf8_codepoint_cb(xm_utf8_int_t code, tb_cpointer_t udata) {
lua_State* lua = (lua_State*)udata;
lua_pushinteger(lua, code);
return tb_true;
}
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * implementation
+ */
+
/*
** codepoint(s, [i, [j [, lax]]]) -> returns codepoints for all
** characters that start in the range [i,j]
diff --git a/core/src/xmake/utf8/codes.c b/core/src/xmake/utf8/codes.c
index be6cf462a..46664e891 100644
--- a/core/src/xmake/utf8/codes.c
+++ b/core/src/xmake/utf8/codes.c
@@ -28,7 +28,7 @@
* private implementation
*/
-static tb_int_t iter_aux (lua_State *lua, tb_bool_t strict) {
+static tb_int_t xm_utf8_codes_iter(lua_State *lua, tb_bool_t strict) {
size_t len;
tb_char_t const* s = luaL_checklstring(lua, 1, &len);
lua_Unsigned n = (lua_Unsigned)lua_tointeger(lua, 2);
@@ -48,12 +48,12 @@ static tb_int_t iter_aux (lua_State *lua, tb_bool_t strict) {
}
}
-static int iter_auxstrict (lua_State *lua) {
- return iter_aux(lua, tb_true);
+static int xm_utf8_codes_iter_strict(lua_State *lua) {
+ return xm_utf8_codes_iter(lua, tb_true);
}
-static int iter_auxlax (lua_State *lua) {
- return iter_aux(lua, tb_false);
+static int xm_utf8_codes_iter_lax(lua_State *lua) {
+ return xm_utf8_codes_iter(lua, tb_false);
}
/* //////////////////////////////////////////////////////////////////////////////////////
@@ -64,7 +64,7 @@ tb_int_t xm_utf8_codes(lua_State *lua) {
tb_bool_t lax = lua_toboolean(lua, 2);
tb_char_t const* s = luaL_checkstring(lua, 1);
luaL_argcheck(lua, !xm_utf8_iscontp(s), 1, XM_UTF8_MSGInvalid);
- lua_pushcfunction(lua, lax ? iter_auxlax : iter_auxstrict);
+ lua_pushcfunction(lua, lax ? xm_utf8_codes_iter_lax : xm_utf8_codes_iter_strict);
lua_pushvalue(lua, 1);
lua_pushinteger(lua, 0);
return 3;
diff --git a/core/src/xmake/utf8/utf8.h b/core/src/xmake/utf8/utf8.h
index 8306abee9..a2ecebca4 100644
--- a/core/src/xmake/utf8/utf8.h
+++ b/core/src/xmake/utf8/utf8.h
@@ -23,15 +23,18 @@ typedef tb_uint32_t xm_utf8_int_t;
typedef tb_bool_t (*xm_utf8_codepoint_func_t)(xm_utf8_int_t code, tb_cpointer_t udata);
/* //////////////////////////////////////////////////////////////////////////////////////
- * interfaces
+ * inline interfaces
*/
-
static __tb_inline__ tb_long_t xm_utf8_posrelat(tb_long_t pos, tb_size_t len) {
if (pos >= 0) return pos;
else if (0u - (tb_size_t)pos > len) return 0;
else return (tb_long_t)len + pos + 1;
}
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * interfaces
+ */
+
tb_char_t const* xm_utf8_decode(tb_char_t const* s, xm_utf8_int_t* val, tb_bool_t strict);
tb_size_t xm_utf8_encode(tb_char_t* s, xm_utf8_int_t val);
@@ -39,10 +42,4 @@ tb_long_t xm_utf8_len_impl(tb_char_t const* s, tb_size_t len, tb_long_
tb_long_t xm_utf8_offset_impl(tb_char_t const* s, tb_size_t len, tb_long_t n, tb_long_t posi);
tb_bool_t xm_utf8_codepoint_impl(tb_char_t const* s, tb_size_t len, tb_long_t posi, tb_long_t posj, tb_bool_t strict, xm_utf8_codepoint_func_t func, tb_cpointer_t udata);
-tb_int_t xm_utf8_char(lua_State* lua);
-tb_int_t xm_utf8_codes(lua_State* lua);
-tb_int_t xm_utf8_codepoint(lua_State* lua);
-tb_int_t xm_utf8_len(lua_State* lua);
-tb_int_t xm_utf8_offset(lua_State* lua);
-
#endif