aboutsummaryrefslogtreecommitdiff
path: root/lapi.c
diff options
context:
space:
mode:
Diffstat (limited to 'lapi.c')
-rw-r--r--lapi.c27
1 files changed, 26 insertions, 1 deletions
diff --git a/lapi.c b/lapi.c
index d7b8c376..49ee0864 100644
--- a/lapi.c
+++ b/lapi.c
@@ -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
467LUA_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
467LUA_API int lua_getmetatable (lua_State *L, int objindex) { 481LUA_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
572LUA_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
558LUA_API int lua_setmetatable (lua_State *L, int objindex) { 583LUA_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;