diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1999-01-04 10:41:12 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1999-01-04 10:41:12 -0200 |
commit | 827846804196b1779a61ffdc75d0aeb157f8465d (patch) | |
tree | 7f54880a83d66cedad8cf2555144d684569f3427 /liolib.c | |
parent | 4fbb2531b3e60094e760e30fffbd9c8b2d67a238 (diff) | |
download | lua-827846804196b1779a61ffdc75d0aeb157f8465d.tar.gz lua-827846804196b1779a61ffdc75d0aeb157f8465d.tar.bz2 lua-827846804196b1779a61ffdc75d0aeb157f8465d.zip |
comments
Diffstat (limited to 'liolib.c')
-rw-r--r-- | liolib.c | 40 |
1 files changed, 31 insertions, 9 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: liolib.c,v 1.27 1998/12/27 20:21:28 roberto Exp roberto $ | 2 | ** $Id: liolib.c,v 1.28 1998/12/28 13:44:54 roberto Exp $ |
3 | ** Standard I/O (and system) library | 3 | ** Standard I/O (and system) library |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -52,11 +52,6 @@ int pclose(); | |||
52 | 52 | ||
53 | 53 | ||
54 | 54 | ||
55 | static int gettag (int i) { | ||
56 | return (int)lua_getnumber(lua_getparam(i)); | ||
57 | } | ||
58 | |||
59 | |||
60 | static void pushresult (int i) { | 55 | static void pushresult (int i) { |
61 | if (i) | 56 | if (i) |
62 | lua_pushuserdata(NULL); | 57 | lua_pushuserdata(NULL); |
@@ -68,6 +63,17 @@ static void pushresult (int i) { | |||
68 | } | 63 | } |
69 | 64 | ||
70 | 65 | ||
66 | /* | ||
67 | ** {====================================================== | ||
68 | ** FILE Operations | ||
69 | ** ======================================================= | ||
70 | */ | ||
71 | |||
72 | static int gettag (int i) { | ||
73 | return (int)lua_getnumber(lua_getparam(i)); | ||
74 | } | ||
75 | |||
76 | |||
71 | static int ishandler (lua_Object f) { | 77 | static int ishandler (lua_Object f) { |
72 | if (lua_isuserdata(f)) { | 78 | if (lua_isuserdata(f)) { |
73 | if (lua_tag(f) == gettag(CLOSEDTAG)) | 79 | if (lua_tag(f) == gettag(CLOSEDTAG)) |
@@ -190,9 +196,11 @@ static void io_appendto (void) { | |||
190 | 196 | ||
191 | 197 | ||
192 | 198 | ||
193 | /*==================================================== | 199 | /* |
200 | ** {====================================================== | ||
194 | ** READ | 201 | ** READ |
195 | **===================================================*/ | 202 | ** ======================================================= |
203 | */ | ||
196 | 204 | ||
197 | static int read_pattern (FILE *f, char *p) { | 205 | static int read_pattern (FILE *f, char *p) { |
198 | int inskip = 0; /* {skip} level */ | 206 | int inskip = 0; /* {skip} level */ |
@@ -314,6 +322,8 @@ static void io_read (void) { | |||
314 | } while ((p = luaL_opt_string(arg++, NULL)) != NULL); | 322 | } while ((p = luaL_opt_string(arg++, NULL)) != NULL); |
315 | } | 323 | } |
316 | 324 | ||
325 | /* }====================================================== */ | ||
326 | |||
317 | 327 | ||
318 | static void io_write (void) { | 328 | static void io_write (void) { |
319 | int arg = FIRSTARG; | 329 | int arg = FIRSTARG; |
@@ -350,6 +360,14 @@ static void io_flush (void) { | |||
350 | pushresult(fflush(f) == 0); | 360 | pushresult(fflush(f) == 0); |
351 | } | 361 | } |
352 | 362 | ||
363 | /* }====================================================== */ | ||
364 | |||
365 | |||
366 | /* | ||
367 | ** {====================================================== | ||
368 | ** Other O.S. Operations | ||
369 | ** ======================================================= | ||
370 | */ | ||
353 | 371 | ||
354 | static void io_execute (void) { | 372 | static void io_execute (void) { |
355 | lua_pushnumber(system(luaL_check_string(1))); | 373 | lua_pushnumber(system(luaL_check_string(1))); |
@@ -412,6 +430,9 @@ static void io_exit (void) { | |||
412 | exit(lua_isnumber(o) ? (int)lua_getnumber(o) : 1); | 430 | exit(lua_isnumber(o) ? (int)lua_getnumber(o) : 1); |
413 | } | 431 | } |
414 | 432 | ||
433 | /* }====================================================== */ | ||
434 | |||
435 | |||
415 | 436 | ||
416 | static void io_debug (void) { | 437 | static void io_debug (void) { |
417 | for (;;) { | 438 | for (;;) { |
@@ -439,7 +460,8 @@ static void errorfb (void) { | |||
439 | char *chunkname; | 460 | char *chunkname; |
440 | int linedefined; | 461 | int linedefined; |
441 | lua_funcinfo(func, &chunkname, &linedefined); | 462 | lua_funcinfo(func, &chunkname, &linedefined); |
442 | strcat(buff, (level==2) ? "Active Stack:\n\t" : "\t"); | 463 | if (level == 2) strcat(buff, "Active Stack:\n"); |
464 | strcat(buff, "\t"); | ||
443 | if (strlen(buff) > MAXMESSAGE-MESSAGESIZE) { | 465 | if (strlen(buff) > MAXMESSAGE-MESSAGESIZE) { |
444 | strcat(buff, "...\n"); | 466 | strcat(buff, "...\n"); |
445 | break; /* buffer is full */ | 467 | break; /* buffer is full */ |