diff options
| author | ruki <[email protected]> | 2025-11-09 23:22:44 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2025-11-09 23:22:44 +0800 |
| commit | 831447a51da0b094e08bb047247bf269a6e6cf71 (patch) | |
| tree | f345e66e3d9882cbb4d49d588c3080d88bc17cd8 /core | |
| parent | bf2da8a3d7f04bf5ffcdce8fd4c334d5421d3494 (diff) | |
format more if-else
Diffstat (limited to 'core')
48 files changed, 247 insertions, 147 deletions
diff --git a/core/src/xmake/curses/curses.c b/core/src/xmake/curses/curses.c index 988e6840c..4f8c03028 100644 --- a/core/src/xmake/curses/curses.c +++ b/core/src/xmake/curses/curses.c @@ -105,10 +105,12 @@ static int g_mapkey = 0; * private implementation */ static chtype xm_curses_checkch(lua_State *lua, int index) { - if (lua_type(lua, index) == LUA_TNUMBER) + if (lua_type(lua, index) == LUA_TNUMBER) { return (chtype)luaL_checknumber(lua, index); - if (lua_type(lua, index) == LUA_TSTRING) + } + if (lua_type(lua, index) == LUA_TSTRING) { return *lua_tostring(lua, index); + } #ifdef USE_LUAJIT luaL_typerror(lua, index, "chtype"); #endif @@ -685,26 +687,29 @@ static int xm_curses_napms(lua_State *lua) { } static int xm_curses_cbreak(lua_State *lua) { - if (lua_isnoneornil(lua, 1) || lua_toboolean(lua, 1)) + if (lua_isnoneornil(lua, 1) || lua_toboolean(lua, 1)) { lua_pushboolean(lua, XM_CURSES_OK(cbreak())); - else + } else { lua_pushboolean(lua, XM_CURSES_OK(nocbreak())); + } return 1; } static int xm_curses_echo(lua_State *lua) { - if (lua_isnoneornil(lua, 1) || lua_toboolean(lua, 1)) + if (lua_isnoneornil(lua, 1) || lua_toboolean(lua, 1)) { lua_pushboolean(lua, XM_CURSES_OK(echo())); - else + } else { lua_pushboolean(lua, XM_CURSES_OK(noecho())); + } return 1; } static int xm_curses_nl(lua_State *lua) { - if (lua_isnoneornil(lua, 1) || lua_toboolean(lua, 1)) + if (lua_isnoneornil(lua, 1) || lua_toboolean(lua, 1)) { lua_pushboolean(lua, XM_CURSES_OK(nl())); - else + } else { lua_pushboolean(lua, XM_CURSES_OK(nonl())); + } return 1; } diff --git a/core/src/xmake/fwatcher/add.c b/core/src/xmake/fwatcher/add.c index 77c23ea48..10c31b6b0 100644 --- a/core/src/xmake/fwatcher/add.c +++ b/core/src/xmake/fwatcher/add.c @@ -39,8 +39,9 @@ tb_int_t xm_fwatcher_add(lua_State *lua) { tb_assert_and_check_return_val(lua, 0); // is pointer? - if (!xm_lua_ispointer(lua, 1)) + if (!xm_lua_ispointer(lua, 1)) { return 0; + } // get the fwatcher tb_fwatcher_ref_t fwatcher = (tb_fwatcher_ref_t)xm_lua_topointer(lua, 1); diff --git a/core/src/xmake/fwatcher/close.c b/core/src/xmake/fwatcher/close.c index a5501d906..61c78868a 100644 --- a/core/src/xmake/fwatcher/close.c +++ b/core/src/xmake/fwatcher/close.c @@ -39,8 +39,9 @@ tb_int_t xm_fwatcher_close(lua_State *lua) { tb_assert_and_check_return_val(lua, 0); // is pointer? - if (!xm_lua_ispointer(lua, 1)) + if (!xm_lua_ispointer(lua, 1)) { return 0; + } // get the fwatcher tb_fwatcher_ref_t fwatcher = (tb_fwatcher_ref_t)xm_lua_topointer(lua, 1); diff --git a/core/src/xmake/fwatcher/open.c b/core/src/xmake/fwatcher/open.c index 13ab91d5a..032921fb3 100644 --- a/core/src/xmake/fwatcher/open.c +++ b/core/src/xmake/fwatcher/open.c @@ -38,9 +38,10 @@ tb_int_t xm_fwatcher_open(lua_State *lua) { // init fwatcher tb_fwatcher_ref_t fwatcher = (tb_fwatcher_ref_t)tb_fwatcher_init(); - if (fwatcher) + if (fwatcher) { xm_lua_pushpointer(lua, (tb_pointer_t)fwatcher); - else + } else { lua_pushnil(lua); + } return 1; } diff --git a/core/src/xmake/fwatcher/remove.c b/core/src/xmake/fwatcher/remove.c index 6285b0649..a3636dbe3 100644 --- a/core/src/xmake/fwatcher/remove.c +++ b/core/src/xmake/fwatcher/remove.c @@ -39,8 +39,9 @@ tb_int_t xm_fwatcher_remove(lua_State *lua) { tb_assert_and_check_return_val(lua, 0); // is pointer? - if (!xm_lua_ispointer(lua, 1)) + if (!xm_lua_ispointer(lua, 1)) { return 0; + } // get the fwatcher tb_fwatcher_ref_t fwatcher = (tb_fwatcher_ref_t)xm_lua_topointer(lua, 1); diff --git a/core/src/xmake/fwatcher/wait.c b/core/src/xmake/fwatcher/wait.c index 42b01b8aa..0602c931c 100644 --- a/core/src/xmake/fwatcher/wait.c +++ b/core/src/xmake/fwatcher/wait.c @@ -39,8 +39,9 @@ tb_int_t xm_fwatcher_wait(lua_State *lua) { tb_assert_and_check_return_val(lua, 0); // is pointer? - if (!xm_lua_ispointer(lua, 1)) + if (!xm_lua_ispointer(lua, 1)) { return 0; + } // get the fwatcher tb_fwatcher_ref_t fwatcher = (tb_fwatcher_ref_t)xm_lua_topointer(lua, 1); diff --git a/core/src/xmake/libc/byteof.c b/core/src/xmake/libc/byteof.c index dac772e9b..1d49bf815 100644 --- a/core/src/xmake/libc/byteof.c +++ b/core/src/xmake/libc/byteof.c @@ -38,19 +38,21 @@ tb_int_t xm_libc_byteof(lua_State *lua) { // get data tb_pointer_t data = tb_null; - if (lua_isnumber(lua, 1)) + if (lua_isnumber(lua, 1)) { data = (tb_pointer_t)(tb_size_t)lua_tointeger(lua, 1); - else if (lua_isstring(lua, 1)) + } else if (lua_isstring(lua, 1)) { data = (tb_pointer_t)luaL_checkstring(lua, 1); - else + } else { xm_libc_return_error(lua, "libc.byteof(invalid data)!"); + } // get offset tb_int_t offset = 0; - if (lua_isnumber(lua, 2)) + if (lua_isnumber(lua, 2)) { offset = (tb_int_t)lua_tointeger(lua, 2); - else + } else { xm_libc_return_error(lua, "libc.byteof(invalid offset)!"); + } lua_pushinteger(lua, ((tb_byte_t const *)data)[offset]); return 1; } diff --git a/core/src/xmake/libc/dataptr.c b/core/src/xmake/libc/dataptr.c index 363853800..881b373d2 100644 --- a/core/src/xmake/libc/dataptr.c +++ b/core/src/xmake/libc/dataptr.c @@ -37,14 +37,15 @@ tb_int_t xm_libc_dataptr(lua_State *lua) { tb_assert_and_check_return_val(lua, 0); tb_pointer_t data = tb_null; - if (lua_isstring(lua, 1)) + if (lua_isstring(lua, 1)) { data = (tb_pointer_t)luaL_checkstring(lua, 1); - else if (lua_isnumber(lua, 1)) + } else if (lua_isnumber(lua, 1)) { data = (tb_pointer_t)(tb_size_t)lua_tointeger(lua, 1); - else if (xm_lua_ispointer(lua, 1)) + } else if (xm_lua_ispointer(lua, 1)) { data = (tb_pointer_t)xm_lua_topointer(lua, 1); - else + } else { xm_libc_return_error(lua, "libc.dataptr(invalid data)!"); + } lua_pushinteger(lua, (lua_Integer)(tb_long_t)data); return 1; } diff --git a/core/src/xmake/libc/free.c b/core/src/xmake/libc/free.c index 6f0d70f3d..0b686aeb5 100644 --- a/core/src/xmake/libc/free.c +++ b/core/src/xmake/libc/free.c @@ -38,7 +38,8 @@ tb_int_t xm_libc_free(lua_State *lua) { // do free tb_pointer_t data = (tb_pointer_t)(tb_size_t)luaL_checkinteger(lua, 1); - if (data) + if (data) { tb_free(data); + } return 0; } diff --git a/core/src/xmake/libc/malloc.c b/core/src/xmake/libc/malloc.c index faaa00e97..6bda4167d 100644 --- a/core/src/xmake/libc/malloc.c +++ b/core/src/xmake/libc/malloc.c @@ -39,8 +39,9 @@ tb_int_t xm_libc_malloc(lua_State *lua) { // do malloc tb_pointer_t data = tb_null; tb_long_t size = (tb_long_t)luaL_checkinteger(lua, 1); - if (size > 0) + if (size > 0) { data = tb_malloc(size); + } lua_pushinteger(lua, (lua_Integer)(tb_long_t)data); return 1; } diff --git a/core/src/xmake/libc/memcpy.c b/core/src/xmake/libc/memcpy.c index e0e8b1492..ce5e34312 100644 --- a/core/src/xmake/libc/memcpy.c +++ b/core/src/xmake/libc/memcpy.c @@ -40,7 +40,8 @@ tb_int_t xm_libc_memcpy(lua_State *lua) { tb_pointer_t dst = (tb_pointer_t)(tb_size_t)luaL_checkinteger(lua, 1); tb_pointer_t src = (tb_pointer_t)(tb_size_t)luaL_checkinteger(lua, 2); tb_int_t size = (tb_int_t)lua_tointeger(lua, 3); - if (dst && src && size > 0) + if (dst && src && size > 0) { tb_memcpy(dst, src, size); + } return 0; } diff --git a/core/src/xmake/libc/memmov.c b/core/src/xmake/libc/memmov.c index 66120e168..1843a4301 100644 --- a/core/src/xmake/libc/memmov.c +++ b/core/src/xmake/libc/memmov.c @@ -40,7 +40,8 @@ tb_int_t xm_libc_memmov(lua_State *lua) { tb_pointer_t dst = (tb_pointer_t)(tb_size_t)luaL_checkinteger(lua, 1); tb_pointer_t src = (tb_pointer_t)(tb_size_t)luaL_checkinteger(lua, 2); tb_int_t size = (tb_int_t)lua_tointeger(lua, 3); - if (dst && src && size > 0) + if (dst && src && size > 0) { tb_memmov(dst, src, size); + } return 0; } diff --git a/core/src/xmake/libc/memset.c b/core/src/xmake/libc/memset.c index 4f8864842..01b4f3f89 100644 --- a/core/src/xmake/libc/memset.c +++ b/core/src/xmake/libc/memset.c @@ -40,7 +40,8 @@ tb_int_t xm_libc_memset(lua_State *lua) { tb_pointer_t data = (tb_pointer_t)(tb_size_t)luaL_checkinteger(lua, 1); tb_char_t ch = (tb_char_t)lua_tointeger(lua, 2); tb_int_t size = (tb_int_t)lua_tointeger(lua, 3); - if (data && size > 0) + if (data && size > 0) { tb_memset(data, ch, size); + } return 0; } diff --git a/core/src/xmake/libc/setbyte.c b/core/src/xmake/libc/setbyte.c index d53c30229..3bcc3fcdc 100644 --- a/core/src/xmake/libc/setbyte.c +++ b/core/src/xmake/libc/setbyte.c @@ -38,24 +38,27 @@ tb_int_t xm_libc_setbyte(lua_State *lua) { // get data tb_pointer_t data = tb_null; - if (lua_isnumber(lua, 1)) + if (lua_isnumber(lua, 1)) { data = (tb_pointer_t)(tb_size_t)lua_tointeger(lua, 1); - else if (lua_isstring(lua, 1)) + } else if (lua_isstring(lua, 1)) { data = (tb_pointer_t)luaL_checkstring(lua, 1); - else + } else { xm_libc_return_error(lua, "libc.setbyte(invalid data)!"); + } // get offset tb_int_t offset = 0; - if (lua_isnumber(lua, 2)) + if (lua_isnumber(lua, 2)) { offset = (tb_int_t)lua_tointeger(lua, 2); - else + } else { xm_libc_return_error(lua, "libc.setbyte(invalid offset)!"); + } // set byte - if (lua_isnumber(lua, 3)) + if (lua_isnumber(lua, 3)) { ((tb_byte_t *)data)[offset] = (tb_byte_t)lua_tointeger(lua, 3); - else + } else { xm_libc_return_error(lua, "libc.setbyte(invalid value)!"); + } return 0; } diff --git a/core/src/xmake/libc/strndup.c b/core/src/xmake/libc/strndup.c index f61cebb2c..138a4907f 100644 --- a/core/src/xmake/libc/strndup.c +++ b/core/src/xmake/libc/strndup.c @@ -38,16 +38,18 @@ tb_int_t xm_libc_strndup(lua_State *lua) { // do strndup tb_char_t const *s = tb_null; - if (lua_isnumber(lua, 1)) + if (lua_isnumber(lua, 1)) { s = (tb_char_t const *)(tb_size_t)lua_tointeger(lua, 1); - else if (lua_isstring(lua, 2)) + } else if (lua_isstring(lua, 2)) { s = lua_tostring(lua, 2); - else + } else { xm_libc_return_error(lua, "libc.strndup(invalid args)!"); + } tb_int_t n = (tb_int_t)lua_tointeger(lua, 2); - if (s && n >= 0) + if (s && n >= 0) { lua_pushlstring(lua, s, n); - else + } else { lua_pushliteral(lua, ""); + } return 1; } diff --git a/core/src/xmake/lz4/block_compress.c b/core/src/xmake/lz4/block_compress.c index 53b592a22..34fb06def 100644 --- a/core/src/xmake/lz4/block_compress.c +++ b/core/src/xmake/lz4/block_compress.c @@ -39,10 +39,12 @@ tb_int_t xm_lz4_block_compress(lua_State *lua) { // get data and size tb_int_t size = 0; tb_byte_t const *data = tb_null; - if (xm_lua_isinteger(lua, 1)) + if (xm_lua_isinteger(lua, 1)) { data = (tb_byte_t const *)(tb_size_t)(tb_long_t)lua_tointeger(lua, 1); - if (xm_lua_isinteger(lua, 2)) + } + if (xm_lua_isinteger(lua, 2)) { size = (tb_int_t)lua_tointeger(lua, 2); + } if (!data || !size || size > LZ4_MAX_INPUT_SIZE) { lua_pushnil(lua); lua_pushfstring(lua, "invalid data(%p) and size(%d)!", data, (tb_int_t)size); @@ -73,7 +75,8 @@ tb_int_t xm_lz4_block_compress(lua_State *lua) { output_data = tb_null; } - if (!ok) + if (!ok) { lua_pushnil(lua); + } return 1; } diff --git a/core/src/xmake/lz4/block_decompress.c b/core/src/xmake/lz4/block_decompress.c index 2a6ed1d20..07c80236d 100644 --- a/core/src/xmake/lz4/block_decompress.c +++ b/core/src/xmake/lz4/block_decompress.c @@ -39,10 +39,12 @@ tb_int_t xm_lz4_block_decompress(lua_State *lua) { // get data and size tb_size_t size = 0; tb_byte_t const *data = tb_null; - if (xm_lua_isinteger(lua, 1)) + if (xm_lua_isinteger(lua, 1)) { data = (tb_byte_t const *)(tb_size_t)(tb_long_t)lua_tointeger(lua, 1); - if (xm_lua_isinteger(lua, 2)) + } + if (xm_lua_isinteger(lua, 2)) { size = (tb_size_t)lua_tointeger(lua, 2); + } if (!data || !size) { lua_pushnil(lua); lua_pushfstring(lua, "invalid data(%p) and size(%d)!", data, (tb_int_t)size); @@ -78,7 +80,8 @@ tb_int_t xm_lz4_block_decompress(lua_State *lua) { output_data = tb_null; } - if (!ok) + if (!ok) { lua_pushnil(lua); + } return 1; } diff --git a/core/src/xmake/lz4/compress.c b/core/src/xmake/lz4/compress.c index 69af51113..dffda1f23 100644 --- a/core/src/xmake/lz4/compress.c +++ b/core/src/xmake/lz4/compress.c @@ -39,10 +39,12 @@ tb_int_t xm_lz4_compress(lua_State *lua) { // get data and size tb_size_t size = 0; tb_byte_t const *data = tb_null; - if (xm_lua_isinteger(lua, 1)) + if (xm_lua_isinteger(lua, 1)) { data = (tb_byte_t const *)(tb_size_t)(tb_long_t)lua_tointeger(lua, 1); - if (xm_lua_isinteger(lua, 2)) + } + if (xm_lua_isinteger(lua, 2)) { size = (tb_size_t)lua_tointeger(lua, 2); + } if (!data || !size) { lua_pushnil(lua); lua_pushfstring(lua, "invalid data(%p) and size(%d)!", data, (tb_int_t)size); diff --git a/core/src/xmake/lz4/compress_file.c b/core/src/xmake/lz4/compress_file.c index 48596e17b..552ece99d 100644 --- a/core/src/xmake/lz4/compress_file.c +++ b/core/src/xmake/lz4/compress_file.c @@ -70,13 +70,15 @@ tb_int_t xm_lz4_compress_file(lua_State *lua) { } } tb_assert_and_check_break(oreal >= 0); - } else + } else { break; + } write_ok = tb_true; } - if (tb_stream_beof(istream) && write_ok) + if (tb_stream_beof(istream) && write_ok) { ok = tb_true; + } } // exit stream diff --git a/core/src/xmake/lz4/compress_stream_close.c b/core/src/xmake/lz4/compress_stream_close.c index d1f534cde..4bea381e9 100644 --- a/core/src/xmake/lz4/compress_stream_close.c +++ b/core/src/xmake/lz4/compress_stream_close.c @@ -37,8 +37,9 @@ tb_int_t xm_lz4_compress_stream_close(lua_State *lua) { tb_assert_and_check_return_val(lua, 0); // is pointer? - if (!xm_lua_ispointer(lua, 1)) + if (!xm_lua_ispointer(lua, 1)) { return 0; + } // get the stream xm_lz4_cstream_t *stream = (xm_lz4_cstream_t *)xm_lua_topointer(lua, 1); diff --git a/core/src/xmake/lz4/compress_stream_open.c b/core/src/xmake/lz4/compress_stream_open.c index d4ac50667..536e259e0 100644 --- a/core/src/xmake/lz4/compress_stream_open.c +++ b/core/src/xmake/lz4/compress_stream_open.c @@ -37,9 +37,10 @@ tb_int_t xm_lz4_compress_stream_open(lua_State *lua) { tb_assert_and_check_return_val(lua, 0); xm_lz4_cstream_t *stream = xm_lz4_cstream_init(); - if (stream) + if (stream) { xm_lua_pushpointer(lua, (tb_pointer_t)stream); - else + } else { lua_pushnil(lua); + } return 1; } diff --git a/core/src/xmake/lz4/compress_stream_read.c b/core/src/xmake/lz4/compress_stream_read.c index ff1315c3e..6d0515eb5 100644 --- a/core/src/xmake/lz4/compress_stream_read.c +++ b/core/src/xmake/lz4/compress_stream_read.c @@ -50,8 +50,9 @@ tb_int_t xm_lz4_compress_stream_read(lua_State *lua) { // get data tb_byte_t *data = tb_null; - if (xm_lua_isinteger(lua, 2)) + if (xm_lua_isinteger(lua, 2)) { data = (tb_byte_t *)(tb_size_t)(tb_long_t)lua_tointeger(lua, 2); + } if (!data) { lua_pushinteger(lua, -1); lua_pushfstring(lua, "invalid data(%p)!", data); @@ -61,8 +62,9 @@ tb_int_t xm_lz4_compress_stream_read(lua_State *lua) { // get size tb_long_t size = 0; - if (xm_lua_isinteger(lua, 3)) + if (xm_lua_isinteger(lua, 3)) { size = (tb_long_t)lua_tointeger(lua, 3); + } if (size <= 0) { lua_pushinteger(lua, -1); lua_pushfstring(lua, "invalid size(%d)!", (tb_int_t)size); diff --git a/core/src/xmake/lz4/compress_stream_write.c b/core/src/xmake/lz4/compress_stream_write.c index 730a4f986..8a4276318 100644 --- a/core/src/xmake/lz4/compress_stream_write.c +++ b/core/src/xmake/lz4/compress_stream_write.c @@ -51,10 +51,12 @@ tb_int_t xm_lz4_compress_stream_write(lua_State *lua) { // get data and size tb_size_t size = 0; tb_byte_t const *data = tb_null; - if (xm_lua_isinteger(lua, 2)) + if (xm_lua_isinteger(lua, 2)) { data = (tb_byte_t const *)(tb_size_t)(tb_long_t)lua_tointeger(lua, 2); - if (xm_lua_isinteger(lua, 3)) + } + if (xm_lua_isinteger(lua, 3)) { size = (tb_size_t)lua_tointeger(lua, 3); + } if (!data || !size) { lua_pushinteger(lua, -1); lua_pushfstring(lua, "invalid data(%p) and size(%d)!", data, (tb_int_t)size); @@ -64,8 +66,9 @@ tb_int_t xm_lz4_compress_stream_write(lua_State *lua) { // is end? tb_bool_t end = tb_false; - if (lua_isboolean(lua, 4)) + if (lua_isboolean(lua, 4)) { end = lua_toboolean(lua, 4); + } // write data tb_long_t real = xm_lz4_cstream_write(stream, data, size, end); diff --git a/core/src/xmake/lz4/decompress.c b/core/src/xmake/lz4/decompress.c index 51a50c112..500e932a1 100644 --- a/core/src/xmake/lz4/decompress.c +++ b/core/src/xmake/lz4/decompress.c @@ -39,10 +39,12 @@ tb_int_t xm_lz4_decompress(lua_State *lua) { // get data and size tb_size_t size = 0; tb_byte_t const *data = tb_null; - if (xm_lua_isinteger(lua, 1)) + if (xm_lua_isinteger(lua, 1)) { data = (tb_byte_t const *)(tb_size_t)(tb_long_t)lua_tointeger(lua, 1); - if (xm_lua_isinteger(lua, 2)) + } + if (xm_lua_isinteger(lua, 2)) { size = (tb_size_t)lua_tointeger(lua, 2); + } if (!data || !size) { lua_pushnil(lua); lua_pushfstring(lua, "invalid data(%p) and size(%d)!", data, (tb_int_t)size); @@ -59,8 +61,9 @@ tb_int_t xm_lz4_decompress(lua_State *lua) { tb_buffer_init(&result); code = LZ4F_createDecompressionContext(&ctx, LZ4F_VERSION); - if (LZ4F_isError(code)) + if (LZ4F_isError(code)) { break; + } tb_byte_t buffer[8192]; tb_bool_t failed = tb_false; @@ -73,8 +76,9 @@ tb_int_t xm_lz4_decompress(lua_State *lua) { break; } - if (buffer_size == 0) + if (buffer_size == 0) { break; + } data += advance; size -= advance; diff --git a/core/src/xmake/lz4/decompress_file.c b/core/src/xmake/lz4/decompress_file.c index 7d91c5be4..accc993f8 100644 --- a/core/src/xmake/lz4/decompress_file.c +++ b/core/src/xmake/lz4/decompress_file.c @@ -70,13 +70,15 @@ tb_int_t xm_lz4_decompress_file(lua_State *lua) { } } tb_assert_and_check_break(oreal >= 0); - } else + } else { break; + } write_ok = tb_true; } - if (tb_stream_beof(istream) && write_ok) + if (tb_stream_beof(istream) && write_ok) { ok = tb_true; + } } // exit stream diff --git a/core/src/xmake/lz4/decompress_stream_close.c b/core/src/xmake/lz4/decompress_stream_close.c index 89c868c53..c50cd4268 100644 --- a/core/src/xmake/lz4/decompress_stream_close.c +++ b/core/src/xmake/lz4/decompress_stream_close.c @@ -37,8 +37,9 @@ tb_int_t xm_lz4_decompress_stream_close(lua_State *lua) { tb_assert_and_check_return_val(lua, 0); // is pointer? - if (!xm_lua_ispointer(lua, 1)) + if (!xm_lua_ispointer(lua, 1)) { return 0; + } // get the stream xm_lz4_dstream_t *stream = (xm_lz4_dstream_t *)xm_lua_topointer(lua, 1); diff --git a/core/src/xmake/lz4/decompress_stream_open.c b/core/src/xmake/lz4/decompress_stream_open.c index eb3db7193..7a37f4378 100644 --- a/core/src/xmake/lz4/decompress_stream_open.c +++ b/core/src/xmake/lz4/decompress_stream_open.c @@ -37,9 +37,10 @@ tb_int_t xm_lz4_decompress_stream_open(lua_State *lua) { tb_assert_and_check_return_val(lua, 0); xm_lz4_dstream_t *stream = xm_lz4_dstream_init(); - if (stream) + if (stream) { xm_lua_pushpointer(lua, (tb_pointer_t)stream); - else + } else { lua_pushnil(lua); + } return 1; } diff --git a/core/src/xmake/lz4/decompress_stream_read.c b/core/src/xmake/lz4/decompress_stream_read.c index 85ecdbe9f..eb095d4e0 100644 --- a/core/src/xmake/lz4/decompress_stream_read.c +++ b/core/src/xmake/lz4/decompress_stream_read.c @@ -50,8 +50,9 @@ tb_int_t xm_lz4_decompress_stream_read(lua_State *lua) { // get data tb_byte_t *data = tb_null; - if (xm_lua_isinteger(lua, 2)) + if (xm_lua_isinteger(lua, 2)) { data = (tb_byte_t *)(tb_size_t)(tb_long_t)lua_tointeger(lua, 2); + } if (!data) { lua_pushinteger(lua, -1); lua_pushfstring(lua, "invalid data(%p)!", data); @@ -61,8 +62,9 @@ tb_int_t xm_lz4_decompress_stream_read(lua_State *lua) { // get size tb_long_t size = 0; - if (xm_lua_isinteger(lua, 3)) + if (xm_lua_isinteger(lua, 3)) { size = (tb_long_t)lua_tointeger(lua, 3); + } if (size <= 0) { lua_pushinteger(lua, -1); lua_pushfstring(lua, "invalid size(%d)!", (tb_int_t)size); diff --git a/core/src/xmake/lz4/decompress_stream_write.c b/core/src/xmake/lz4/decompress_stream_write.c index 4359a41d7..94be0533e 100644 --- a/core/src/xmake/lz4/decompress_stream_write.c +++ b/core/src/xmake/lz4/decompress_stream_write.c @@ -51,10 +51,12 @@ tb_int_t xm_lz4_decompress_stream_write(lua_State *lua) { // get data and size tb_size_t size = 0; tb_byte_t const *data = tb_null; - if (xm_lua_isinteger(lua, 2)) + if (xm_lua_isinteger(lua, 2)) { data = (tb_byte_t const *)(tb_size_t)(tb_long_t)lua_tointeger(lua, 2); - if (xm_lua_isinteger(lua, 3)) + } + if (xm_lua_isinteger(lua, 3)) { size = (tb_size_t)lua_tointeger(lua, 3); + } if (!data || !size) { lua_pushinteger(lua, -1); lua_pushfstring(lua, "invalid data(%p) and size(%d)!", data, (tb_int_t)size); diff --git a/core/src/xmake/os/args.c b/core/src/xmake/os/args.c index 8b2c002c9..b48445c89 100644 --- a/core/src/xmake/os/args.c +++ b/core/src/xmake/os/args.c @@ -43,29 +43,33 @@ static tb_void_t tb_os_args_append( tb_bool_t wrap_quote = tb_false; if (!nowrap) { while ((ch = *p)) { - if (ch == ' ') + if (ch == ' ') { wrap_quote = tb_true; + } p++; } } // wrap begin quote - if (wrap_quote) + if (wrap_quote) { tb_string_chrcat(result, '\"'); + } // escape characters p = cstr; while ((ch = *p)) { // escape '"' or '\\' - if (ch == '\"' || ((escape || wrap_quote) && ch == '\\')) + if (ch == '\"' || ((escape || wrap_quote) && ch == '\\')) { tb_string_chrcat(result, '\\'); + } tb_string_chrcat(result, ch); p++; } // wrap end quote - if (wrap_quote) + if (wrap_quote) { tb_string_chrcat(result, '\"'); + } } /* ////////////////////////////////////////////////////////////////////////////////////// @@ -105,42 +109,46 @@ tb_int_t xm_os_args(lua_State *lua) { tb_size_t n = (tb_size_t)lua_objlen(lua, 1); for (i = 1; i <= n; i++) { // add space - if (i != 1) + if (i != 1) { tb_string_chrcat(&result, ' '); + } // add argument lua_pushnumber(lua, (tb_int_t)i); lua_rawget(lua, 1); - if (lua_istable(lua, -1)) // is path instance? - { + if (lua_istable(lua, -1)) { // is path instance? lua_pushstring(lua, "_STR"); lua_gettable(lua, -2); size_t size = 0; tb_char_t const *cstr = luaL_checklstring(lua, -1, &size); - if (cstr && size) + if (cstr && size) { tb_os_args_append(&result, cstr, size, escape, nowrap); + } lua_pop(lua, 1); } else { size_t size = 0; tb_char_t const *cstr = luaL_checklstring(lua, -1, &size); - if (cstr && size) + if (cstr && size) { tb_os_args_append(&result, cstr, size, escape, nowrap); + } } lua_pop(lua, 1); } } else { size_t size = 0; tb_char_t const *cstr = luaL_checklstring(lua, 1, &size); - if (cstr && size) + if (cstr && size) { tb_os_args_append(&result, cstr, size, escape, nowrap); + } } // return result tb_size_t size = tb_string_size(&result); - if (size) + if (size) { lua_pushlstring(lua, tb_string_cstr(&result), size); - else + } else { lua_pushliteral(lua, ""); + } tb_string_exit(&result); return 1; } diff --git a/core/src/xmake/os/argv.c b/core/src/xmake/os/argv.c index f7230d057..12b1f88ec 100644 --- a/core/src/xmake/os/argv.c +++ b/core/src/xmake/os/argv.c @@ -56,8 +56,9 @@ tb_int_t xm_os_argv(lua_State *lua) { lua_newtable(lua); // init arg - if (!tb_string_init(&arg)) + if (!tb_string_init(&arg)) { break; + } // parse command to the arguments tb_int_t i = 1; @@ -73,19 +74,13 @@ tb_int_t xm_os_argv(lua_State *lua) { if (!quote && (ch == '\"' || ch == '\'')) { quote = ch; skip = 1; - } - // leave quote? - else if (ch == quote) { + } else if (ch == quote) { // leave quote? quote = 0; skip = 1; - } - // escape charactor? only escape \\, \" - else if (ch == '\\' && (p[1] == '\\' || p[1] == '\"')) { + } else if (ch == '\\' && (p[1] == '\\' || p[1] == '\"')) { // escape character? only escape \\ and \" escape = 1; skip = 1; - } - // is argument end with ' '? - else if (!quote && tb_isspace(ch)) { + } else if (!quote && tb_isspace(ch)) { // is argument end with ' '? // save this argument tb_string_ltrim(&arg); if (tb_string_size(&arg)) { @@ -100,14 +95,16 @@ tb_int_t xm_os_argv(lua_State *lua) { } // save this charactor to argument - if (splitonly || !skip) + if (splitonly || !skip) { tb_string_chrcat(&arg, ch); + } // step and cancel escape - if (escape == 1) + if (escape == 1) { escape++; - else if (escape == 2) + } else if (escape == 2) { escape = 0; + } // clear skip skip = 0; diff --git a/core/src/xmake/os/cpdir.c b/core/src/xmake/os/cpdir.c index 0df435436..2ea0be1ed 100644 --- a/core/src/xmake/os/cpdir.c +++ b/core/src/xmake/os/cpdir.c @@ -44,12 +44,14 @@ tb_int_t xm_os_cpdir(lua_State *lua) { // init copy flags tb_size_t flags = TB_FILE_COPY_NONE; tb_bool_t is_symlink = lua_toboolean(lua, 3); - if (is_symlink) + if (is_symlink) { flags |= TB_FILE_COPY_LINK; + } tb_bool_t copy_if_different = lua_toboolean(lua, 4); - if (copy_if_different) + if (copy_if_different) { flags |= TB_FILE_COPY_IF_DIFFERENT; + } // do copy lua_pushboolean(lua, tb_directory_copy(src, dst, flags)); diff --git a/core/src/xmake/os/cpfile.c b/core/src/xmake/os/cpfile.c index 7291385a7..d3c62832e 100644 --- a/core/src/xmake/os/cpfile.c +++ b/core/src/xmake/os/cpfile.c @@ -44,16 +44,19 @@ tb_int_t xm_os_cpfile(lua_State *lua) { // init copy flags tb_size_t flags = TB_FILE_COPY_NONE; tb_bool_t is_symlink = lua_toboolean(lua, 3); - if (is_symlink) + if (is_symlink) { flags |= TB_FILE_COPY_LINK; + } tb_bool_t is_writeable = lua_toboolean(lua, 4); - if (is_writeable) + if (is_writeable) { flags |= TB_FILE_COPY_WRITEABLE; + } tb_bool_t copy_if_different = lua_toboolean(lua, 5); - if (copy_if_different) + if (copy_if_different) { flags |= TB_FILE_COPY_IF_DIFFERENT; + } // do copy lua_pushboolean(lua, tb_file_copy(src, dst, flags)); diff --git a/core/src/xmake/os/cpuinfo.c b/core/src/xmake/os/cpuinfo.c index f8ef7d46b..7be9172cc 100644 --- a/core/src/xmake/os/cpuinfo.c +++ b/core/src/xmake/os/cpuinfo.c @@ -93,8 +93,9 @@ static tb_float_t xm_os_cpuinfo_usagerate() { } usagerate += total > 0 ? ((tb_float_t)use / (tb_float_t)total) : 0; } - if (s_cpuinfo_prev) + if (s_cpuinfo_prev) { vm_deallocate(mach_task_self(), (vm_address_t)s_cpuinfo_prev, sizeof(integer_t) * s_cpuinfo_count_prev); + } s_time = tb_mclock(); s_cpuinfo_prev = cpuinfo; s_cpuinfo_count_prev = cpuinfo_count; @@ -119,8 +120,9 @@ static tb_float_t xm_os_cpuinfo_usagerate() { tb_uint64_t kernel_total = kernel_diff - idle_diff; // sometimes kernel_time > idle_time - if (sys_total > 0) + if (sys_total > 0) { usagerate = (tb_float_t)((tb_double_t)(kernel_total + user_diff) / sys_total); + } } idle_prev = idle; @@ -175,8 +177,9 @@ static tb_float_t xm_os_cpuinfo_usagerate() { if (total_prev > 0 && active_prev > 0) { tb_int64_t total_diff = total - total_prev; tb_int64_t active_diff = active - active_prev; - if (total_diff > 0) + if (total_diff > 0) { usagerate = (tb_float_t)((tb_double_t)active_diff / total_diff); + } } total_prev = total; active_prev = active; @@ -214,8 +217,9 @@ static tb_float_t xm_os_cpuinfo_usagerate() { if (total_prev > 0 && active_prev > 0) { tb_int64_t total_diff = total - total_prev; tb_int64_t active_diff = active - active_prev; - if (total_diff > 0) + if (total_diff > 0) { usagerate = (tb_float_t)((tb_double_t)active_diff / total_diff); + } } total_prev = total; active_prev = active; diff --git a/core/src/xmake/os/curdir.c b/core/src/xmake/os/curdir.c index 2d27cf905..987aa60c9 100644 --- a/core/src/xmake/os/curdir.c +++ b/core/src/xmake/os/curdir.c @@ -38,9 +38,10 @@ tb_int_t xm_os_curdir(lua_State *lua) { // os.curdir() tb_char_t path[TB_PATH_MAXN]; - if (tb_directory_current(path, sizeof(path))) + if (tb_directory_current(path, sizeof(path))) { lua_pushstring(lua, path); - else + } else { lua_pushnil(lua); + } return 1; } diff --git a/core/src/xmake/os/filesize.c b/core/src/xmake/os/filesize.c index a99651fbf..c746d96ed 100644 --- a/core/src/xmake/os/filesize.c +++ b/core/src/xmake/os/filesize.c @@ -42,9 +42,10 @@ tb_int_t xm_os_filesize(lua_State *lua) { // os.filesize(path) tb_file_info_t info = { 0 }; - if (tb_file_info(path, &info) && (info.type == TB_FILE_TYPE_FILE)) + if (tb_file_info(path, &info) && (info.type == TB_FILE_TYPE_FILE)) { lua_pushinteger(lua, (lua_Integer)info.size); - else + } else { lua_pushinteger(lua, 0); + } return 1; } diff --git a/core/src/xmake/os/find.c b/core/src/xmake/os/find.c index 2ed5611ad..144ab4daa 100644 --- a/core/src/xmake/os/find.c +++ b/core/src/xmake/os/find.c @@ -46,8 +46,9 @@ static tb_long_t xm_os_find_walk(tb_char_t const *path, tb_file_info_t const *in tb_assert_and_check_return_val(pattern, TB_DIRECTORY_WALK_CODE_END); // remove ./ for path - if (path[0] == '.' && (path[1] == '/' || path[1] == '\\')) + if (path[0] == '.' && (path[1] == '/' || path[1] == '\\')) { path = path + 2; + } // the match mode tb_long_t mode = tuple[2].l; @@ -60,8 +61,9 @@ static tb_long_t xm_os_find_walk(tb_char_t const *path, tb_file_info_t const *in // we can ignore it directly if this path is file, but we need directory tb_size_t needtype = (mode == 1) ? TB_FILE_TYPE_DIRECTORY : ((mode == 0) ? TB_FILE_TYPE_FILE : (TB_FILE_TYPE_FILE | TB_FILE_TYPE_DIRECTORY)); - if (info->type == TB_FILE_TYPE_FILE && needtype == TB_FILE_TYPE_DIRECTORY) + if (info->type == TB_FILE_TYPE_FILE && needtype == TB_FILE_TYPE_DIRECTORY) { return TB_DIRECTORY_WALK_CODE_CONTINUE; + } // do path:match(pattern) lua_getfield(lua, -1, "match"); @@ -88,8 +90,9 @@ static tb_long_t xm_os_find_walk(tb_char_t const *path, tb_file_info_t const *in tb_assert(rootlen + 1 <= tb_strlen(path)); // skip the rootdir if not "." - if (tb_strcmp(rootdir, ".")) + if (tb_strcmp(rootdir, ".")) { path += rootlen + 1; + } // exclude paths tb_int_t i = 0; @@ -140,18 +143,21 @@ static tb_long_t xm_os_find_walk(tb_char_t const *path, tb_file_info_t const *in // is continue? tb_bool_t is_continue = lua_toboolean(lua, -1); lua_pop(lua, 1); - if (!is_continue) + if (!is_continue) { return TB_DIRECTORY_WALK_CODE_END; + } } matched = tb_true; } } // we do not recurse sub-directories if this path has been excluded and it's directory - else + else { skip_recursion = tb_true; + } } - if (!matched) + if (!matched) { lua_pop(lua, 1); + } return skip_recursion ? TB_DIRECTORY_WALK_CODE_SKIP_RECURSION : TB_DIRECTORY_WALK_CODE_CONTINUE; } /* ////////////////////////////////////////////////////////////////////////////////////// diff --git a/core/src/xmake/os/getenv.c b/core/src/xmake/os/getenv.c index dc5578ebe..4d82e0524 100644 --- a/core/src/xmake/os/getenv.c +++ b/core/src/xmake/os/getenv.c @@ -53,8 +53,9 @@ tb_int_t xm_os_getenv(lua_State *lua) { // init values tb_string_t values; - if (!tb_string_init(&values)) + if (!tb_string_init(&values)) { return 0; + } // init environment tb_environment_ref_t environment = tb_environment_init(); @@ -65,10 +66,11 @@ tb_int_t xm_os_getenv(lua_State *lua) { tb_bool_t is_first = tb_true; tb_for_all_if(tb_char_t const *, value, environment, value) { // append separator - if (!is_first) + if (!is_first) { tb_string_chrcat(&values, XM_OS_ENV_SEP); - else + } else { is_first = tb_false; + } // append value tb_string_cstrcat(&values, value); @@ -80,10 +82,11 @@ tb_int_t xm_os_getenv(lua_State *lua) { } // save result - if (tb_string_size(&values)) + if (tb_string_size(&values)) { lua_pushstring(lua, tb_string_cstr(&values)); - else + } else { lua_pushnil(lua); + } // exit values tb_string_exit(&values); diff --git a/core/src/xmake/os/getenvs.c b/core/src/xmake/os/getenvs.c index 70c6af7bf..1576c101d 100644 --- a/core/src/xmake/os/getenvs.c +++ b/core/src/xmake/os/getenvs.c @@ -63,12 +63,14 @@ static tb_void_t xm_os_getenvs_trim(tb_char_t const **sstr, tb_char_t const **es tb_char_t const *e = *estr; // trim left - while (p < e && tb_isspace(*p)) + while (p < e && tb_isspace(*p)) { p++; + } // trim right - while (e > p && tb_isspace(*(e - 1))) + while (e > p && tb_isspace(*(e - 1))) { e--; + } // save trimmed string *sstr = p; @@ -93,8 +95,9 @@ static tb_void_t xm_os_getenvs_process_line(lua_State *lua, tb_char_t const *lin // trim key xm_os_getenvs_trim(&key_start, &key_end); - if (key_start >= key_end) + if (key_start >= key_end) { return; + } // trim value xm_os_getenvs_trim(&value_start, &value_end); @@ -137,8 +140,9 @@ tb_int_t xm_os_getenvs(lua_State *lua) { while (*p) { n = tb_wcslen(p); if (n + 1 < tb_arrayn(line)) { - if (tb_wtoa(line, p, tb_arrayn(line)) >= 0) + if (tb_wtoa(line, p, tb_arrayn(line)) >= 0) { xm_os_getenvs_process_line(lua, line); + } } else { if (!data) { maxn = n + 1; @@ -149,13 +153,15 @@ tb_int_t xm_os_getenvs(lua_State *lua) { } tb_assert_and_check_break(data); - if (tb_wtoa(data, p, maxn) >= 0) + if (tb_wtoa(data, p, maxn) >= 0) { xm_os_getenvs_process_line(lua, data); + } } p += n + 1; } - if (data && data != line) + if (data && data != line) { tb_free(data); + } data = tb_null; } #else diff --git a/core/src/xmake/os/getown.c b/core/src/xmake/os/getown.c index ef7846ad1..3d002cb96 100644 --- a/core/src/xmake/os/getown.c +++ b/core/src/xmake/os/getown.c @@ -50,8 +50,9 @@ tb_int_t xm_os_getown(lua_State *lua) { // get stat struct stat sts; - if (stat(pathname, &sts) != 0) + if (stat(pathname, &sts) != 0) { return 0; + } // push lua_newtable(lua); diff --git a/core/src/xmake/os/meminfo.c b/core/src/xmake/os/meminfo.c index 1e6e5f422..44fbb7770 100644 --- a/core/src/xmake/os/meminfo.c +++ b/core/src/xmake/os/meminfo.c @@ -103,8 +103,9 @@ static tb_bool_t xm_os_meminfo_stats(tb_int_t *ptotalsize, tb_int_t *pavailsize) tb_int64_t freesize = xm_os_meminfo_get_value(buffer, "MemFree:"); tb_int64_t buffersize = xm_os_meminfo_get_value(buffer, "Buffers:"); tb_int64_t shmemsize = xm_os_meminfo_get_value(buffer, "Shmem:"); - if (cachesize >= 0 && freesize >= 0 && buffersize >= 0 && shmemsize >= 0) + if (cachesize >= 0 && freesize >= 0 && buffersize >= 0 && shmemsize >= 0) { availsize = freesize + buffersize + cachesize - shmemsize; + } } if (totalsize > 0 && availsize >= 0) { *ptotalsize = (tb_int_t)(totalsize / 1024); @@ -134,19 +135,22 @@ static tb_bool_t xm_os_meminfo_stats(tb_int_t *ptotalsize, tb_int_t *pavailsize) #elif defined(TB_CONFIG_OS_BSD) && !defined(__OpenBSD__) unsigned long totalsize; size_t size = sizeof(totalsize); - if (sysctlbyname("hw.physmem", &totalsize, &size, tb_null, 0) != 0) + if (sysctlbyname("hw.physmem", &totalsize, &size, tb_null, 0) != 0) { return tb_false; + } // http://web.mit.edu/freebsd/head/usr.bin/systat/vmstat.c tb_uint32_t v_free_count; size = sizeof(v_free_count); - if (sysctlbyname("vm.stats.vm.v_free_count", &v_free_count, &size, tb_null, 0) != 0) + if (sysctlbyname("vm.stats.vm.v_free_count", &v_free_count, &size, tb_null, 0) != 0) { return tb_false; + } tb_uint32_t v_inactive_count; size = sizeof(v_inactive_count); - if (sysctlbyname("vm.stats.vm.v_inactive_count", &v_inactive_count, &size, tb_null, 0) != 0) + if (sysctlbyname("vm.stats.vm.v_inactive_count", &v_inactive_count, &size, tb_null, 0) != 0) { return tb_false; + } *ptotalsize = (tb_int_t)(totalsize / (1024 * 1024)); *pavailsize = (tb_int_t)(((tb_int64_t)(v_free_count + v_inactive_count) * tb_page_size()) / (1024 * 1024)); diff --git a/core/src/xmake/os/mkdir.c b/core/src/xmake/os/mkdir.c index 19507b5aa..9f8b3399d 100644 --- a/core/src/xmake/os/mkdir.c +++ b/core/src/xmake/os/mkdir.c @@ -42,10 +42,11 @@ tb_int_t xm_os_mkdir(lua_State *lua) { // os.mkdir(path) tb_file_info_t info = { 0 }; - if (!tb_file_info(path, &info) || (info.type != TB_FILE_TYPE_DIRECTORY)) + if (!tb_file_info(path, &info) || (info.type != TB_FILE_TYPE_DIRECTORY)) { lua_pushboolean(lua, tb_directory_create(path)); - else + } else { lua_pushboolean(lua, tb_true); + } return 1; } diff --git a/core/src/xmake/os/mtime.c b/core/src/xmake/os/mtime.c index 73014666b..0dd10c7ca 100644 --- a/core/src/xmake/os/mtime.c +++ b/core/src/xmake/os/mtime.c @@ -42,9 +42,10 @@ tb_int_t xm_os_mtime(lua_State *lua) { // os.mtime(path) tb_file_info_t info = { 0 }; - if (tb_file_info(path, &info)) + if (tb_file_info(path, &info)) { lua_pushinteger(lua, (lua_Integer)info.mtime); - else + } else { lua_pushinteger(lua, 0); + } return 1; } diff --git a/core/src/xmake/os/readlink.c b/core/src/xmake/os/readlink.c index 603ab7104..c1a45cf4b 100644 --- a/core/src/xmake/os/readlink.c +++ b/core/src/xmake/os/readlink.c @@ -57,15 +57,17 @@ tb_int_t xm_os_readlink(lua_State *lua) { if (size > 0 && size < maxn) { data[size] = '\0'; lua_pushstring(lua, data); - } else + } else { lua_pushnil(lua); + } tb_free(data); } } else if (size >= 0 && size < TB_PATH_MAXN) { srcpath[size] = '\0'; lua_pushstring(lua, srcpath); - } else + } else { lua_pushnil(lua); + } #endif return 1; diff --git a/core/src/xmake/os/rmdir.c b/core/src/xmake/os/rmdir.c index f04ba2a9c..21b7005a8 100644 --- a/core/src/xmake/os/rmdir.c +++ b/core/src/xmake/os/rmdir.c @@ -57,8 +57,9 @@ static tb_long_t xm_os_rmdir_remove(tb_char_t const *path, tb_file_info_t const tb_trace_d("path: %s, emptydir: %u", path, is_emptydir); // remove empty directory - if (is_emptydir) + if (is_emptydir) { tb_directory_remove(path); + } } return TB_DIRECTORY_WALK_CODE_CONTINUE; } @@ -82,8 +83,9 @@ tb_int_t xm_os_rmdir(lua_State *lua) { // remove empty root directory tb_bool_t is_emptydir = tb_true; tb_directory_walk(path, tb_false, tb_true, xm_os_rmdir_empty, &is_emptydir); - if (is_emptydir) + if (is_emptydir) { tb_directory_remove(path); + } tb_trace_d("path: %s, emptydir: %u", path, is_emptydir); diff --git a/core/src/xmake/os/signal.c b/core/src/xmake/os/signal.c index 4d9e8a4c5..64f68762a 100644 --- a/core/src/xmake/os/signal.c +++ b/core/src/xmake/os/signal.c @@ -78,8 +78,9 @@ static tb_void_t xm_os_signal_handler_impl(tb_int_t signo) { #if defined(TB_CONFIG_OS_WINDOWS) static BOOL WINAPI xm_os_signal_handler(DWORD ctrl_type) { - if (ctrl_type == CTRL_C_EVENT) + if (ctrl_type == CTRL_C_EVENT) { xm_os_signal_handler_impl(XM_OS_SIGINT); + } return TRUE; } #elif defined(SIGINT) @@ -92,8 +93,9 @@ static tb_void_t xm_os_signal_handler(tb_int_t signo_native) { default: break; } - if (signo >= 0) + if (signo >= 0) { xm_os_signal_handler_impl(signo); + } } #endif @@ -106,10 +108,11 @@ tb_int_t xm_os_signal(lua_State *lua) { tb_int_t handler = XM_OS_SIGFUN; // check signal handler - if (lua_isnumber(lua, 2)) + if (lua_isnumber(lua, 2)) { handler = (tb_int_t)luaL_checkinteger(lua, 2); - else if (!lua_isfunction(lua, 2)) + } else if (!lua_isfunction(lua, 2)) { return 0; + } // save signal handler tb_int_t signo = (tb_int_t)luaL_checkinteger(lua, 1); @@ -121,8 +124,9 @@ tb_int_t xm_os_signal(lua_State *lua) { } #if defined(TB_CONFIG_OS_WINDOWS) - if (signo != XM_OS_SIGINT) + if (signo != XM_OS_SIGINT) { return 0; + } switch (handler) { case XM_OS_SIGFUN: diff --git a/core/src/xmake/os/sleep.c b/core/src/xmake/os/sleep.c index 0c4172b43..0c8fa135e 100644 --- a/core/src/xmake/os/sleep.c +++ b/core/src/xmake/os/sleep.c @@ -36,7 +36,8 @@ tb_int_t xm_os_sleep(lua_State *lua) { tb_assert_and_check_return_val(lua, 0); tb_long_t interval = (tb_long_t)luaL_checklong(lua, 1); - if (interval >= 0) + if (interval >= 0) { tb_msleep(interval); + } return 0; } diff --git a/core/src/xmake/os/tmpdir.c b/core/src/xmake/os/tmpdir.c index 4396603d4..6d20fc546 100644 --- a/core/src/xmake/os/tmpdir.c +++ b/core/src/xmake/os/tmpdir.c @@ -38,9 +38,10 @@ tb_int_t xm_os_tmpdir(lua_State *lua) { // os.tmpdir() tb_char_t path[TB_PATH_MAXN]; - if (tb_directory_temporary(path, sizeof(path))) + if (tb_directory_temporary(path, sizeof(path))) { lua_pushstring(lua, path); - else + } else { lua_pushnil(lua); + } return 1; } |
