diff options
| author | 2024-09-03 14:38:18 -0400 | |
|---|---|---|
| committer | 2024-09-03 14:38:18 -0400 | |
| commit | 5568fba03dad423d3e56dd238752aa39972905fa (patch) | |
| tree | 630345deac6a5da4b7cf24e7c07ad0f355df1def /src/lush.c | |
| parent | added debug mode for scripting (diff) | |
removed need for lush command to execute lua files
Diffstat (limited to 'src/lush.c')
| -rw-r--r-- | src/lush.c | 20 |
1 files changed, 12 insertions, 8 deletions
@@ -38,10 +38,10 @@ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. #define BUFFER_SIZE 1024 // -- builtin functions -- -char *builtin_strs[] = {"cd", "help", "exit", "time", "lush"}; +char *builtin_strs[] = {"cd", "help", "exit", "time"}; int (*builtin_func[])(lua_State *, char ***) = { - &lush_cd, &lush_help, &lush_exit, &lush_time, &lush_lush}; + &lush_cd, &lush_help, &lush_exit, &lush_time, &lush_lua}; int lush_num_builtins() { return sizeof(builtin_strs) / sizeof(char *); } @@ -122,15 +122,10 @@ int lush_time(lua_State *L, char ***args) { return rc; } -int lush_lush(lua_State *L, char ***args) { - // move past lush command - args[0]++; - +int lush_lua(lua_State *L, char ***args) { // run the lua file given lua_load_script(L, args[0][0]); - // return pointer back for free() - args[0]--; return 1; } @@ -445,6 +440,15 @@ int lush_run(lua_State *L, char ***commands, int num_commands) { return 1; } + // check if the command is a lua script + char *ext = strchr(commands[0][0], '.'); + if (ext) { + ext++; + if (strcmp(ext, "lua") == 0) { + return ((*builtin_func[4])(L, commands)); + } + } + // check shell builtins for (int i = 0; i < lush_num_builtins(); i++) { if (strcmp(commands[0][0], builtin_strs[i]) == 0) { |
