From b2c89ed2d21b50dea460415003e3f2f4d7188818 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Wed, 18 Aug 1999 14:40:54 -0300 Subject: [PATCH] new mechanism to access argv from a script --- lua.c | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/lua.c b/lua.c index 474e583f..ec185a17 100644 --- a/lua.c +++ b/lua.c @@ -1,5 +1,5 @@ /* -** $Id: lua.c,v 1.21 1999/07/02 18:22:38 roberto Exp roberto $ +** $Id: lua.c,v 1.22 1999/08/16 20:52:00 roberto Exp roberto $ ** Lua stand-alone interpreter ** See Copyright Notice in lua.h */ @@ -69,8 +69,9 @@ static void print_message (void) { " -e stat dostring `stat'\n" " -q interactive mode without prompt\n" " -i interactive mode with prompt\n" -" - executes stdin as a file\n" -" a=b sets global `a' with string `b'\n" +" - execute stdin as a file\n" +" -- start arguments for table `arg'\n" +" a=b set global `a' with string `b'\n" " name dofile `name'\n\n"); } @@ -89,6 +90,27 @@ static void assign (char *arg) { } +static void getargs (int argc, char *argv[]) { + int i, j; + lua_Object args = lua_createtable(); + lua_pushobject(args); + lua_setglobal("arg"); + for (i=0; i "); lua_setglobal("_PROMPT"); lua_userinit(); + getargs(argc, argv); if (argc < 2) { /* no arguments? */ if (isatty(0)) { printf("%s %s\n", LUA_VERSION, LUA_COPYRIGHT); @@ -162,6 +184,9 @@ int main (int argc, char *argv[]) return 1; } break; + case '-': + i = argc; /* end loop */ + break; default: print_message(); exit(1);