aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2000-05-10 14:00:21 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2000-05-10 14:00:21 -0300
commit8ac0bbf64b93a672c6f29c2d96d22d727035e9ed (patch)
tree975761662d52e65c32ee0201c5790546230c972a
parentdc1e4f50734705830c3fbae3c3d643184d6614ff (diff)
downloadlua-8ac0bbf64b93a672c6f29c2d96d22d727035e9ed.tar.gz
lua-8ac0bbf64b93a672c6f29c2d96d22d727035e9ed.tar.bz2
lua-8ac0bbf64b93a672c6f29c2d96d22d727035e9ed.zip
new option `-c' to close lua.
-rw-r--r--lua.c27
1 files changed, 16 insertions, 11 deletions
diff --git a/lua.c b/lua.c
index b4fc603b..fadc3688 100644
--- a/lua.c
+++ b/lua.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lua.c,v 1.36 2000/03/30 17:19:48 roberto Exp roberto $ 2** $Id: lua.c,v 1.37 2000/04/14 17:46:29 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*/
@@ -69,6 +69,7 @@ static void print_message (void) {
69 fprintf(stderr, 69 fprintf(stderr,
70 "usage: lua [options]. Available options are:\n" 70 "usage: lua [options]. Available options are:\n"
71 " - execute stdin as a file\n" 71 " - execute stdin as a file\n"
72 " -c close lua when exiting\n"
72 " -d turn debug on\n" 73 " -d turn debug on\n"
73 " -e stat execute string `stat'\n" 74 " -e stat execute string `stat'\n"
74 " -f name execute file `name' with remaining arguments in table `arg'\n" 75 " -f name execute file `name' with remaining arguments in table `arg'\n"
@@ -166,12 +167,14 @@ static void manual_input (int version, int prompt) {
166 167
167 168
168int main (int argc, char *argv[]) { 169int main (int argc, char *argv[]) {
170 int toclose = 0;
171 int status = EXIT_SUCCESS;
169 int i = 1; 172 int i = 1;
170 if (i < argc && argv[1][0] == '-' && argv[1][1] == 's') { 173 if (i < argc && argv[1][0] == '-' && argv[1][1] == 's') {
171 int stacksize = atoi(&argv[1][2]); 174 int stacksize = atoi(&argv[1][2]);
172 if (stacksize == 0) { 175 if (stacksize == 0) {
173 fprintf(stderr, "lua: invalid stack size ('%s')\n", &argv[1][2]); 176 fprintf(stderr, "lua: invalid stack size ('%s')\n", &argv[1][2]);
174 exit(1); 177 exit(EXIT_FAILURE);
175 } 178 }
176 i++; 179 i++;
177 lua_state = lua_newstate("stack", stacksize, NULL); 180 lua_state = lua_newstate("stack", stacksize, NULL);
@@ -207,6 +210,9 @@ int main (int argc, char *argv[]) {
207 manual_input(1, 1); 210 manual_input(1, 1);
208 } 211 }
209 break; 212 break;
213 case 'c':
214 toclose = 1;
215 break;
210 case 'v': 216 case 'v':
211 print_version(); 217 print_version();
212 break; 218 break;
@@ -214,18 +220,18 @@ int main (int argc, char *argv[]) {
214 i++; 220 i++;
215 if (i >= argc) { 221 if (i >= argc) {
216 print_message(); 222 print_message();
217 exit(1); 223 status = EXIT_FAILURE; goto endloop;
218 } 224 }
219 if (ldo(lua_dostring, argv[i]) != 0) { 225 if (ldo(lua_dostring, argv[i]) != 0) {
220 fprintf(stderr, "lua: error running argument `%s'\n", argv[i]); 226 fprintf(stderr, "lua: error running argument `%s'\n", argv[i]);
221 exit(1); 227 status = EXIT_FAILURE; goto endloop;
222 } 228 }
223 break; 229 break;
224 case 'f': 230 case 'f':
225 i++; 231 i++;
226 if (i >= argc) { 232 if (i >= argc) {
227 print_message(); 233 print_message();
228 exit(1); 234 status = EXIT_FAILURE; goto endloop;
229 } 235 }
230 lua_pushobject(getargs(argv+i)); /* collect remaining arguments */ 236 lua_pushobject(getargs(argv+i)); /* collect remaining arguments */
231 lua_setglobal("arg"); 237 lua_setglobal("arg");
@@ -234,10 +240,10 @@ int main (int argc, char *argv[]) {
234 break; 240 break;
235 case 's': 241 case 's':
236 fprintf(stderr, "lua: stack size (`-s') must be the first option\n"); 242 fprintf(stderr, "lua: stack size (`-s') must be the first option\n");
237 exit(1); 243 status = EXIT_FAILURE; goto endloop;
238 default: 244 default:
239 print_message(); 245 print_message();
240 exit(1); 246 status = EXIT_FAILURE; goto endloop;
241 } 247 }
242 } 248 }
243 else if (strchr(argv[i], '=')) 249 else if (strchr(argv[i], '='))
@@ -246,9 +252,8 @@ int main (int argc, char *argv[]) {
246 file_input(argv[i]); 252 file_input(argv[i]);
247 } 253 }
248 endloop: 254 endloop:
249#ifdef DEBUG 255 if (toclose)
250 lua_close(); 256 lua_close();
251#endif 257 return status;
252 return 0;
253} 258}
254 259