Lua cannot have static variables.

This commit is contained in:
Roberto Ierusalimschy 1999-02-05 13:22:43 -02:00
parent 8fdd06ba3c
commit b22baf386d

View File

@ -1,5 +1,5 @@
/* /*
** $Id: liolib.c,v 1.28 1998/12/28 13:44:54 roberto Exp $ ** $Id: liolib.c,v 1.29 1999/01/04 12:41:12 roberto Exp roberto $
** Standard I/O (and system) library ** Standard I/O (and system) library
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -40,6 +40,7 @@
#define FINPUT "_INPUT" #define FINPUT "_INPUT"
#define FOUTPUT "_OUTPUT" #define FOUTPUT "_OUTPUT"
#define MODESIZE 3 /* string for file mode */
#ifdef POPEN #ifdef POPEN
FILE *popen(); FILE *popen();
@ -108,15 +109,13 @@ static FILE *getfileparam (char *name, int *arg) {
} }
static char *getmode (char mode) { static void getmode (char mode, char *m) {
static char m[3];
m[0] = mode; m[0] = mode;
if (*luaL_opt_string(FIRSTARG+1, "text") == 'b') { if (*luaL_opt_string(FIRSTARG+1, "text") == 'b') {
m[1] = 'b'; m[1] = 'b';
m[2] = '\0'; m[2] = '\0';
} }
else m[1] = '\0'; else m[1] = '\0';
return m;
} }
@ -154,7 +153,9 @@ static void io_readfrom (void) {
current = lua_getuserdata(f); current = lua_getuserdata(f);
else { else {
char *s = luaL_check_string(FIRSTARG); char *s = luaL_check_string(FIRSTARG);
current = (*s == '|') ? popen(s+1, "r") : fopen(s, getmode('r')); char m[MODESIZE];
getmode('r', m);
current = (*s == '|') ? popen(s+1, "r") : fopen(s, m);
if (current == NULL) { if (current == NULL) {
pushresult(0); pushresult(0);
return; return;
@ -175,7 +176,9 @@ static void io_writeto (void) {
current = lua_getuserdata(f); current = lua_getuserdata(f);
else { else {
char *s = luaL_check_string(FIRSTARG); char *s = luaL_check_string(FIRSTARG);
current = (*s == '|') ? popen(s+1,"w") : fopen(s,getmode('w')); char m[MODESIZE];
getmode('w', m);
current = (*s == '|') ? popen(s+1,"w") : fopen(s, m);
if (current == NULL) { if (current == NULL) {
pushresult(0); pushresult(0);
return; return;
@ -187,7 +190,10 @@ static void io_writeto (void) {
static void io_appendto (void) { static void io_appendto (void) {
char *s = luaL_check_string(FIRSTARG); char *s = luaL_check_string(FIRSTARG);
FILE *fp = fopen (s, getmode('a')); char m[MODESIZE];
FILE *fp;
getmode('a', m);
fp = fopen (s, m);
if (fp != NULL) if (fp != NULL)
setreturn(fp, FOUTPUT); setreturn(fp, FOUTPUT);
else else