diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2003-02-11 13:24:52 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2003-02-11 13:24:52 -0200 |
commit | 5085f09ce55fad35b24ff0ffa28b26eeb87d1c01 (patch) | |
tree | 8c151a9209b737e477f17c80e0195a6e94fc5b7e | |
parent | d67462639223159372371a24c41e87376c8b3569 (diff) | |
download | lua-5085f09ce55fad35b24ff0ffa28b26eeb87d1c01.tar.gz lua-5085f09ce55fad35b24ff0ffa28b26eeb87d1c01.tar.bz2 lua-5085f09ce55fad35b24ff0ffa28b26eeb87d1c01.zip |
small optimizations
-rw-r--r-- | liolib.c | 13 |
1 files changed, 3 insertions, 10 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: liolib.c,v 2.29 2002/12/20 10:26:33 roberto Exp roberto $ | 2 | ** $Id: liolib.c,v 2.30 2003/01/17 15:27:28 roberto Exp roberto $ |
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 | */ |
@@ -499,6 +499,8 @@ static const luaL_reg flib[] = { | |||
499 | {"seek", f_seek}, | 499 | {"seek", f_seek}, |
500 | {"write", f_write}, | 500 | {"write", f_write}, |
501 | {"close", io_close}, | 501 | {"close", io_close}, |
502 | {"__gc", io_gc}, | ||
503 | {"__tostring", io_tostring}, | ||
502 | {NULL, NULL} | 504 | {NULL, NULL} |
503 | }; | 505 | }; |
504 | 506 | ||
@@ -506,15 +508,6 @@ static const luaL_reg flib[] = { | |||
506 | static void createmeta (lua_State *L) { | 508 | static void createmeta (lua_State *L) { |
507 | lua_pushliteral(L, FILEHANDLE); | 509 | lua_pushliteral(L, FILEHANDLE); |
508 | lua_newtable(L); /* push new metatable for file handles */ | 510 | lua_newtable(L); /* push new metatable for file handles */ |
509 | /* close files when collected */ | ||
510 | lua_pushliteral(L, "__gc"); | ||
511 | lua_pushvalue(L, -2); /* push metatable (will be upvalue for `gc' method) */ | ||
512 | lua_pushcclosure(L, io_gc, 1); | ||
513 | lua_rawset(L, -3); /* metatable.__gc = io_gc */ | ||
514 | lua_pushliteral(L, "__tostring"); | ||
515 | lua_pushvalue(L, -2); /* push metatable */ | ||
516 | lua_pushcclosure(L, io_tostring, 1); | ||
517 | lua_rawset(L, -3); | ||
518 | /* file methods */ | 511 | /* file methods */ |
519 | lua_pushliteral(L, "__index"); | 512 | lua_pushliteral(L, "__index"); |
520 | lua_pushvalue(L, -2); /* push metatable */ | 513 | lua_pushvalue(L, -2); /* push metatable */ |