diff options
| -rw-r--r-- | lua.c | 22 |
1 files changed, 20 insertions, 2 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lua.c,v 1.5 1997/11/21 19:00:46 roberto Exp roberto $ | 2 | ** $Id: lua.c,v 1.6 1997/12/01 20:31:25 roberto Exp roberto $ |
| 3 | ** Lua stand-alone interpreter | 3 | ** Lua stand-alone interpreter |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -26,6 +26,21 @@ | |||
| 26 | #endif | 26 | #endif |
| 27 | 27 | ||
| 28 | 28 | ||
| 29 | static void assign (char *arg) | ||
| 30 | { | ||
| 31 | if (strlen(arg) >= 500) | ||
| 32 | fprintf(stderr, "lua: shell argument too long"); | ||
| 33 | else { | ||
| 34 | char buffer[500]; | ||
| 35 | char *eq = strchr(arg, '='); | ||
| 36 | lua_pushstring(eq+1); | ||
| 37 | strncpy(buffer, arg, eq-arg); | ||
| 38 | buffer[eq-arg] = 0; | ||
| 39 | lua_setglobal(buffer); | ||
| 40 | } | ||
| 41 | } | ||
| 42 | |||
| 43 | |||
| 29 | static void manual_input (void) | 44 | static void manual_input (void) |
| 30 | { | 45 | { |
| 31 | if (isatty(0)) { | 46 | if (isatty(0)) { |
| @@ -65,12 +80,15 @@ int main (int argc, char *argv[]) | |||
| 65 | else if (strcmp(argv[i], "-v") == 0) | 80 | else if (strcmp(argv[i], "-v") == 0) |
| 66 | printf("%s %s\n(written by %s)\n\n", | 81 | printf("%s %s\n(written by %s)\n\n", |
| 67 | LUA_VERSION, LUA_COPYRIGHT, LUA_AUTHORS); | 82 | LUA_VERSION, LUA_COPYRIGHT, LUA_AUTHORS); |
| 68 | else if ((strcmp(argv[i], "-e") == 0 && i++) || strchr(argv[i], '=')) { | 83 | else if (strcmp(argv[i], "-e") == 0) { |
| 84 | i++; | ||
| 69 | if (lua_dostring(argv[i]) != 0) { | 85 | if (lua_dostring(argv[i]) != 0) { |
| 70 | fprintf(stderr, "lua: error running argument `%s'\n", argv[i]); | 86 | fprintf(stderr, "lua: error running argument `%s'\n", argv[i]); |
| 71 | return 1; | 87 | return 1; |
| 72 | } | 88 | } |
| 73 | } | 89 | } |
| 90 | else if (strchr(argv[i], '=')) | ||
| 91 | assign(argv[i]); | ||
| 74 | else { | 92 | else { |
| 75 | int result = lua_dofile(argv[i]); | 93 | int result = lua_dofile(argv[i]); |
| 76 | if (result) { | 94 | if (result) { |
