diff options
| author | 2025-07-22 23:17:16 -0500 | |
|---|---|---|
| committer | 2025-07-22 23:17:16 -0500 | |
| commit | 92c575cedf8a40046113516f490a1d5e0a77337e (patch) | |
| tree | 2b79408246ff270a63c4f73c437386c3a63e3573 | |
| parent | Added liblua5.4-dev package for build (diff) | |
Fixed the header path for compat: preload compat modules for lua within lua-init block
| -rw-r--r-- | premake5.lua | 7 | ||||
| -rw-r--r-- | src/lush.c | 23 |
2 files changed, 28 insertions, 2 deletions
diff --git a/premake5.lua b/premake5.lua index 127e86e..20dfa8a 100644 --- a/premake5.lua +++ b/premake5.lua @@ -31,7 +31,12 @@ files({ "lib/hashmap/**.h", "lib/hashmap/**.c", "lib/compat53/c-api/compat-5.3.h", - "lib/compat53/c-api/compat-5.3.c" + "lib/compat53/c-api/compat-5.3.c", + "lib/compat53/lbitlib.c", + "lib/compat53/liolib.c", + "lib/compat53/lstrlib.c", + "lib/compat53/ltablib.c", + "lib/compat53/lutf8lib.c" }) defines({ 'LUSH_VERSION="0.3.2"', 'COMPAT53_PREFIX=""' }) @@ -21,7 +21,7 @@ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. #include "lua.h" #include "lua_api.h" #include "lualib.h" -#include "../lib/compat53/c-api/compat-5.3.h" +#include "compat-5.3.h" #include <asm-generic/ioctls.h> #include <bits/time.h> #include <ctype.h> @@ -43,6 +43,10 @@ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. #include <time.h> #include <unistd.h> +// Forward declare the open functions for the compat C modules we need to preload +int luaopen_bit32 (lua_State *L); +int luaopen_utf8 (lua_State *L); + #define BUFFER_SIZE 1024 #define MAX_GLOB 512 @@ -1489,6 +1493,23 @@ int main(int argc, char *argv[]) { // init lua state lua_State *L = luaL_newstate(); luaL_openlibs(L); + + // --- Pre-load compat modules --- + // This is to make C modules available to Lua + luaL_getglobal(L, "package"); + luaL_getfield(L, -1, "preload"); + + // Preload bit32 for Lua 5.1 compatibility + lua_pushcfunction(L, luaopen_bit32); + lua_setfield(L, -2, "bit32"); + + // Preload utf8 for Lua 5.1/5.2 compatibility + lua_pushcfunction(L, luaopen_utf8); + lua_setfield(L, -2, "utf8"); + + // Pop package and preload tables + lua_pop(L, 2); + // --- End pre-loading --- luaopen_compat53(L); lua_register_api(L); lua_run_init(L); |
