summaryrefslogtreecommitdiff
path: root/clients/lua
diff options
context:
space:
mode:
authorLua Team <team@lua.org>1995-11-28 12:00:00 +0000
committerrepogen <>1995-11-28 12:00:00 +0000
commit71754d2f6423fb9b6e87658e58bafc5470d53f65 (patch)
treec704e97b80e52a52d3152738941bb4c8ca676b97 /clients/lua
parenta8b6ba0954edb9e0e669e1f451b9a8f145ce5166 (diff)
downloadlua-github-2.2.tar.gz
Lua 2.22.2
Diffstat (limited to 'clients/lua')
-rw-r--r--clients/lua/Makefile8
-rw-r--r--clients/lua/lua.c34
2 files changed, 33 insertions, 9 deletions
diff --git a/clients/lua/Makefile b/clients/lua/Makefile
index 10538d67..b76dae3c 100644
--- a/clients/lua/Makefile
+++ b/clients/lua/Makefile
@@ -12,6 +12,7 @@ INCS= -I/usr/5include -I$(INC)
WARN= -Wall -Wmissing-prototypes -Wshadow -ansi
OBJS= lua.o
+SRCS= lua.c
T=$(BIN)/lua
@@ -19,9 +20,14 @@ $T: $(OBJS)
$(CC) -o $@ $(OBJS) -L$(LIB) -llua -llualib -lm
dynamic:
+ rm -f $T
+ make
clean:
rm -f $T $(OBJS)
co:
- co -M lua.c
+ co -f -M $(SRCS)
+
+klean: clean
+ rm -f $(SRCS)
diff --git a/clients/lua/lua.c b/clients/lua/lua.c
index 19836646..33c7adcb 100644
--- a/clients/lua/lua.c
+++ b/clients/lua/lua.c
@@ -3,7 +3,7 @@
** Linguagem para Usuarios de Aplicacao
*/
-char *rcs_lua="$Id: lua.c,v 1.4 1995/02/07 16:04:15 lhf Exp $";
+char *rcs_lua="$Id: lua.c,v 1.7 1995/10/31 17:05:35 roberto Exp $";
#include <stdio.h>
#include <string.h>
@@ -15,6 +15,12 @@ static int lua_argc;
static char **lua_argv;
/*
+** although this function is POSIX, there is no standard header file that
+** defines it
+*/
+int isatty (int fd);
+
+/*
%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.
@@ -33,6 +39,19 @@ static void lua_getargv (void)
}
+static void manual_input (void)
+{
+ if (isatty(fileno(stdin)))
+ {
+ char buffer[250];
+ while (gets(buffer) != 0)
+ lua_dostring(buffer);
+ }
+ else
+ lua_dofile(NULL); /* executes stdin as a file */
+}
+
+
int main (int argc, char *argv[])
{
int i;
@@ -44,26 +63,25 @@ int main (int argc, char *argv[])
lua_register("argv", lua_getargv);
if (argc < 2)
- {
- char buffer[250];
- while (gets(buffer) != 0)
- result = lua_dostring(buffer);
- }
+ manual_input();
else
{
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 if (strcmp(argv[i], "-") == 0)
+ manual_input();
+ else if (strcmp(argv[i], "-v") == 0)
+ printf("%s %s\n(written by %s)\n\n",
+ LUA_VERSION, LUA_COPYRIGHT, LUA_AUTHORS);
else
result = lua_dofile (argv[i]);
}