Skip to content

Commit

Permalink
fix isinteger
Browse files Browse the repository at this point in the history
  • Loading branch information
waruqi committed May 7, 2024
1 parent 9cfed98 commit 0cd3709
Show file tree
Hide file tree
Showing 21 changed files with 46 additions and 37 deletions.
4 changes: 2 additions & 2 deletions core/src/xmake/base64/encode.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ tb_int_t xm_base64_encode(lua_State* lua)
// get data and size
tb_size_t size = 0;
tb_byte_t const* data = tb_null;
if (lua_isinteger(lua, 1)) data = (tb_byte_t const*)(tb_size_t)(tb_long_t)lua_tointeger(lua, 1);
if (lua_isinteger(lua, 2)) size = (tb_size_t)lua_tointeger(lua, 2);
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)) size = (tb_size_t)lua_tointeger(lua, 2);
if (!data || !size)
{
lua_pushnil(lua);
Expand Down
4 changes: 2 additions & 2 deletions core/src/xmake/bloom_filter/bloom_filter_data_set.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ tb_int_t xm_bloom_filter_data_set(lua_State* lua)
// get data and size
tb_size_t size = 0;
tb_byte_t const* data = tb_null;
if (lua_isinteger(lua, 2)) data = (tb_byte_t const*)(tb_size_t)(tb_long_t)lua_tointeger(lua, 2);
if (lua_isinteger(lua, 3)) size = (tb_size_t)lua_tointeger(lua, 3);
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)) size = (tb_size_t)lua_tointeger(lua, 3);
if (!data || !size)
{
lua_pushinteger(lua, -1);
Expand Down
2 changes: 1 addition & 1 deletion core/src/xmake/hash/md5.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ tb_int_t xm_hash_md5(lua_State* lua)
tb_assert_and_check_return_val(lua, 0);

// is bytes? get data and size
if (lua_isinteger(lua, 1) && lua_isinteger(lua, 2))
if (xm_lua_isinteger(lua, 1) && xm_lua_isinteger(lua, 2))
{
tb_byte_t const* data = (tb_byte_t const*)(tb_size_t)(tb_long_t)lua_tointeger(lua, 1);
tb_size_t size = (tb_size_t)lua_tointeger(lua, 2);
Expand Down
2 changes: 1 addition & 1 deletion core/src/xmake/hash/sha.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ tb_int_t xm_hash_sha(lua_State* lua)
tb_size_t mode = (tb_size_t)lua_tointeger(lua, 1);

// is bytes? get data and size
if (lua_isinteger(lua, 2) && lua_isinteger(lua, 3))
if (xm_lua_isinteger(lua, 2) && xm_lua_isinteger(lua, 3))
{
tb_byte_t const* data = (tb_byte_t const*)(tb_size_t)(tb_long_t)lua_tointeger(lua, 2);
tb_size_t size = (tb_size_t)lua_tointeger(lua, 3);
Expand Down
2 changes: 1 addition & 1 deletion core/src/xmake/hash/xxhash.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ tb_int_t xm_hash_xxhash(lua_State* lua)
}

// is bytes? get data and size
if (lua_isinteger(lua, 2) && lua_isinteger(lua, 3))
if (xm_lua_isinteger(lua, 2) && xm_lua_isinteger(lua, 3))
{
tb_assert_static(sizeof(lua_Integer) == sizeof(tb_pointer_t));
tb_byte_t const* data = (tb_byte_t const*)(tb_size_t)(tb_long_t)lua_tointeger(lua, 2);
Expand Down
4 changes: 2 additions & 2 deletions core/src/xmake/io/file_write.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,14 @@ tb_int_t xm_io_file_write(lua_State* lua)
// get bytes data
lua_pushstring(lua, "data");
lua_gettable(lua, i);
if (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);
lua_pop(lua, 1);
tb_assert_static(sizeof(lua_Integer) == sizeof(tb_pointer_t));

lua_pushstring(lua, "size");
lua_gettable(lua, i);
if (lua_isinteger(lua, -1))
if (xm_lua_isinteger(lua, -1))
datasize = (tb_size_t)lua_tointeger(lua, -1);
lua_pop(lua, 1);

Expand Down
4 changes: 2 additions & 2 deletions core/src/xmake/io/pipe_read.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ tb_int_t xm_io_pipe_read(lua_State* lua)

// get data
tb_byte_t* data = tb_null;
if (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)
{
Expand All @@ -66,7 +66,7 @@ tb_int_t xm_io_pipe_read(lua_State* lua)

// get size
tb_long_t size = 0;
if (lua_isinteger(lua, 3)) size = (tb_long_t)lua_tointeger(lua, 3);
if (xm_lua_isinteger(lua, 3)) size = (tb_long_t)lua_tointeger(lua, 3);
if (size <= 0)
{
lua_pushinteger(lua, -1);
Expand Down
4 changes: 2 additions & 2 deletions core/src/xmake/io/pipe_write.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ tb_int_t xm_io_pipe_write(lua_State* lua)
// get data and size
tb_size_t size = 0;
tb_byte_t const* data = tb_null;
if (lua_isinteger(lua, 2)) data = (tb_byte_t const*)(tb_size_t)(tb_long_t)lua_tointeger(lua, 2);
if (lua_isinteger(lua, 3)) size = (tb_size_t)lua_tointeger(lua, 3);
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)) size = (tb_size_t)lua_tointeger(lua, 3);
if (!data || !size)
{
lua_pushinteger(lua, -1);
Expand Down
4 changes: 2 additions & 2 deletions core/src/xmake/io/socket_recv.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ tb_int_t xm_io_socket_recv(lua_State* lua)

// get data
tb_byte_t* data = tb_null;
if (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)
{
Expand All @@ -66,7 +66,7 @@ tb_int_t xm_io_socket_recv(lua_State* lua)

// get size
tb_long_t size = 0;
if (lua_isinteger(lua, 3)) size = (tb_long_t)lua_tointeger(lua, 3);
if (xm_lua_isinteger(lua, 3)) size = (tb_long_t)lua_tointeger(lua, 3);
if (size <= 0)
{
lua_pushinteger(lua, -1);
Expand Down
4 changes: 2 additions & 2 deletions core/src/xmake/io/socket_recvfrom.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ tb_int_t xm_io_socket_recvfrom(lua_State* lua)

// get data
tb_byte_t* data = tb_null;
if (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)
{
Expand All @@ -66,7 +66,7 @@ tb_int_t xm_io_socket_recvfrom(lua_State* lua)

// get size
tb_long_t size = 0;
if (lua_isinteger(lua, 3)) size = (tb_long_t)lua_tointeger(lua, 3);
if (xm_lua_isinteger(lua, 3)) size = (tb_long_t)lua_tointeger(lua, 3);
if (size <= 0)
{
lua_pushinteger(lua, -1);
Expand Down
4 changes: 2 additions & 2 deletions core/src/xmake/io/socket_send.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ tb_int_t xm_io_socket_send(lua_State* lua)
// get data and size
tb_size_t size = 0;
tb_byte_t const* data = tb_null;
if (lua_isinteger(lua, 2)) data = (tb_byte_t const*)(tb_size_t)(tb_long_t)lua_tointeger(lua, 2);
if (lua_isinteger(lua, 3)) size = (tb_size_t)lua_tointeger(lua, 3);
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)) size = (tb_size_t)lua_tointeger(lua, 3);
if (!data || !size)
{
lua_pushinteger(lua, -1);
Expand Down
4 changes: 2 additions & 2 deletions core/src/xmake/io/socket_sendto.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ tb_int_t xm_io_socket_sendto(lua_State* lua)
// get data and size
tb_size_t size = 0;
tb_byte_t const* data = tb_null;
if (lua_isinteger(lua, 2)) data = (tb_byte_t const*)(tb_size_t)(tb_long_t)lua_tointeger(lua, 2);
if (lua_isinteger(lua, 3)) size = (tb_size_t)lua_tointeger(lua, 3);
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)) size = (tb_size_t)lua_tointeger(lua, 3);
if (!data || !size)
{
lua_pushinteger(lua, -1);
Expand Down
4 changes: 2 additions & 2 deletions core/src/xmake/lz4/block_compress.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ 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 (lua_isinteger(lua, 1)) data = (tb_byte_t const*)(tb_size_t)(tb_long_t)lua_tointeger(lua, 1);
if (lua_isinteger(lua, 2)) size = (tb_int_t)lua_tointeger(lua, 2);
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)) size = (tb_int_t)lua_tointeger(lua, 2);
if (!data || !size || size > LZ4_MAX_INPUT_SIZE)
{
lua_pushnil(lua);
Expand Down
4 changes: 2 additions & 2 deletions core/src/xmake/lz4/block_decompress.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ 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 (lua_isinteger(lua, 1)) data = (tb_byte_t const*)(tb_size_t)(tb_long_t)lua_tointeger(lua, 1);
if (lua_isinteger(lua, 2)) size = (tb_size_t)lua_tointeger(lua, 2);
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)) size = (tb_size_t)lua_tointeger(lua, 2);
if (!data || !size)
{
lua_pushnil(lua);
Expand Down
4 changes: 2 additions & 2 deletions core/src/xmake/lz4/compress.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ 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 (lua_isinteger(lua, 1)) data = (tb_byte_t const*)(tb_size_t)(tb_long_t)lua_tointeger(lua, 1);
if (lua_isinteger(lua, 2)) size = (tb_size_t)lua_tointeger(lua, 2);
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)) size = (tb_size_t)lua_tointeger(lua, 2);
if (!data || !size)
{
lua_pushnil(lua);
Expand Down
4 changes: 2 additions & 2 deletions core/src/xmake/lz4/compress_stream_read.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ tb_int_t xm_lz4_compress_stream_read(lua_State* lua)

// get data
tb_byte_t* data = tb_null;
if (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)
{
Expand All @@ -65,7 +65,7 @@ tb_int_t xm_lz4_compress_stream_read(lua_State* lua)

// get size
tb_long_t size = 0;
if (lua_isinteger(lua, 3)) size = (tb_long_t)lua_tointeger(lua, 3);
if (xm_lua_isinteger(lua, 3)) size = (tb_long_t)lua_tointeger(lua, 3);
if (size <= 0)
{
lua_pushinteger(lua, -1);
Expand Down
4 changes: 2 additions & 2 deletions core/src/xmake/lz4/compress_stream_write.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ 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 (lua_isinteger(lua, 2)) data = (tb_byte_t const*)(tb_size_t)(tb_long_t)lua_tointeger(lua, 2);
if (lua_isinteger(lua, 3)) size = (tb_size_t)lua_tointeger(lua, 3);
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)) size = (tb_size_t)lua_tointeger(lua, 3);
if (!data || !size)
{
lua_pushinteger(lua, -1);
Expand Down
4 changes: 2 additions & 2 deletions core/src/xmake/lz4/decompress.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ 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 (lua_isinteger(lua, 1)) data = (tb_byte_t const*)(tb_size_t)(tb_long_t)lua_tointeger(lua, 1);
if (lua_isinteger(lua, 2)) size = (tb_size_t)lua_tointeger(lua, 2);
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)) size = (tb_size_t)lua_tointeger(lua, 2);
if (!data || !size)
{
lua_pushnil(lua);
Expand Down
4 changes: 2 additions & 2 deletions core/src/xmake/lz4/decompress_stream_read.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ tb_int_t xm_lz4_decompress_stream_read(lua_State* lua)

// get data
tb_byte_t* data = tb_null;
if (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)
{
Expand All @@ -65,7 +65,7 @@ tb_int_t xm_lz4_decompress_stream_read(lua_State* lua)

// get size
tb_long_t size = 0;
if (lua_isinteger(lua, 3)) size = (tb_long_t)lua_tointeger(lua, 3);
if (xm_lua_isinteger(lua, 3)) size = (tb_long_t)lua_tointeger(lua, 3);
if (size <= 0)
{
lua_pushinteger(lua, -1);
Expand Down
4 changes: 2 additions & 2 deletions core/src/xmake/lz4/decompress_stream_write.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ 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 (lua_isinteger(lua, 2)) data = (tb_byte_t const*)(tb_size_t)(tb_long_t)lua_tointeger(lua, 2);
if (lua_isinteger(lua, 3)) size = (tb_size_t)lua_tointeger(lua, 3);
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)) size = (tb_size_t)lua_tointeger(lua, 3);
if (!data || !size)
{
lua_pushinteger(lua, -1);
Expand Down
9 changes: 9 additions & 0 deletions core/src/xmake/prefix.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,15 @@ static __tb_inline__ tb_void_t xm_lua_register(lua_State *lua, tb_char_t const*
#endif
}

static __tb_inline__ tb_int_t xm_lua_isinteger(lua_State* lua, int idx)
{
#ifdef USE_LUAJIT
return lua_isnumber(lua, idx);
#else
return lua_isinteger(lua, idx);
#endif
}

#endif


0 comments on commit 0cd3709

Please sign in to comment.