Process enumerated arguments for a configuration function */
| 288 | |
| 289 | /* Process enumerated arguments for a configuration function */ |
| 290 | static int json_enum_option(lua_State *l, int optindex, int *setting, |
| 291 | const char **options, int bool_true) |
| 292 | { |
| 293 | static const char *bool_options[] = { "off", "on", NULL }; |
| 294 | |
| 295 | if (!options) { |
| 296 | options = bool_options; |
| 297 | bool_true = 1; |
| 298 | } |
| 299 | |
| 300 | if (!lua_isnil(l, optindex)) { |
| 301 | if (bool_true && lua_isboolean(l, optindex)) |
| 302 | *setting = lua_toboolean(l, optindex) * bool_true; |
| 303 | else |
| 304 | *setting = luaL_checkoption(l, optindex, NULL, options); |
| 305 | } |
| 306 | |
| 307 | if (bool_true && (*setting == 0 || *setting == bool_true)) |
| 308 | lua_pushboolean(l, *setting); |
| 309 | else |
| 310 | lua_pushstring(l, options[*setting]); |
| 311 | |
| 312 | return 1; |
| 313 | } |
| 314 | |
| 315 | /* Configures handling of extremely sparse arrays: |
| 316 | * convert: Convert extremely sparse arrays into objects? Otherwise error. |
no test coverage detected