aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1997-12-11 15:00:21 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1997-12-11 15:00:21 -0200
commitcdd261f332c112b86eddd7438b9a06e1231e3e4c (patch)
tree406cd291f65c81bb188f939e4092abb0ab4f2fd2
parent034f16892eb49361ee66f8d89aec26b071c98f57 (diff)
downloadlua-cdd261f332c112b86eddd7438b9a06e1231e3e4c.tar.gz
lua-cdd261f332c112b86eddd7438b9a06e1231e3e4c.tar.bz2
lua-cdd261f332c112b86eddd7438b9a06e1231e3e4c.zip
new option "-q" (quiet), and multi-line commands (ending with '\')
-rw-r--r--lua.c40
1 files changed, 31 insertions, 9 deletions
diff --git a/lua.c b/lua.c
index 8221e5bb..a155e90c 100644
--- a/lua.c
+++ b/lua.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lua.c,v 1.7 1997/12/03 19:57:54 roberto Exp roberto $ 2** $Id: lua.c,v 1.8 1997/12/11 14:48:46 roberto Exp roberto $
3** Lua stand-alone interpreter 3** Lua stand-alone interpreter
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -40,16 +40,36 @@ static void assign (char *arg)
40 } 40 }
41} 41}
42 42
43#define BUF_SIZE 512
43 44
44static void manual_input (void) 45static void manual_input (int prompt)
45{ 46{
46 if (isatty(0)) { 47 if (isatty(0)) {
47 char buffer[250]; 48 int cont = 1;
48 while (1) { 49 while (cont) {
50 char buffer[BUF_SIZE];
51 int i = 0;
49 lua_beginblock(); 52 lua_beginblock();
50 printf("%s", lua_getstring(lua_getglobal("_PROMPT"))); 53 if (prompt)
51 if (fgets(buffer, sizeof(buffer), stdin) == 0) 54 printf("%s", lua_getstring(lua_getglobal("_PROMPT")));
52 break; 55 for(;;) {
56 int c = getchar();
57 if (c == EOF) {
58 cont = 0;
59 break;
60 }
61 else if (c == '\n') {
62 if (i>0 && buffer[i-1] == '\\')
63 buffer[i-1] = '\n';
64 else break;
65 }
66 else if (i >= BUF_SIZE-1) {
67 fprintf(stderr, "lua: argument line too long\n");
68 break;
69 }
70 else buffer[i++] = c;
71 }
72 buffer[i] = 0;
53 lua_dostring(buffer); 73 lua_dostring(buffer);
54 lua_endblock(); 74 lua_endblock();
55 } 75 }
@@ -70,11 +90,13 @@ int main (int argc, char *argv[])
70 lua_pushstring("> "); lua_setglobal("_PROMPT"); 90 lua_pushstring("> "); lua_setglobal("_PROMPT");
71 if (argc < 2) { 91 if (argc < 2) {
72 printf("%s %s\n", LUA_VERSION, LUA_COPYRIGHT); 92 printf("%s %s\n", LUA_VERSION, LUA_COPYRIGHT);
73 manual_input(); 93 manual_input(1);
74 } 94 }
75 else for (i=1; i<argc; i++) { 95 else for (i=1; i<argc; i++) {
76 if (strcmp(argv[i], "-") == 0) 96 if (strcmp(argv[i], "-") == 0)
77 manual_input(); 97 manual_input(1);
98 else if (strcmp(argv[i], "-q") == 0)
99 manual_input(0);
78 else if (strcmp(argv[i], "-d") == 0) 100 else if (strcmp(argv[i], "-d") == 0)
79 lua_debug = 1; 101 lua_debug = 1;
80 else if (strcmp(argv[i], "-v") == 0) 102 else if (strcmp(argv[i], "-v") == 0)