Skip to content

Commit

Permalink
Merge pull request wheremyfoodat#334 from wheremyfoodat/delete-emu
Browse files Browse the repository at this point in the history
Add libuv to lua bindings
  • Loading branch information
wheremyfoodat authored Feb 1, 2024
2 parents 28ca4cd + ce63596 commit 880cc20
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -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
15 changes: 15 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
15 changes: 13 additions & 2 deletions src/lua.cpp
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions third_party/libuv
Submodule libuv added at b8368a
1 change: 1 addition & 0 deletions third_party/luv
Submodule luv added at 3e55ac

0 comments on commit 880cc20

Please sign in to comment.