MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / json_enum_option

Function json_enum_option

deps/lua/src/lua_cjson.c:239–262  ·  view source on GitHub ↗

Process enumerated arguments for a configuration function */

Source from the content-addressed store, hash-verified

237
238/* Process enumerated arguments for a configuration function */
239static int json_enum_option(lua_State *l, int optindex, int *setting,
240 const char **options, int bool_true)
241{
242 static const char *bool_options[] = { "off", "on", NULL };
243
244 if (!options) {
245 options = bool_options;
246 bool_true = 1;
247 }
248
249 if (!lua_isnil(l, optindex)) {
250 if (bool_true && lua_isboolean(l, optindex))
251 *setting = lua_toboolean(l, optindex) * bool_true;
252 else
253 *setting = luaL_checkoption(l, optindex, NULL, options);
254 }
255
256 if (bool_true && (*setting == 0 || *setting == bool_true))
257 lua_pushboolean(l, *setting);
258 else
259 lua_pushstring(l, options[*setting]);
260
261 return 1;
262}
263
264/* Configures handling of extremely sparse arrays:
265 * convert: Convert extremely sparse arrays into objects? Otherwise error.

Calls 4

lua_tobooleanFunction · 0.85
luaL_checkoptionFunction · 0.85
lua_pushbooleanFunction · 0.85
lua_pushstringFunction · 0.85

Tested by

no test coverage detected