From 6f8c0f3abda585b3ee1d87e3b8e19c729b52b4a6 Mon Sep 17 00:00:00 2001 From: Andrew D. France Date: Mon, 14 Jul 2025 17:51:23 -0500 Subject: Added compat53 support and fixed bugged non-interactive mode --- premake5.lua | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'premake5.lua') diff --git a/premake5.lua b/premake5.lua index 037cfca..127e86e 100644 --- a/premake5.lua +++ b/premake5.lua @@ -18,7 +18,11 @@ else links({ "lua" }) end -includedirs({ lua_inc_path, "lib/hashmap" }) +includedirs({ + lua_inc_path, + "lib/hashmap", + "lib/compat53/c-api" +}) libdirs({ lua_lib_path }) files({ @@ -26,8 +30,10 @@ files({ "src/**.c", "lib/hashmap/**.h", "lib/hashmap/**.c", + "lib/compat53/c-api/compat-5.3.h", + "lib/compat53/c-api/compat-5.3.c" }) -defines({ 'LUSH_VERSION="0.3.2"' }) +defines({ 'LUSH_VERSION="0.3.2"', 'COMPAT53_PREFIX=""' }) filter("configurations:Debug") defines({ "DEBUG" }) -- cgit v1.2.3-59-g8ed1b From 92c575cedf8a40046113516f490a1d5e0a77337e Mon Sep 17 00:00:00 2001 From: Andrew D. France Date: Tue, 22 Jul 2025 23:17:16 -0500 Subject: Fixed the header path for compat: preload compat modules for lua within lua-init block --- premake5.lua | 7 ++++++- src/lush.c | 23 ++++++++++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) (limited to 'premake5.lua') 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=""' }) diff --git a/src/lush.c b/src/lush.c index 49b205e..8beed6a 100644 --- a/src/lush.c +++ b/src/lush.c @@ -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 #include #include @@ -43,6 +43,10 @@ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. #include #include +// 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); -- cgit v1.2.3-59-g8ed1b From 69001c115100a19955249bfb6ec45ad332cd5ae8 Mon Sep 17 00:00:00 2001 From: Andrew D. France Date: Tue, 22 Jul 2025 23:27:06 -0500 Subject: Compat53 library uses the floor function, which is part of the C math library (libm); removed the incorrect luaopen_compat53 call that was still present --- premake5.lua | 3 ++- src/lush.c | 1 - 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'premake5.lua') diff --git a/premake5.lua b/premake5.lua index 20dfa8a..3ec299a 100644 --- a/premake5.lua +++ b/premake5.lua @@ -13,7 +13,8 @@ local lua_lib_path = "/usr/lib" if os.findlib("lua5.4") then lua_inc_path = "/usr/include/lua5.4" lua_lib_path = "/usr/lib/5.4" - links({ "lua5.4" }) +-- Readline for better interactive support, dl for dynamic loading, and m for the math library dependency + links({ "lua5.4", "readline", "dl", "m" }) else links({ "lua" }) end diff --git a/src/lush.c b/src/lush.c index 8beed6a..88d2998 100644 --- a/src/lush.c +++ b/src/lush.c @@ -1510,7 +1510,6 @@ int main(int argc, char *argv[]) { // Pop package and preload tables lua_pop(L, 2); // --- End pre-loading --- - luaopen_compat53(L); lua_register_api(L); lua_run_init(L); -- cgit v1.2.3-59-g8ed1b From 18052989d5722ba9fe01361b53b98330198dbb1e Mon Sep 17 00:00:00 2001 From: Andrew D. France Date: Wed, 23 Jul 2025 01:24:29 -0500 Subject: - The premake5.lua file has been updated to include the LUA_COMPAT_BITLIB compiler definition. This flag instructs the compat-5.3 submodule to build the actual bit32 library instead of a stub that throws a deprecated error. - The main function in src/lush.c is modified to explicitly load the bit32 and utf8 libraries into the global Lua state at startup using luaL_requiref. This makes them directly accessible to all scripts running in the shell, which is necessary for the test script to find and use the bit32 functions without a require() call. - Added a null check after luaL_newstate() in src/lush.c to ensure the Lua state is created successfully before its actually used. --- premake5.lua | 2 +- src/lush.c | 23 +++++++++-------------- 2 files changed, 10 insertions(+), 15 deletions(-) (limited to 'premake5.lua') diff --git a/premake5.lua b/premake5.lua index 3ec299a..1043c07 100644 --- a/premake5.lua +++ b/premake5.lua @@ -39,7 +39,7 @@ files({ "lib/compat53/ltablib.c", "lib/compat53/lutf8lib.c" }) -defines({ 'LUSH_VERSION="0.3.2"', 'COMPAT53_PREFIX=""' }) +defines({ 'LUSH_VERSION="0.3.2"', 'COMPAT53_PREFIX=""', 'LUA_COMPAT_BITLIB' }) filter("configurations:Debug") defines({ "DEBUG" }) diff --git a/src/lush.c b/src/lush.c index eef8f6d..b512a70 100644 --- a/src/lush.c +++ b/src/lush.c @@ -1492,23 +1492,18 @@ int main(int argc, char *argv[]) { // init lua state lua_State *L = luaL_newstate(); + if (!L) { + fprintf(stderr, "Failed to create Lua state\n"); + return -1; // or handle appropriately + } luaL_openlibs(L); - // --- Pre-load compat modules --- - // This is to make C modules available to Lua - lua_getglobal(L, "package"); - lua_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"); + // --- Load compat modules and make them global --- + luaL_requiref(L, "bit32", luaopen_bit32, 1); + lua_pop(L, 1); // luaL_requiref leaves the module on the stack - // Pop package and preload tables - lua_pop(L, 2); + luaL_requiref(L, "utf8", luaopen_utf8, 1); + lua_pop(L, 1); // --- End pre-loading --- lua_register_api(L); lua_run_init(L); -- cgit v1.2.3-59-g8ed1b