From e02f2b94dcf5e130f7ce4d3ad76cba47f7c0f182 Mon Sep 17 00:00:00 2001 From: MentatBot <160964065+MentatBot@users.noreply.github.com> Date: Mon, 14 Apr 2025 04:58:05 +0000 Subject: [PATCH] Revert to using standard Lua instead of Luau headers --- .github/workflows/build.yml | 23 ++++++++++++++++++++-- cmake/FindLuaFileSystem.cmake | 36 ++++++++++++++++++++--------------- source/lfs.c | 16 +++++++++------- 3 files changed, 51 insertions(+), 24 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f6862cd9..9b9e532c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -55,8 +55,27 @@ jobs: fi fi - # Note: We're using the internal Luau headers, not external Lua - echo "Using internal Luau headers - no need to install external Lua" + # Note: We're using standard Lua headers + echo "Using standard Lua headers - we'll look for them on the system" + + # Install lua and luarocks with homebrew + brew install lua@5.4 || brew install lua || echo "Lua installation failed but we'll continue" + which lua || echo "Lua not found in PATH" + + # Copy any headers found to our directory + mkdir -p /tmp/lua_include + find /opt/homebrew -name "lua.h" -exec cp {} /tmp/lua_include/ \; || echo "No lua.h found" + find /opt/homebrew -name "lauxlib.h" -exec cp {} /tmp/lua_include/ \; || echo "No lauxlib.h found" + find /opt/homebrew -name "lualib.h" -exec cp {} /tmp/lua_include/ \; || echo "No lualib.h found" + + # Find and copy lua libraries + mkdir -p /tmp/lua_lib + find /opt/homebrew -name "liblua*.dylib" -exec cp {} /tmp/lua_lib/ \; || echo "No lua libraries found" + find /opt/homebrew -name "liblua*.a" -exec cp {} /tmp/lua_lib/ \; || echo "No lua libraries found" + + # Set environment variables + echo "LUA_INCLUDE_DIR=/tmp/lua_include" >> $GITHUB_ENV + echo "LUA_LIBRARIES=/tmp/lua_lib/liblua.dylib" >> $GITHUB_ENV # Create directories for project resources (only once) mkdir -p Resources/AIData/LocalModels diff --git a/cmake/FindLuaFileSystem.cmake b/cmake/FindLuaFileSystem.cmake index 5b72c51f..e73a1a35 100644 --- a/cmake/FindLuaFileSystem.cmake +++ b/cmake/FindLuaFileSystem.cmake @@ -1,38 +1,44 @@ # FindLuaFileSystem.cmake -# This module allows compilation of lfs.c specifically using our own Lua headers +# This module allows compilation of lfs.c specifically by finding external Lua -# Create a target for lfs.c that ensures it can find the Luau headers +# Create a target for lfs.c with external Lua function(add_lfs_target) # Don't add it twice if(TARGET lfs_obj) return() endif() - message(STATUS "Setting up LuaFileSystem with native Luau headers") + message(STATUS "Setting up LuaFileSystem with external Lua headers") # Create an object library for lfs.c add_library(lfs_obj OBJECT ${CMAKE_SOURCE_DIR}/source/lfs.c) - # Set include directories for just this file - # The source directory is needed for relative includes like "cpp/luau/lua.h" - target_include_directories(lfs_obj PRIVATE - ${CMAKE_SOURCE_DIR}/source # Main source directory for relative includes - ${CMAKE_SOURCE_DIR}/source/cpp # For cpp/luau/lua.h path style - ${CMAKE_SOURCE_DIR}/source/cpp/luau # For direct lua.h access - ${CMAKE_SOURCE_DIR} # For absolute paths + # Look for lua in standard paths + find_path(LUA_INCLUDE_DIR lua.h + PATHS + /opt/homebrew/opt/lua/include + /opt/homebrew/include + /usr/local/include + /usr/include + PATH_SUFFIXES lua lua5.4 lua5.3 lua5.2 lua5.1 ) - # Add a define to use the internal Luau headers - target_compile_definitions(lfs_obj PRIVATE - LFS_USE_INTERNAL_LUAU=1 - LUAU_FASTFLAG_LUAERROR=1 # Handle missing dependencies + # Add include directories + target_include_directories(lfs_obj PRIVATE + ${LUA_INCLUDE_DIR} ) + # Enable standard paths with quotes if needed + if(LUA_INCLUDE_DIR) + message(STATUS "Found Lua include directory: ${LUA_INCLUDE_DIR}") + target_compile_definitions(lfs_obj PRIVATE LFS_USE_INCLUDE_QUOTES) + endif() + # Ensure the compiler knows this is C set_target_properties(lfs_obj PROPERTIES C_STANDARD 99 POSITION_INDEPENDENT_CODE ON ) - message(STATUS "LFS using internal Luau headers from ${CMAKE_SOURCE_DIR}/source/cpp/luau") + message(STATUS "LFS using external Lua headers from: ${LUA_INCLUDE_DIR}") endfunction() diff --git a/source/lfs.c b/source/lfs.c index f07f8231..7752235a 100644 --- a/source/lfs.c +++ b/source/lfs.c @@ -86,13 +86,15 @@ #include "lauxlib.h" #include "lualib.h" #else -// Use the Lua headers from our source tree -#include "cpp/luau/lua.h" -#include "cpp/luau/lualib.h" - -// Define missing lauxlib symbols we need -#ifndef luaL_register -extern void luaL_register(lua_State* L, const char* libname, const luaL_Reg* l); +// Use standard Lua headers - we're going back to the original approach +#ifdef LFS_USE_INCLUDE_QUOTES +#include "lua.h" +#include "lauxlib.h" +#include "lualib.h" +#else +#include +#include +#include #endif #endif