files now have proper tags.

This commit is contained in:
Roberto Ierusalimschy 1997-03-20 17:36:58 -03:00
parent ae067dcddd
commit 052a1cc46c

13
iolib.c
View File

@ -12,6 +12,8 @@
FILE *lua_infile, *lua_outfile; FILE *lua_infile, *lua_outfile;
int lua_tagio;
#ifdef POPEN #ifdef POPEN
FILE *popen(); FILE *popen();
@ -56,7 +58,7 @@ static void io_readfrom (void)
lua_Object f = lua_getparam(1); lua_Object f = lua_getparam(1);
if (f == LUA_NOOBJECT) if (f == LUA_NOOBJECT)
closefile(lua_infile); /* restore standart input */ closefile(lua_infile); /* restore standart input */
else if (lua_isuserdata(f)) else if (lua_tag(f) == lua_tagio)
lua_infile = lua_getuserdata(f); lua_infile = lua_getuserdata(f);
else { else {
char *s = luaL_check_string(1, "readfrom"); char *s = luaL_check_string(1, "readfrom");
@ -68,7 +70,7 @@ static void io_readfrom (void)
return; return;
} }
} }
lua_pushuserdata(lua_infile); lua_pushusertag(lua_infile, lua_tagio);
} }
@ -77,7 +79,7 @@ static void io_writeto (void)
lua_Object f = lua_getparam(1); lua_Object f = lua_getparam(1);
if (f == LUA_NOOBJECT) if (f == LUA_NOOBJECT)
closefile(lua_outfile); /* restore standart output */ closefile(lua_outfile); /* restore standart output */
else if (lua_isuserdata(f)) else if (lua_tag(f) == lua_tagio)
lua_outfile = lua_getuserdata(f); lua_outfile = lua_getuserdata(f);
else { else {
char *s = luaL_check_string(1, "writeto"); char *s = luaL_check_string(1, "writeto");
@ -89,7 +91,7 @@ static void io_writeto (void)
return; return;
} }
} }
lua_pushuserdata(lua_outfile); lua_pushusertag(lua_outfile, lua_tagio);
} }
@ -99,7 +101,7 @@ static void io_appendto (void)
FILE *fp = fopen (s, "a"); FILE *fp = fopen (s, "a");
if (fp != NULL) { if (fp != NULL) {
lua_outfile = fp; lua_outfile = fp;
lua_pushuserdata(lua_outfile); lua_pushusertag(lua_outfile, lua_tagio);
} }
else else
pushresult(0); pushresult(0);
@ -294,6 +296,7 @@ static struct luaL_reg iolib[] = {
void iolib_open (void) void iolib_open (void)
{ {
lua_tagio = lua_newtag("userdata");
lua_infile=stdin; lua_outfile=stdout; lua_infile=stdin; lua_outfile=stdout;
luaL_openlib(iolib, (sizeof(iolib)/sizeof(iolib[0]))); luaL_openlib(iolib, (sizeof(iolib)/sizeof(iolib[0])));
lua_setglobalmethod("error", errorfb); lua_setglobalmethod("error", errorfb);