From 5568fba03dad423d3e56dd238752aa39972905fa Mon Sep 17 00:00:00 2001 From: BanceDev Date: Tue, 3 Sep 2024 14:38:18 -0400 Subject: removed need for lush command to execute lua files --- src/lush.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'src/lush.c') diff --git a/src/lush.c b/src/lush.c index bdb9ba5..ff8bbb1 100644 --- a/src/lush.c +++ b/src/lush.c @@ -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) { -- cgit v1.2.3-59-g8ed1b