From 69d97712ecfcd06aa4edb7374b262131210d0bbc Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Wed, 3 Dec 1997 17:57:54 -0200 Subject: arguments "var=value" doesn't need quotes for value --- lua.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/lua.c b/lua.c index 2ebfc951..d2749ca4 100644 --- a/lua.c +++ b/lua.c @@ -1,5 +1,5 @@ /* -** $Id: lua.c,v 1.5 1997/11/21 19:00:46 roberto Exp roberto $ +** $Id: lua.c,v 1.6 1997/12/01 20:31:25 roberto Exp roberto $ ** Lua stand-alone interpreter ** See Copyright Notice in lua.h */ @@ -26,6 +26,21 @@ #endif +static void assign (char *arg) +{ + if (strlen(arg) >= 500) + fprintf(stderr, "lua: shell argument too long"); + else { + char buffer[500]; + char *eq = strchr(arg, '='); + lua_pushstring(eq+1); + strncpy(buffer, arg, eq-arg); + buffer[eq-arg] = 0; + lua_setglobal(buffer); + } +} + + static void manual_input (void) { if (isatty(0)) { @@ -65,12 +80,15 @@ int main (int argc, char *argv[]) else if (strcmp(argv[i], "-v") == 0) printf("%s %s\n(written by %s)\n\n", LUA_VERSION, LUA_COPYRIGHT, LUA_AUTHORS); - else if ((strcmp(argv[i], "-e") == 0 && i++) || strchr(argv[i], '=')) { + else if (strcmp(argv[i], "-e") == 0) { + i++; if (lua_dostring(argv[i]) != 0) { fprintf(stderr, "lua: error running argument `%s'\n", argv[i]); return 1; } } + else if (strchr(argv[i], '=')) + assign(argv[i]); else { int result = lua_dofile(argv[i]); if (result) { -- cgit v1.2.3-55-g6feb