summaryrefslogtreecommitdiff
path: root/lua.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2004-04-30 17:13:38 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2004-04-30 17:13:38 -0300
commitb4cd38ba6c148cf7db5deae6208b660c3417cac9 (patch)
tree8818b5e364c8ad5489a9755d3fc24110bccfdfe2 /lua.c
parent079facab40542ff2e6be9ecc254fd148772b47c9 (diff)
downloadlua-b4cd38ba6c148cf7db5deae6208b660c3417cac9.tar.gz
lua-b4cd38ba6c148cf7db5deae6208b660c3417cac9.tar.bz2
lua-b4cd38ba6c148cf7db5deae6208b660c3417cac9.zip
new scheme for configuration through `luaconf.h'
Diffstat (limited to 'lua.c')
-rw-r--r--lua.c57
1 files changed, 12 insertions, 45 deletions
diff --git a/lua.c b/lua.c
index 7f0fc4ba..05ffc88e 100644
--- a/lua.c
+++ b/lua.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lua.c,v 1.123 2003/05/07 16:02:16 roberto Exp roberto $ 2** $Id: lua.c,v 1.124 2003/10/23 18:06:22 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*/
@@ -26,39 +26,6 @@
26#endif 26#endif
27 27
28 28
29/*
30** definition of `isatty'
31*/
32#ifdef _POSIX_C_SOURCE
33#include <unistd.h>
34#define stdin_is_tty() isatty(0)
35#else
36#define stdin_is_tty() 1 /* assume stdin is a tty */
37#endif
38
39
40
41#ifndef PROMPT
42#define PROMPT "> "
43#endif
44
45
46#ifndef PROMPT2
47#define PROMPT2 ">> "
48#endif
49
50#ifndef PROGNAME
51#define PROGNAME "lua"
52#endif
53
54#ifndef lua_userinit
55#define lua_userinit(L) openstdlibs(L)
56#endif
57
58
59#ifndef LUA_EXTRALIBS
60#define LUA_EXTRALIBS /* empty */
61#endif
62 29
63 30
64static lua_State *L = NULL; 31static lua_State *L = NULL;
@@ -187,14 +154,6 @@ static int load_file (const char *name) {
187} 154}
188 155
189 156
190/*
191** this macro can be used by some `history' system to save lines
192** read in manual input
193*/
194#ifndef lua_saveline
195#define lua_saveline(L,line) /* empty */
196#endif
197
198 157
199/* 158/*
200** this macro defines a function to show the prompt and reads the 159** this macro defines a function to show the prompt and reads the
@@ -291,8 +250,11 @@ static void manual_input (void) {
291} 250}
292 251
293 252
253#define clearinteractive(i) (*i &= 2)
254
294static int handle_argv (char *argv[], int *interactive) { 255static int handle_argv (char *argv[], int *interactive) {
295 if (argv[1] == NULL) { /* no more arguments? */ 256 if (argv[1] == NULL) { /* no arguments? */
257 *interactive = 0;
296 if (stdin_is_tty()) { 258 if (stdin_is_tty()) {
297 print_version(); 259 print_version();
298 manual_input(); 260 manual_input();
@@ -314,19 +276,22 @@ static int handle_argv (char *argv[], int *interactive) {
314 goto endloop; /* stop handling arguments */ 276 goto endloop; /* stop handling arguments */
315 } 277 }
316 case '\0': { 278 case '\0': {
279 clearinteractive(interactive);
317 file_input(NULL); /* executes stdin as a file */ 280 file_input(NULL); /* executes stdin as a file */
318 break; 281 break;
319 } 282 }
320 case 'i': { 283 case 'i': {
321 *interactive = 1; 284 *interactive = 2; /* force interactive mode after arguments */
322 break; 285 break;
323 } 286 }
324 case 'v': { 287 case 'v': {
288 clearinteractive(interactive);
325 print_version(); 289 print_version();
326 break; 290 break;
327 } 291 }
328 case 'e': { 292 case 'e': {
329 const char *chunk = argv[i] + 2; 293 const char *chunk = argv[i] + 2;
294 clearinteractive(interactive);
330 if (*chunk == '\0') chunk = argv[++i]; 295 if (*chunk == '\0') chunk = argv[++i];
331 if (chunk == NULL) { 296 if (chunk == NULL) {
332 print_usage(); 297 print_usage();
@@ -356,6 +321,7 @@ static int handle_argv (char *argv[], int *interactive) {
356 break; 321 break;
357 } 322 }
358 default: { 323 default: {
324 clearinteractive(interactive);
359 print_usage(); 325 print_usage();
360 return 1; 326 return 1;
361 } 327 }
@@ -364,6 +330,7 @@ static int handle_argv (char *argv[], int *interactive) {
364 if (argv[i] != NULL) { 330 if (argv[i] != NULL) {
365 const char *filename = argv[i]; 331 const char *filename = argv[i];
366 getargs(argv, i); /* collect arguments */ 332 getargs(argv, i); /* collect arguments */
333 clearinteractive(interactive);
367 lua_setglobal(L, "arg"); 334 lua_setglobal(L, "arg");
368 return file_input(filename); /* stop scanning arguments */ 335 return file_input(filename); /* stop scanning arguments */
369 } 336 }
@@ -401,7 +368,7 @@ struct Smain {
401static int pmain (lua_State *l) { 368static int pmain (lua_State *l) {
402 struct Smain *s = (struct Smain *)lua_touserdata(l, 1); 369 struct Smain *s = (struct Smain *)lua_touserdata(l, 1);
403 int status; 370 int status;
404 int interactive = 0; 371 int interactive = 1;
405 if (s->argv[0] && s->argv[0][0]) progname = s->argv[0]; 372 if (s->argv[0] && s->argv[0][0]) progname = s->argv[0];
406 L = l; 373 L = l;
407 lua_userinit(l); /* open libraries */ 374 lua_userinit(l); /* open libraries */