diff --git a/.gitmodules b/.gitmodules index 3735d0cb1..f1e8f469c 100644 --- a/.gitmodules +++ b/.gitmodules @@ -49,3 +49,9 @@ [submodule "third_party/oaknut"] path = third_party/oaknut url = https://github.com/merryhime/oaknut +[submodule "third_party/luv"] + path = third_party/luv + url = https://github.com/luvit/luv +[submodule "third_party/libuv"] + path = third_party/libuv + url = https://github.com/libuv/libuv diff --git a/CMakeLists.txt b/CMakeLists.txt index ac6cdfb85..456d6513a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -266,6 +266,16 @@ set(THIRD_PARTY_SOURCE_FILES third_party/imgui/imgui.cpp third_party/xxhash/xxhash.c ) +if(ENABLE_LUAJIT AND NOT ANDROID) + # Build luv and libuv for Lua TCP server usage if we're not on Android + include_directories(third_party/luv/src) + include_directories(third_party/luv/deps/lua-compat-5.3/c-api) + include_directories(third_party/libuv/include) + set(THIRD_PARTY_SOURCE_FILES ${THIRD_PARTY_SOURCE_FILES} third_party/luv/src/luv.c) + set(LIBUV_BUILD_SHARED OFF) + + add_subdirectory(third_party/libuv) +endif() if(ENABLE_QT_GUI) include_directories(third_party/duckstation) @@ -433,6 +443,11 @@ endif() if(ENABLE_LUAJIT) target_compile_definitions(Alber PUBLIC "PANDA3DS_ENABLE_LUA=1") target_link_libraries(Alber PRIVATE libluajit) + + # If we're not on Android, link libuv too + if (NOT ANDROID) + target_link_libraries(Alber PRIVATE uv_a) + endif() endif() if(ENABLE_OPENGL) diff --git a/src/lua.cpp b/src/lua.cpp index ec1287bda..09c631735 100644 --- a/src/lua.cpp +++ b/src/lua.cpp @@ -1,6 +1,12 @@ #ifdef PANDA3DS_ENABLE_LUA #include "lua_manager.hpp" +#ifndef __ANDROID__ +extern "C" { + #include "luv.h" +} +#endif + void LuaManager::initialize() { L = luaL_newstate(); // Open Lua @@ -9,10 +15,15 @@ void LuaManager::initialize() { initialized = false; return; } - luaL_openlibs(L); - initializeThunks(); +#ifndef __ANDROID__ + lua_pushstring(L, "luv"); + luaopen_luv(L); + lua_settable(L, LUA_GLOBALSINDEX); +#endif + + initializeThunks(); initialized = true; haveScript = false; } diff --git a/third_party/libuv b/third_party/libuv new file mode 160000 index 000000000..b8368a144 --- /dev/null +++ b/third_party/libuv @@ -0,0 +1 @@ +Subproject commit b8368a1441fd4ebdaaae70b67136c80b1a98be32 diff --git a/third_party/luv b/third_party/luv new file mode 160000 index 000000000..3e55ac433 --- /dev/null +++ b/third_party/luv @@ -0,0 +1 @@ +Subproject commit 3e55ac4331d06aa5f43016a142aa2aaa23264105