diff options
| -rw-r--r-- | .github/workflows/build.yml | 5 | ||||
| -rw-r--r-- | src/lush.c | 27 |
2 files changed, 28 insertions, 4 deletions
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0fcd9fd..91955e3 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -53,11 +53,8 @@ jobs: - name: Run Lua tests run: | - /usr/bin/lush <<EOF || true cd test - run_tests.lua - exit - EOF + lush run_tests.lua - name: Upload the compiled binary uses: actions/upload-artifact@v3 @@ -1159,11 +1159,38 @@ int main(int argc, char *argv[]) { #endif return 0; } + // init lua state lua_State *L = luaL_newstate(); luaL_openlibs(L); lua_register_api(L); lua_run_init(L); + + // if a lua function is passed on load run non-interactively + if (argc > 1) { + char *ext = strrchr(argv[1], '.'); + if (ext) { + ext++; + if (strcmp(ext, "lua") == 0) { + int status = 0; + argv++; + char ***args = lush_split_args(argv, &status); + + if (status == -1) { + fprintf(stderr, "lush: Expected end of quoted string\n"); + } else if (lush_run(L, args, status) == 0) { + exit(1); + } + + for (int i = 0; args[i]; i++) { + free(args[i]); + } + free(args); + return status; + } + } + } + // eat ^C in main struct sigaction sa; sa.sa_handler = SIG_IGN; |
