aboutsummaryrefslogtreecommitdiff
path: root/lbaselib.c
diff options
context:
space:
mode:
Diffstat (limited to 'lbaselib.c')
-rw-r--r--lbaselib.c26
1 files changed, 25 insertions, 1 deletions
diff --git a/lbaselib.c b/lbaselib.c
index d0dd1e9f..4a979814 100644
--- a/lbaselib.c
+++ b/lbaselib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lbaselib.c,v 1.31 2001/03/26 14:31:49 roberto Exp roberto $ 2** $Id: lbaselib.c,v 1.32 2001/04/06 18:25:00 roberto Exp roberto $
3** Basic library 3** Basic library
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -169,6 +169,29 @@ static int luaB_settag (lua_State *L) {
169 return 1; /* return table */ 169 return 1; /* return table */
170} 170}
171 171
172static int luaB_weakmode (lua_State *L) {
173 const char *mode = luaL_opt_string(L, 2, NULL);
174 luaL_checktype(L, 1, LUA_TTABLE);
175 if (mode == NULL) {
176 char buff[3];
177 char *s = buff;
178 int imode = lua_getweakmode(L, 1);
179 if (imode & LUA_WEAK_KEY) *s++ = 'k';
180 if (imode & LUA_WEAK_VALUE) *s++ = 'v';
181 *s = '\0';
182 lua_pushstring(L, buff);
183 return 1;
184 }
185 else {
186 int imode = 0;
187 lua_pushvalue(L, 1); /* push table */
188 if (strchr(mode, l_c('k'))) imode |= LUA_WEAK_KEY;
189 if (strchr(mode, l_c('v'))) imode |= LUA_WEAK_VALUE;
190 lua_setweakmode(L, imode);
191 return 1;
192 }
193}
194
172static int luaB_newtype (lua_State *L) { 195static int luaB_newtype (lua_State *L) {
173 const l_char *name = luaL_opt_string(L, 1, NULL); 196 const l_char *name = luaL_opt_string(L, 1, NULL);
174 lua_pushnumber(L, lua_newtype(L, name, LUA_TTABLE)); 197 lua_pushnumber(L, lua_newtype(L, name, LUA_TTABLE));
@@ -753,6 +776,7 @@ static const luaL_reg base_funcs[] = {
753 {l_s("tremove"), luaB_tremove}, 776 {l_s("tremove"), luaB_tremove},
754 {l_s("unwrap"), luaB_unwrap}, 777 {l_s("unwrap"), luaB_unwrap},
755 {l_s("xtype"), luaB_xtype}, 778 {l_s("xtype"), luaB_xtype},
779 {l_s("weakmode"), luaB_weakmode}
756}; 780};
757 781
758 782