diff options
author | Lua Team <team@lua.org> | 1995-02-07 12:00:00 +0000 |
---|---|---|
committer | repogen <> | 1995-02-07 12:00:00 +0000 |
commit | a8b6ba0954edb9e0e669e1f451b9a8f145ce5166 (patch) | |
tree | 35e9e9999968c4f13a25a5f647203456f044274a /clients/lua | |
parent | 944fc7d7d95575f2b8023c1f3d4ac19e1369fc76 (diff) | |
download | lua-github-2.1.tar.gz |
Lua 2.12.1
Diffstat (limited to 'clients/lua')
-rw-r--r-- | clients/lua/Makefile | 12 | ||||
-rw-r--r-- | clients/lua/lua.c | 58 |
2 files changed, 63 insertions, 7 deletions
diff --git a/clients/lua/Makefile b/clients/lua/Makefile index 7bb74208..10538d67 100644 --- a/clients/lua/Makefile +++ b/clients/lua/Makefile @@ -5,13 +5,23 @@ INC= $(LUA)/include LIB= $(LUA)/lib CC= gcc -CFLAGS= -g -Wall -O2 -I$(INC) +CFLAGS= $(INCS) $(DEFS) $(WARN) -O2 + +# in SunOs /usr/5include contains prototypes for standard lib +INCS= -I/usr/5include -I$(INC) +WARN= -Wall -Wmissing-prototypes -Wshadow -ansi OBJS= lua.o + T=$(BIN)/lua $T: $(OBJS) $(CC) -o $@ $(OBJS) -L$(LIB) -llua -llualib -lm +dynamic: + clean: rm -f $T $(OBJS) + +co: + co -M lua.c diff --git a/clients/lua/lua.c b/clients/lua/lua.c index c4b83cee..19836646 100644 --- a/clients/lua/lua.c +++ b/clients/lua/lua.c @@ -3,26 +3,72 @@ ** Linguagem para Usuarios de Aplicacao */ -char *rcs_lua="$Id: lua.c,v 1.1 1993/12/17 18:41:19 celes Exp $"; +char *rcs_lua="$Id: lua.c,v 1.4 1995/02/07 16:04:15 lhf Exp $"; #include <stdio.h> +#include <string.h> #include "lua.h" #include "lualib.h" -void main (int argc, char *argv[]) +static int lua_argc; +static char **lua_argv; + +/* +%F Allow Lua code to access argv strings. +%i Receive from Lua the argument number (starting with 1). +%o Return to Lua the argument, or nil if it does not exist. +*/ +static void lua_getargv (void) +{ + lua_Object lo = lua_getparam(1); + if (!lua_isnumber(lo)) + lua_pushnil(); + else + { + int n = (int)lua_getnumber(lo); + if (n < 1 || n > lua_argc) lua_pushnil(); + else lua_pushstring(lua_argv[n]); + } +} + + +int main (int argc, char *argv[]) { int i; + int result = 0; iolib_open (); strlib_open (); mathlib_open (); + + lua_register("argv", lua_getargv); + if (argc < 2) { - char buffer[2048]; + char buffer[250]; while (gets(buffer) != 0) - lua_dostring(buffer); + result = lua_dostring(buffer); } else - for (i=1; i<argc; i++) - lua_dofile (argv[i]); + { + for (i=1; i<argc; i++) + { + if (strcmp(argv[i], "--") == 0) + { + lua_argc = argc-i-1; + lua_argv = argv+i; + break; + } + } + for (i=1; i<argc; i++) + { + if (strcmp(argv[i], "--") == 0) + break; + else + result = lua_dofile (argv[i]); + } + } + return result; } + + |