diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-08-06 14:06:56 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-08-06 14:06:56 -0300 |
| commit | 634344d61fb4bd7ebd033d37b814a0083e55b5a2 (patch) | |
| tree | 01794c51e00c7ec1faec1e08fe2963ee75b1a139 /lapi.c | |
| parent | a2fa48a570b01b2a2cd37f01799f08f693fc5892 (diff) | |
| download | lua-634344d61fb4bd7ebd033d37b814a0083e55b5a2.tar.gz lua-634344d61fb4bd7ebd033d37b814a0083e55b5a2.tar.bz2 lua-634344d61fb4bd7ebd033d37b814a0083e55b5a2.zip | |
new API for weak mode
Diffstat (limited to '')
| -rw-r--r-- | lapi.c | 27 |
1 files changed, 26 insertions, 1 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lapi.c,v 1.206 2002/08/05 14:43:38 roberto Exp roberto $ | 2 | ** $Id: lapi.c,v 1.207 2002/08/06 15:32:22 roberto Exp roberto $ |
| 3 | ** Lua API | 3 | ** Lua API |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -464,6 +464,20 @@ LUA_API void lua_newtable (lua_State *L) { | |||
| 464 | } | 464 | } |
| 465 | 465 | ||
| 466 | 466 | ||
| 467 | LUA_API const char *lua_getmode (lua_State *L, int index) { | ||
| 468 | static const char *const modes[] = {"", "k", "v", "kv"}; | ||
| 469 | int mode = 0; | ||
| 470 | TObject *t; | ||
| 471 | lua_lock(L); | ||
| 472 | t = luaA_index(L, index); | ||
| 473 | api_check(L, ttistable(t)); | ||
| 474 | if (hvalue(t)->mode & WEAKKEY) mode += 1; | ||
| 475 | if (hvalue(t)->mode & WEAKVALUE) mode += 2; | ||
| 476 | lua_unlock(L); | ||
| 477 | return modes[mode]; | ||
| 478 | } | ||
| 479 | |||
| 480 | |||
| 467 | LUA_API int lua_getmetatable (lua_State *L, int objindex) { | 481 | LUA_API int lua_getmetatable (lua_State *L, int objindex) { |
| 468 | StkId obj; | 482 | StkId obj; |
| 469 | Table *mt; | 483 | Table *mt; |
| @@ -555,6 +569,17 @@ LUA_API void lua_rawseti (lua_State *L, int index, int n) { | |||
| 555 | } | 569 | } |
| 556 | 570 | ||
| 557 | 571 | ||
| 572 | LUA_API void lua_setmode (lua_State *L, int index, const char *mode) { | ||
| 573 | TObject *t; | ||
| 574 | lua_lock(L); | ||
| 575 | t = luaA_index(L, index); | ||
| 576 | api_check(L, ttistable(t)); | ||
| 577 | hvalue(t)->mode &= ~(WEAKKEY | WEAKVALUE); /* clear bits */ | ||
| 578 | if (strchr(mode, 'k')) hvalue(t)->mode |= WEAKKEY; | ||
| 579 | if (strchr(mode, 'v')) hvalue(t)->mode |= WEAKVALUE; | ||
| 580 | lua_unlock(L); | ||
| 581 | } | ||
| 582 | |||
| 558 | LUA_API int lua_setmetatable (lua_State *L, int objindex) { | 583 | LUA_API int lua_setmetatable (lua_State *L, int objindex) { |
| 559 | TObject *obj, *mt; | 584 | TObject *obj, *mt; |
| 560 | int res = 1; | 585 | int res = 1; |
