Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
161 changes: 153 additions & 8 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,21 +62,166 @@ jobs:
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
# Create our include directories
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"

# Create minimal header files directly
echo "Creating minimal Lua headers..."
cat > /tmp/lua_include/lua.h << 'EOF'
/* Minimal lua.h for LuaFileSystem */
#ifndef LUA_H
#define LUA_H

#include <stdarg.h>
#include <stddef.h>

#define LUA_VERSION_MAJOR "5"
#define LUA_VERSION_MINOR "1"
#define LUA_VERSION "Lua 5.1"

#define LUA_REGISTRYINDEX (-10000)
#define LUA_GLOBALSINDEX (-10002)

#define LUA_TNONE (-1)
#define LUA_TNIL 0
#define LUA_TBOOLEAN 1
#define LUA_TLIGHTUSERDATA 2
#define LUA_TNUMBER 3
#define LUA_TSTRING 4
#define LUA_TTABLE 5
#define LUA_TFUNCTION 6
#define LUA_TUSERDATA 7
#define LUA_TTHREAD 8

typedef struct lua_State lua_State;
typedef int (*lua_CFunction) (lua_State *L);

/* Basic stack manipulation */
int lua_gettop (lua_State *L);
void lua_settop (lua_State *L, int idx);
void lua_pushvalue (lua_State *L, int idx);
void lua_remove (lua_State *L, int idx);
void lua_insert (lua_State *L, int idx);
void lua_replace (lua_State *L, int idx);

/* Basic type checks */
int lua_isnumber (lua_State *L, int idx);
int lua_isstring (lua_State *L, int idx);
int lua_istable (lua_State *L, int idx);
int lua_isfunction (lua_State *L, int idx);
int lua_isuserdata (lua_State *L, int idx);
int lua_type (lua_State *L, int idx);
const char *lua_typename (lua_State *L, int tp);

/* Get functions (Lua -> stack) */
void lua_gettable (lua_State *L, int idx);
void lua_getfield (lua_State *L, int idx, const char *k);
void lua_rawget (lua_State *L, int idx);
void lua_rawgeti (lua_State *L, int idx, int n);
void lua_createtable (lua_State *L, int narr, int nrec);
void *lua_newuserdata (lua_State *L, size_t sz);
int lua_getmetatable (lua_State *L, int objindex);

/* Set functions (stack -> Lua) */
void lua_settable (lua_State *L, int idx);
void lua_setfield (lua_State *L, int idx, const char *k);
void lua_rawset (lua_State *L, int idx);
void lua_rawseti (lua_State *L, int idx, int n);
int lua_setmetatable (lua_State *L, int objindex);

/* Push functions (C -> stack) */
void lua_pushnil (lua_State *L);
void lua_pushnumber (lua_State *L, double n);
void lua_pushinteger (lua_State *L, int n);
void lua_pushlstring (lua_State *L, const char *s, size_t l);
void lua_pushstring (lua_State *L, const char *s);
const char *lua_pushfstring (lua_State *L, const char *fmt, ...);
const char *lua_pushvfstring (lua_State *L, const char *fmt, va_list argp);
void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n);
void lua_pushboolean (lua_State *L, int b);

/* Pop values */
#define lua_pop(L,n) lua_settop(L, -(n)-1)
#define lua_newtable(L) lua_createtable(L, 0, 0)
#define lua_pushcfunction(L,f) lua_pushcclosure(L, (f), 0)

#define LUA_NOREF (-2)
#define LUA_REFNIL (-1)
int luaL_ref (lua_State *L, int t);
void luaL_unref (lua_State *L, int t, int ref);

#endif /* LUA_H */
EOF

cat > /tmp/lua_include/lauxlib.h << 'EOF'
/* Minimal lauxlib.h for LuaFileSystem */
#ifndef LAUXLIB_H
#define LAUXLIB_H

#include "lua.h"
#include <stddef.h>
#include <stdio.h>

/* Compatibility */
#if defined(LUA_VERSION_NUM) && LUA_VERSION_NUM >= 502
#define luaL_register(L,n,l) luaL_setfuncs(L,l,0)
#endif

typedef struct luaL_Reg {
const char *name;
lua_CFunction func;
} luaL_Reg;

void luaL_openlib (lua_State *L, const char *libname, const luaL_Reg *l, int nup);
void luaL_register (lua_State *L, const char *libname, const luaL_Reg *l);
int luaL_getmetafield (lua_State *L, int obj, const char *event);
int luaL_callmeta (lua_State *L, int obj, const char *event);
void luaL_checkany (lua_State *L, int narg);
int luaL_error (lua_State *L, const char *fmt, ...);
int luaL_checkoption (lua_State *L, int narg, const char *def, const char *const lst[]);
void luaL_checktype (lua_State *L, int narg, int t);
int luaL_newmetatable (lua_State *L, const char *tname);
void *luaL_checkudata (lua_State *L, int ud, const char *tname);

#endif /* LAUXLIB_H */
EOF

cat > /tmp/lua_include/lualib.h << 'EOF'
/* Minimal lualib.h for LuaFileSystem */
#ifndef LUALIB_H
#define LUALIB_H

#include "lua.h"

#define LUA_FILEHANDLE "FILE*"

int luaopen_base (lua_State *L);
int luaopen_package (lua_State *L);
int luaopen_string (lua_State *L);
int luaopen_table (lua_State *L);
int luaopen_math (lua_State *L);
int luaopen_io (lua_State *L);
int luaopen_os (lua_State *L);
int luaopen_debug (lua_State *L);

#endif /* LUALIB_H */
EOF

echo "Created minimal Lua header files in /tmp/lua_include"

# Create dummy library
echo "/* Dummy liblua.dylib */" > /tmp/lua_lib/liblua.dylib
echo "/* Dummy liblua.a */" > /tmp/lua_lib/liblua.a

# Set environment variables
echo "LUA_INCLUDE_DIR=/tmp/lua_include" >> $GITHUB_ENV
echo "LUA_LIBRARIES=/tmp/lua_lib/liblua.dylib" >> $GITHUB_ENV

# Add these directories to compiler flags
echo "CFLAGS=-I/tmp/lua_include" >> $GITHUB_ENV
echo "CXXFLAGS=-I/tmp/lua_include" >> $GITHUB_ENV

# Create directories for project resources (only once)
mkdir -p Resources/AIData/LocalModels
mkdir -p Resources/AIData/Vulnerabilities
Expand Down
8 changes: 1 addition & 7 deletions source/lfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,10 @@
#include "lauxlib.h"
#include "lualib.h"
#else
// Use standard Lua headers - we're going back to the original approach
#ifdef LFS_USE_INCLUDE_QUOTES
// Always use quotes for includes since paths might be non-standard
#include "lua.h"
#include "lauxlib.h"
#include "lualib.h"
#else
#include <lua.h>
#include <lauxlib.h>
#include <lualib.h>
#endif
#endif

#include "lfs.h"
Expand Down