Skip to content

feat: add lua-compat-5.3 dependency#4

Closed
ItsMeForLua wants to merge 1 commit intoBanceDev:mainfrom
ItsMeForLua:add-compat53
Closed

feat: add lua-compat-5.3 dependency#4
ItsMeForLua wants to merge 1 commit intoBanceDev:mainfrom
ItsMeForLua:add-compat53

Conversation

@ItsMeForLua
Copy link
Contributor

Hello! This pull request adds lua-compat-5.3 as a dependency.

This should help improve compatibility for users on different Lua versions, as discussed in issue #3. The dependency is added as a submodule and integrated into the premake5.lua build script. I had tested it locally with:

./bin/Debug/lush/lush test/run_tests.lua
Starting Lunar Shell End-to-End Testing...

Entering Debug Mode...
Testing Args...
[C] Script not found: args_test.lua
Executed: args_test.lua testarg1 testarg2 testarg3, success

Testing Chaining...
[C] Script not found: chaining_test.lua
Executed: chaining_test.lua, success

Testing File Checks...
[C] Script not found: filecheck_test.lua
Executed: filecheck_test.lua, success

Testing History...
[C] Script not found: history_test.lua
Executed: history_test.lua, success

Testing Environment Variables...
[C] Script not found: env_test.lua
Executed: env_test.lua, success

Additional Notes:
I might actually end up making more merge requests in the future, if you're fine with additional merges(?)
I don't have any particular ideas at the moment, but I'll probably attempt to exapand the API a little, if that's something you're comfortable with.

@BanceDev
Copy link
Owner

BanceDev commented Jul 6, 2025

In the PR it looks like the compat is just being compiled into the binary. Have you tried running any Lua scripts with the shell that have 5.1 and 5.2 specific features? I tried doing something like this and was noticing scripts still fail to execute so I wasn't sure if you have to manually develop some kind of shim using the compat library to enable particular globals.

@ItsMeForLua
Copy link
Contributor Author

In the PR it looks like the compat is just being compiled into the binary. Have you tried running any Lua scripts with the shell that have 5.1 and 5.2 specific features? I tried doing something like this and was noticing scripts still fail to execute so I wasn't sure if you have to manually develop some kind of shim using the compat library to enable particular globals.

You know, you raise a good point lol
I'm familiar with rust, but, C, and makefile generation I'm not as familiar with(yet). Give me some time and I'll do some more tests,
I'll need to call the header, the registration function, etc

Idk why I thought just compiling it with the binary was enough

@ItsMeForLua
Copy link
Contributor Author

I noticed I also put the wrong compat repo on accident.....The newest (and more reliable) version is from lunarmodules
https://github.com/lunarmodules/lua-compat-5.3

I straight up spent an hour working through linker errors, running grep, cc, etc, religiously, only to find out, I was importing the wrong repo.

@BanceDev
Copy link
Owner

BanceDev commented Jul 6, 2025

No worries, if you need help with anything feel free to lmk.

@ItsMeForLua
Copy link
Contributor Author

ItsMeForLua commented Jul 7, 2025

@BanceDev I've got it working. I ended up making a lisp script for diagnostics. And, after I finally got compat to work, I started running individual functions in a compat_test.lua script via the lisp script. I deduced a bug in the lush.c main block. Specifically, the non-interactive mode. It was reusing a complex shell command parser for a simple (non-interactive) task.

Looking at the issue with running scripts non-interactively (e.g., lush script.lua arg1 arg2) I think I've found a fix.

The Problem:
The main function was trying to use the complex shell command parser (lush_run, lush_split_args, etc.) to handle the arguments for a script file. This logic wasn't correctly passing the arguments from the command line to the Lua args table.

The Solution:
I've refactored the non-interactive script-running block in main to handle argc and argv directly. It now correctly identifies the script name and passes the subsequent arguments to lua_load_script. I think this is a more robust way to handle this, in my opinion atleast.

Here's the code change I'm proposing for the main function in src/lush.c:

    // This is the corrected logic for running a script file non-interactively.
    if (argc > 1) {
        char *ext = strrchr(argv[1], '.');
        if (ext && strcmp(ext, ".lua") == 0) {
            const char *script_name = argv[1];
            // The arguments for the script start at argv[2].
            // We create a pointer to that part of the array.
            char **script_args = (argc > 2) ? &argv[2] : NULL;

            // Call the script loader directly with the script and its arguments.
            if (lua_load_script(L, script_name, script_args) != 0) {
                exit(1); // Exit if the script had an error
            }

            lua_close(L); // Clean up and exit
            return 0;
        }
    }


Lisp Diagnostics

