summaryrefslogtreecommitdiff
path: root/liolib.c
diff options
context:
space:
mode:
Diffstat (limited to 'liolib.c')
-rw-r--r--liolib.c27
1 files changed, 13 insertions, 14 deletions
diff --git a/liolib.c b/liolib.c
index 042657be..d0799122 100644
--- a/liolib.c
+++ b/liolib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: liolib.c,v 2.17 2002/08/21 14:57:48 roberto Exp roberto $ 2** $Id: liolib.c,v 2.18 2002/09/17 20:35:54 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*/
@@ -440,21 +440,20 @@ static const luaL_reg flib[] = {
440 440
441 441
442static void createmeta (lua_State *L) { 442static void createmeta (lua_State *L) {
443 lua_pushliteral(L, FILEHANDLE); /* S: FH */ 443 lua_pushliteral(L, FILEHANDLE);
444 lua_newtable(L); /* S: mt FH */ 444 lua_newtable(L); /* push new metatable for file handles */
445 /* close files when collected */ 445 /* close files when collected */
446 lua_pushliteral(L, "__gc"); /* S: `gc' mt FH */ 446 lua_pushliteral(L, "__gc");
447 lua_pushvalue(L, -2); /* S: mt `gc' mt FH */ 447 lua_pushvalue(L, -2); /* push metatable (will be upvalue for `gc' method) */
448 lua_pushcclosure(L, io_gc, 1); /* S: close `gc' mt FH */ 448 lua_pushcclosure(L, io_gc, 1);
449 lua_rawset(L, -3); /* S: mt FH */ 449 lua_rawset(L, -3); /* metatable.__gc = io_gc */
450 /* file methods */ 450 /* file methods */
451 lua_pushliteral(L, "__gettable"); /* S: `gettable' mt FH */ 451 lua_pushliteral(L, "__index");
452 lua_pushvalue(L, -2); /* S: mt `gettable' mt FH */ 452 lua_pushvalue(L, -2); /* push metatable */
453 lua_rawset(L, -3); /* S: mt FH */ 453 lua_rawset(L, -3); /* metatable.__index = metatable */
454 lua_pushvalue(L, -1); /* S: mt mt FH */ 454 lua_pushvalue(L, -1); /* push metatable (will be upvalue for library) */
455 luaL_openlib(L, flib, 1); /* S: mt FH */ 455 luaL_openlib(L, flib, 1);
456 /* put new metatable into registry */ 456 lua_rawset(L, LUA_REGISTRYINDEX); /* registry.FILEHANDLE = metatable */
457 lua_rawset(L, LUA_REGISTRYINDEX); /* S: empty */
458} 457}
459 458
460/* }====================================================== */ 459/* }====================================================== */