From 052a1cc46c3b1a2e589bd061be0e1bd153c9e47a Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Thu, 20 Mar 1997 17:36:58 -0300 Subject: files now have proper tags. --- iolib.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/iolib.c b/iolib.c index 3dfedb28..05747d37 100644 --- a/iolib.c +++ b/iolib.c @@ -12,6 +12,8 @@ FILE *lua_infile, *lua_outfile; +int lua_tagio; + #ifdef POPEN FILE *popen(); @@ -56,7 +58,7 @@ static void io_readfrom (void) lua_Object f = lua_getparam(1); if (f == LUA_NOOBJECT) closefile(lua_infile); /* restore standart input */ - else if (lua_isuserdata(f)) + else if (lua_tag(f) == lua_tagio) lua_infile = lua_getuserdata(f); else { char *s = luaL_check_string(1, "readfrom"); @@ -68,7 +70,7 @@ static void io_readfrom (void) 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); if (f == LUA_NOOBJECT) closefile(lua_outfile); /* restore standart output */ - else if (lua_isuserdata(f)) + else if (lua_tag(f) == lua_tagio) lua_outfile = lua_getuserdata(f); else { char *s = luaL_check_string(1, "writeto"); @@ -89,7 +91,7 @@ static void io_writeto (void) 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"); if (fp != NULL) { lua_outfile = fp; - lua_pushuserdata(lua_outfile); + lua_pushusertag(lua_outfile, lua_tagio); } else pushresult(0); @@ -294,6 +296,7 @@ static struct luaL_reg iolib[] = { void iolib_open (void) { + lua_tagio = lua_newtag("userdata"); lua_infile=stdin; lua_outfile=stdout; luaL_openlib(iolib, (sizeof(iolib)/sizeof(iolib[0]))); lua_setglobalmethod("error", errorfb); -- cgit v1.2.3-55-g6feb