Skip to content

Commit

Permalink
Merge branch 'luvit:master' into fix/async-arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
javalikescript authored Jan 25, 2025
2 parents bc90207 + 1b29585 commit 74054c1
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 43 deletions.
44 changes: 11 additions & 33 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,17 @@ if(WIN32)
add_definitions(-DLUA_BUILD_AS_DLL -DLUA_LIB)
endif()

add_executable(test EXCLUDE_FROM_ALL src/test.c src/luv.c)
# Need to link Lua/LuaJIT libraries on non-Windows for the test executable
if ((LUAJIT_LIBRARIES OR LUA_LIBRARIES) AND NOT (WIN32 OR CYGWIN))
if(USE_LUAJIT)
target_link_libraries(test ${LUAJIT_LIBRARIES})
else()
target_link_libraries(test ${LUA_LIBRARIES})
endif()
endif()
list(APPEND ACTIVE_TARGETS "test")

foreach(TARGET_NAME ${ACTIVE_TARGETS})
if(WIN32 OR CYGWIN)
if (LUA)
Expand All @@ -262,39 +273,6 @@ foreach(TARGET_NAME ${ACTIVE_TARGETS})
endif()
endforeach()

if(LUAJIT_LIBRARIES OR LUA_LIBRARIES)
add_executable(test src/test.c src/luv.c)
if(WIN32 OR CYGWIN)
if (LUA)
target_link_libraries(test ${LIBUV_LIBRARIES} ${LUA_LIBRARIES})
else (LUA)
if (USE_LUAJIT)
target_link_libraries(test ${LIBUV_LIBRARIES} ${LUAJIT_LIBRARIES})
else (USE_LUAJIT)
if (LUA_BUILD_TYPE STREQUAL System)
target_link_libraries(test ${LIBUV_LIBRARIES} ${LUA_LIBRARIES})
else (LUA_BUILD_TYPE STREQUAL System)
target_link_libraries(test ${LIBUV_LIBRARIES} lualib)
endif (LUA_BUILD_TYPE STREQUAL System)
endif (USE_LUAJIT)
endif (LUA)
elseif("${CMAKE_SYSTEM_NAME}" MATCHES "Linux")
if (USE_LUAJIT)
target_link_libraries(test ${LIBUV_LIBRARIES} ${LUAJIT_LIBRARIES} rt)
else ()
target_link_libraries(test ${LIBUV_LIBRARIES} ${LUA_LIBRARIES} rt)
endif ()
else()
if (USE_LUAJIT)
target_link_libraries(test ${LIBUV_LIBRARIES} ${LUAJIT_LIBRARIES})
else ()
target_link_libraries(test ${LIBUV_LIBRARIES} ${LUA_LIBRARIES})
endif ()
endif()
else()
message(STATUS "Lua/LuaJIT libraries not found, test not built.")
endif()

if (NOT LUA)
if (BUILD_MODULE)
if (WIN32)
Expand Down
6 changes: 2 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,8 @@ clean:

test: luv
${LUABIN} tests/run.lua
@if [ -f $(BUILD_DIR)/test ]; then \
echo "$(BUILD_DIR)/test exists."; \
$(BUILD_DIR)/test tests/manual-test-external-loop.lua; \
fi
$(MAKE) -C $(BUILD_DIR) test
$(BUILD_DIR)/test tests/manual-test-external-loop.lua

reset:
git submodule update --init --recursive && \
Expand Down
6 changes: 3 additions & 3 deletions docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -4181,7 +4181,7 @@ These string utilities are needed internally for dealing with Windows, and are e

### `uv.utf16_length_as_wtf8(utf16)`

Get the length (in bytes) of a UTF-16 (or UCS-2) string `utf16` value after converting it to WTF-8.
Get the length (in bytes) of a UTF-16 (or UCS-2) string `utf16` value after converting it to WTF-8. The endianness of the UTF-16 (or UCS-2) string is assumed to be the same as the native endianness of the platform.

**Parameters:**
- `utf16`: `string`
Expand All @@ -4190,7 +4190,7 @@ Get the length (in bytes) of a UTF-16 (or UCS-2) string `utf16` value after conv

### `uv.utf16_to_wtf8(utf16)`

Convert UTF-16 (or UCS-2) string `utf16` to WTF-8 string.
Convert UTF-16 (or UCS-2) string `utf16` to WTF-8 string. The endianness of the UTF-16 (or UCS-2) string is assumed to be the same as the native endianness of the platform.

**Parameters:**
- `utf16`: `string`
Expand All @@ -4208,7 +4208,7 @@ Get the length (in UTF-16 code units) of a WTF-8 `wtf8` value after converting i

### `uv.wtf8_to_utf16(wtf8)`

Convert WTF-8 string in `wtf8` to UTF-16 (or UCS-2) string.
Convert WTF-8 string in `wtf8` to UTF-16 (or UCS-2) string. The endianness of the UTF-16 (or UCS-2) string will be the same as the native endianness of the platform.

**Parameters:**
- `wtf8`: `string`
Expand Down
7 changes: 4 additions & 3 deletions tests/test-misc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,8 @@ return require('lib/tap')(function (test)
-- The utf8 content is "中文"
local utf16 = uv.wtf8_to_utf16(utf8)
assert(#utf16==4, #utf16)
assert(utf16==string.char(0x2d, 0x4e, 0x87, 0x65))
-- little-endian or big-endian
assert(utf16==string.char(0x2d, 0x4e, 0x87, 0x65) or utf16==string.char(0x4e, 0x2d, 0x65, 0x87))
assert(uv.utf16_length_as_wtf8(utf16) == 6, uv.utf16_length_as_wtf8(utf16))
utf8 = uv.utf16_to_wtf8(utf16)
assert(utf8=='中文', utf8)
Expand All @@ -242,8 +243,8 @@ return require('lib/tap')(function (test)
local wtf8 = string.char(0xed, 0xa0, 0xbd)
local utf16 = uv.wtf8_to_utf16(wtf8)
assert(#utf16==2, #utf16)
-- U+D83D as little-endian WTF-16
assert(utf16==string.char(0x3d, 0xd8))
-- U+D83D as little-endian or big-endian WTF-16
assert(utf16==string.char(0x3d, 0xd8) or utf16==string.char(0xd8, 0x3d))
assert(uv.utf16_length_as_wtf8(utf16) == #wtf8, uv.utf16_length_as_wtf8(utf16))
assert(uv.wtf8_length_as_utf16(wtf8) == 1, uv.wtf8_length_as_utf16(wtf8))
local roundtrip_wtf8 = uv.utf16_to_wtf8(utf16)
Expand Down

0 comments on commit 74054c1

Please sign in to comment.