aboutsummaryrefslogtreecommitdiffstats
path: root/src/lush.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lush.c')
-rw-r--r--src/lush.c20
1 files changed, 12 insertions, 8 deletions
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) {