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 | |
parent | 6fb0fd506367d70fb83a7885441fc5bd499e937a (diff) | |
download | lua-e8f35fc4ff01c09b3529e25caeca047e3e1e3517.tar.gz lua-e8f35fc4ff01c09b3529e25caeca047e3e1e3517.tar.bz2 lua-e8f35fc4ff01c09b3529e25caeca047e3e1e3517.zip |
unification of __index & __gettable (and __newindex & __settable)
-rw-r--r-- | liolib.c | 27 | ||||
-rw-r--r-- | ltm.c | 3 | ||||
-rw-r--r-- | ltm.h | 4 | ||||
-rw-r--r-- | lvm.c | 6 |
4 files changed, 18 insertions, 22 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 | /* }====================================================== */ |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ltm.c,v 1.100 2002/08/06 17:06:56 roberto Exp roberto $ | 2 | ** $Id: ltm.c,v 1.101 2002/08/30 19:09:21 roberto Exp roberto $ |
3 | ** Tag methods | 3 | ** Tag methods |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -27,7 +27,6 @@ void luaT_init (lua_State *L) { | |||
27 | static const char *const luaT_eventname[] = { /* ORDER TM */ | 27 | static const char *const luaT_eventname[] = { /* ORDER TM */ |
28 | "__index", "__newindex", | 28 | "__index", "__newindex", |
29 | "__gc", "__eq", | 29 | "__gc", "__eq", |
30 | "__gettable", "__settable", | ||
31 | "__add", "__sub", "__mul", "__div", | 30 | "__add", "__sub", "__mul", "__div", |
32 | "__pow", "__unm", "__lt", "__le", | 31 | "__pow", "__unm", "__lt", "__le", |
33 | "__concat", "__call" | 32 | "__concat", "__call" |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ltm.h,v 1.38 2002/07/01 17:06:58 roberto Exp roberto $ | 2 | ** $Id: ltm.h,v 1.39 2002/08/06 17:06:56 roberto Exp roberto $ |
3 | ** Tag methods | 3 | ** Tag methods |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -20,8 +20,6 @@ typedef enum { | |||
20 | TM_NEWINDEX, | 20 | TM_NEWINDEX, |
21 | TM_GC, | 21 | TM_GC, |
22 | TM_EQ, /* last tag method with `fast' access */ | 22 | TM_EQ, /* last tag method with `fast' access */ |
23 | TM_GETTABLE, | ||
24 | TM_SETTABLE, | ||
25 | TM_ADD, | 23 | TM_ADD, |
26 | TM_SUB, | 24 | TM_SUB, |
27 | TM_MUL, | 25 | TM_MUL, |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lvm.c,v 1.254 2002/08/21 18:56:19 roberto Exp roberto $ | 2 | ** $Id: lvm.c,v 1.255 2002/09/19 13:03:53 roberto Exp roberto $ |
3 | ** Lua virtual machine | 3 | ** Lua virtual machine |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -134,7 +134,7 @@ static const TObject *luaV_index (lua_State *L, const TObject *t, | |||
134 | 134 | ||
135 | static const TObject *luaV_getnotable (lua_State *L, const TObject *t, | 135 | static const TObject *luaV_getnotable (lua_State *L, const TObject *t, |
136 | TObject *key, int loop) { | 136 | TObject *key, int loop) { |
137 | const TObject *tm = luaT_gettmbyobj(L, t, TM_GETTABLE); | 137 | const TObject *tm = luaT_gettmbyobj(L, t, TM_INDEX); |
138 | if (ttisnil(tm)) | 138 | if (ttisnil(tm)) |
139 | luaG_typeerror(L, t, "index"); | 139 | luaG_typeerror(L, t, "index"); |
140 | if (ttisfunction(tm)) { | 140 | if (ttisfunction(tm)) { |
@@ -181,7 +181,7 @@ void luaV_settable (lua_State *L, const TObject *t, TObject *key, StkId val) { | |||
181 | } | 181 | } |
182 | /* else will try the tag method */ | 182 | /* else will try the tag method */ |
183 | } | 183 | } |
184 | else if (ttisnil(tm = luaT_gettmbyobj(L, t, TM_SETTABLE))) | 184 | else if (ttisnil(tm = luaT_gettmbyobj(L, t, TM_NEWINDEX))) |
185 | luaG_typeerror(L, t, "index"); | 185 | luaG_typeerror(L, t, "index"); |
186 | if (ttisfunction(tm)) { | 186 | if (ttisfunction(tm)) { |
187 | callTM(L, tm, t, key, val); | 187 | callTM(L, tm, t, key, val); |