| 178 | |
| 179 | #ifdef LUA_READONLY_TABLES |
| 180 | static int treadonly (lua_State *L) { |
| 181 | static const int luabits = (LUA_READONLY_OLD_LUA_BIT | |
| 182 | LUA_READONLY_NEW_LUA_BIT); |
| 183 | int readonly; |
| 184 | |
| 185 | luaL_checktype(L, 1, LUA_TTABLE); |
| 186 | |
| 187 | readonly = lua_getreadonly(L, 1); |
| 188 | |
| 189 | if (lua_isnone(L, 2)) { /* read the state */ |
| 190 | if (!readonly) { |
| 191 | lua_pushboolean(L, 0); |
| 192 | return 1; |
| 193 | } else { |
| 194 | char modes[3], *c = modes; |
| 195 | if (readonly & LUA_READONLY_OLD_BITS) { *c = 'o'; c++; } |
| 196 | if (readonly & LUA_READONLY_NEW_BITS) { *c = 'n'; c++; } |
| 197 | *c = '\0'; /* terminate */ |
| 198 | lua_pushstring(L, modes); |
| 199 | return 1; |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | if (lua_type(L, 2) == LUA_TSTRING) { |
| 204 | const char *s = lua_tostring(L, 2); |
| 205 | readonly &= ~luabits; |
| 206 | if (strchr(s, 'o')) { readonly |= LUA_READONLY_OLD_LUA_BIT; } |
| 207 | if (strchr(s, 'n')) { readonly |= LUA_READONLY_NEW_LUA_BIT; } |
| 208 | } |
| 209 | else { |
| 210 | if (lua_toboolean(L, 2)) { |
| 211 | readonly |= luabits; |
| 212 | } else { |
| 213 | readonly &= ~luabits; |
| 214 | } |
| 215 | } |
| 216 | |
| 217 | lua_setreadonly(L, 1, readonly); /* return the table */ |
| 218 | lua_settop(L, 1); |
| 219 | return 1; |
| 220 | } |
| 221 | #endif |
| 222 | |
| 223 |
nothing calls this directly
no test coverage detected