diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-11-14 10:01:35 -0200 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-11-14 10:01:35 -0200 |
| commit | 5c5d9b27031f0a7fcf61df86cd242105c38485d6 (patch) | |
| tree | 534fb1ea4a4fc82253d5bc8b0af92b91a7ae9714 /ltablib.c | |
| parent | 43d1a6af12fb9cf20e55cc6ba8a1b0231d6b7a3c (diff) | |
| download | lua-5c5d9b27031f0a7fcf61df86cd242105c38485d6.tar.gz lua-5c5d9b27031f0a7fcf61df86cd242105c38485d6.tar.bz2 lua-5c5d9b27031f0a7fcf61df86cd242105c38485d6.zip | |
back to `__mode' metafield to specify weakness
Diffstat (limited to 'ltablib.c')
| -rw-r--r-- | ltablib.c | 8 |
1 files changed, 6 insertions, 2 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ltablib.c,v 1.13 2002/10/04 14:30:31 roberto Exp roberto $ | 2 | ** $Id: ltablib.c,v 1.14 2002/10/23 19:08:23 roberto Exp roberto $ |
| 3 | ** Library for Table Manipulation | 3 | ** Library for Table Manipulation |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -288,7 +288,11 @@ static const luaL_reg tab_funcs[] = { | |||
| 288 | 288 | ||
| 289 | LUALIB_API int lua_tablibopen (lua_State *L) { | 289 | LUALIB_API int lua_tablibopen (lua_State *L) { |
| 290 | lua_newtable(L); /* create N (table to store num. elements in tables) */ | 290 | lua_newtable(L); /* create N (table to store num. elements in tables) */ |
| 291 | lua_setmode(L, -1, "k"); /* make it a weak table */ | 291 | lua_pushvalue(L, -1); /* `N' will be its own metatable */ |
| 292 | lua_setmetatable(L, -2); | ||
| 293 | lua_pushliteral(L, "__mode"); | ||
| 294 | lua_pushliteral(L, "k"); | ||
| 295 | lua_rawset(L, -3); /* metatable(N).__mode = "k" */ | ||
| 292 | luaL_opennamedlib(L, LUA_TABLIBNAME, tab_funcs, 1); | 296 | luaL_opennamedlib(L, LUA_TABLIBNAME, tab_funcs, 1); |
| 293 | return 0; | 297 | return 0; |
| 294 | } | 298 | } |
