From e8f35fc4ff01c09b3529e25caeca047e3e1e3517 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Thu, 19 Sep 2002 17:12:47 -0300 Subject: unification of __index & __gettable (and __newindex & __settable) --- liolib.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) (limited to 'liolib.c') diff --git a/liolib.c b/liolib.c index 042657be..d0799122 100644 --- a/liolib.c +++ b/liolib.c @@ -1,5 +1,5 @@ /* -** $Id: liolib.c,v 2.17 2002/08/21 14:57:48 roberto Exp roberto $ +** $Id: liolib.c,v 2.18 2002/09/17 20:35:54 roberto Exp roberto $ ** Standard I/O (and system) library ** See Copyright Notice in lua.h */ @@ -440,21 +440,20 @@ static const luaL_reg flib[] = { static void createmeta (lua_State *L) { - lua_pushliteral(L, FILEHANDLE); /* S: FH */ - lua_newtable(L); /* S: mt FH */ + lua_pushliteral(L, FILEHANDLE); + lua_newtable(L); /* push new metatable for file handles */ /* close files when collected */ - lua_pushliteral(L, "__gc"); /* S: `gc' mt FH */ - lua_pushvalue(L, -2); /* S: mt `gc' mt FH */ - lua_pushcclosure(L, io_gc, 1); /* S: close `gc' mt FH */ - lua_rawset(L, -3); /* S: mt FH */ + lua_pushliteral(L, "__gc"); + lua_pushvalue(L, -2); /* push metatable (will be upvalue for `gc' method) */ + lua_pushcclosure(L, io_gc, 1); + lua_rawset(L, -3); /* metatable.__gc = io_gc */ /* file methods */ - lua_pushliteral(L, "__gettable"); /* S: `gettable' mt FH */ - lua_pushvalue(L, -2); /* S: mt `gettable' mt FH */ - lua_rawset(L, -3); /* S: mt FH */ - lua_pushvalue(L, -1); /* S: mt mt FH */ - luaL_openlib(L, flib, 1); /* S: mt FH */ - /* put new metatable into registry */ - lua_rawset(L, LUA_REGISTRYINDEX); /* S: empty */ + lua_pushliteral(L, "__index"); + lua_pushvalue(L, -2); /* push metatable */ + lua_rawset(L, -3); /* metatable.__index = metatable */ + lua_pushvalue(L, -1); /* push metatable (will be upvalue for library) */ + luaL_openlib(L, flib, 1); + lua_rawset(L, LUA_REGISTRYINDEX); /* registry.FILEHANDLE = metatable */ } /* }====================================================== */ -- cgit v1.2.3-55-g6feb