summaryrefslogtreecommitdiff
path: root/lua.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1995-10-23 11:54:11 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1995-10-23 11:54:11 -0200
commitb5745d11cdd93c819f8e881504eb534c7e13badd (patch)
treeb9c0642182f045da954d8ddb7e074753eb9bab45 /lua.c
parentebcf546a551cae37835af5ddf6105e2e97706047 (diff)
downloadlua-b5745d11cdd93c819f8e881504eb534c7e13badd.tar.gz
lua-b5745d11cdd93c819f8e881504eb534c7e13badd.tar.bz2
lua-b5745d11cdd93c819f8e881504eb534c7e13badd.zip
uses "isatty" to check if executes stdin line by line or as a file.
Diffstat (limited to 'lua.c')
-rw-r--r--lua.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/lua.c b/lua.c
index 834ebe49..e961d06b 100644
--- a/lua.c
+++ b/lua.c
@@ -3,7 +3,7 @@
3** Linguagem para Usuarios de Aplicacao 3** Linguagem para Usuarios de Aplicacao
4*/ 4*/
5 5
6char *rcs_lua="$Id: lua.c,v 1.4 1995/02/07 16:04:15 lhf Exp roberto $"; 6char *rcs_lua="$Id: lua.c,v 1.5 1995/10/06 14:11:40 roberto Exp roberto $";
7 7
8#include <stdio.h> 8#include <stdio.h>
9#include <string.h> 9#include <string.h>
@@ -15,6 +15,12 @@ static int lua_argc;
15static char **lua_argv; 15static char **lua_argv;
16 16
17/* 17/*
18** although this function is POSIX, there is no standard header file that
19** defines it
20*/
21int isatty (int fd);
22
23/*
18%F Allow Lua code to access argv strings. 24%F Allow Lua code to access argv strings.
19%i Receive from Lua the argument number (starting with 1). 25%i Receive from Lua the argument number (starting with 1).
20%o Return to Lua the argument, or nil if it does not exist. 26%o Return to Lua the argument, or nil if it does not exist.
@@ -35,9 +41,14 @@ static void lua_getargv (void)
35 41
36static void manual_input (void) 42static void manual_input (void)
37{ 43{
44 if (isatty(fileno(stdin)))
45 {
38 char buffer[250]; 46 char buffer[250];
39 while (gets(buffer) != 0) 47 while (gets(buffer) != 0)
40 lua_dostring(buffer); 48 lua_dostring(buffer);
49 }
50 else
51 lua_dofile(NULL); /* executes stdin as a file */
41} 52}
42 53
43 54