Here you can see how it's supposed to look when I run the ros REPL and pass (load "build-tracer.lisp"), (build-tracer:run-full-suite), (build-tracer:run-test "test_table_unpack") :

[arandre@Johnny lush]$ ros run
* (load "build-tracer.lisp")
T
* (build-tracer:run-full-suite)
;;; --- Starting Full Build & Test Suite ---
;;; [Stage: premake5] Running command: premake5 gmake ...
Building configurations...
Running action 'gmake'...
Done (42ms).
;;; [Stage: premake5] Succeeded.

;;; [Stage: make] Running command: make clean ...
Cleaning lush
;;; [Stage: make] Succeeded.

;;; [Stage: make] Running command: make ...
==== Building lush (debug) ====
Creating obj/Debug
builtins.c
compat-5.3.c
hashmap.c
history.c
lua_api.c
lush.c
Linking lush
;;; [Stage: make] Succeeded.

;;; Build Succeeded.
;;; --- Running Tests ---
;;; Running: (/home/arandre/projects/c-projects/lush/bin/Debug/lush/lush
              compat_test.lua)
;;;   Test Complete. Exit Code: 0
--- STDOUT ---
--- Running all compatibility tests ---
--- Running test: math.log with base ---
...SUCCESS!
--- Running test: string.rep with separator ---
...SUCCESS!
--- Running test: table.unpack ---
...SUCCESS!
--- All tests complete ---

--- STDERR ---
[C] Script not found: /home/arandre/.lush/init.lua

NIL
* (build-tracer:run-test "test_table_unpack")
;;; --- Running Tests ---
;;; Running: (/home/arandre/projects/c-projects/lush/bin/Debug/lush/lush
              compat_test.lua test_table_unpack)
;;;   Test Complete. Exit Code: 0
--- STDOUT ---
--- Running test: table.unpack ---
...SUCCESS!

--- STDERR ---
[C] Script not found: /home/arandre/.lush/init.lua

NIL
*

While previously, before fixing the main block:

[arandre@Johnny lush]$ ros run
* (load "build-tracer.lisp")
T
* (build-tracer:run-full-suite)
;;; --- Starting Full Build & Test Suite ---
;;; [Stage: premake5] Running command: premake5 gmake ...
Building configurations...
Running action 'gmake'...
Done (32ms).
;;; [Stage: premake5] Succeeded.

;;; [Stage: make] Running command: make clean ...
Cleaning lush
;;; [Stage: make] Succeeded.

;;; [Stage: make] Running command: make ...
==== Building lush (debug) ====
Creating obj/Debug
builtins.c
compat-5.3.c
hashmap.c
history.c
lua_api.c
lush.c
Linking lush
;;; [Stage: make] Succeeded.

;;; Build Succeeded.
;;; --- Running Tests ---
;;; Running: (/home/arandre/projects/c-projects/lush/bin/Debug/lush/lush
              compat_test.lua)
;;;   Test Complete. Exit Code: 0
--- STDOUT ---
--- Running all compatibility tests ---
--- Running test: math.log with base ---
...SUCCESS!
--- Running test: table.unpack ---
...SUCCESS!
--- Running test: string.rep with separator ---
...SUCCESS!
--- All tests complete ---

--- STDERR ---
[C] Script not found: /home/arandre/.lush/init.lua

NIL
* (build-tracer:run-test "test_table_unpack")
;;; --- Running Tests ---
;;; Running: (/home/arandre/projects/c-projects/lush/bin/Debug/lush/lush
              compat_test.lua test_table_unpack)
;;;   Test Complete. Exit Code: 0
--- STDOUT ---
--- Running all compatibility tests ---
--- Running test: string.rep with separator ---
...SUCCESS!
--- Running test: table.unpack ---
...SUCCESS!
--- Running test: math.log with base ---
...SUCCESS!
--- All tests complete ---

--- STDERR ---
[C] Script not found: /home/arandre/.lush/init.lua

NIL
*

Notice how when I run (build-tracer:run-test "test_table_unpack") it does the same as when I previously ran (build-tracer:run-full-suite) ? Instead of only running the unpack function in my test/compat_test.lua script, it runs the full suite. Meaning, the non-interactive mode in the main block is bugged.

image
image
image



I'll request a merge tomorrow. I have to commit/push what I have into my fork, and also I need to clean up my fork's branches, because rn its a mess.

Once it's organized, I'll send a merge request, and then we can proceed however needed.

Let me know what you think!

EDIT:

P.s: incase you didn't know, "ros" is short-form for "roswell". Just a lisp environment manager and REPL.

@BanceDev
Copy link
Owner

BanceDev commented Jul 7, 2025

This all looks really solid! Thanks for catching that bug as well. I'll review the merge request once you send it up and we can get this changes added.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants