diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-09-19 17:12:47 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-09-19 17:12:47 -0300 |
commit | e8f35fc4ff01c09b3529e25caeca047e3e1e3517 (patch) | |
tree | dbe5bdbdb9a39343789f057a38a3873420a06d23 /liolib.c | |
parent | 6fb0fd506367d70fb83a7885441fc5bd499e937a (diff) | |
download | lua-e8f35fc4ff01c09b3529e25caeca047e3e1e3517.tar.gz lua-e8f35fc4ff01c09b3529e25caeca047e3e1e3517.tar.bz2 lua-e8f35fc4ff01c09b3529e25caeca047e3e1e3517.zip |
unification of __index & __gettable (and __newindex & __settable)
Diffstat (limited to 'liolib.c')
-rw-r--r-- | liolib.c | 27 |
1 files changed, 13 insertions, 14 deletions
@@ -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 | ||
442 | static void createmeta (lua_State *L) { | 442 | static 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 | /* }====================================================== */ |