MCPcopy Create free account
hub / github.com/9chu/LuaSTGPlus / json_enum_option

Function json_enum_option

LuaSTGPlus/LuaExtensions/cjson4lua/lua_cjson.c:242–265  ·  view source on GitHub ↗

Process enumerated arguments for a configuration function */

Source from the content-addressed store, hash-verified

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

Calls

no outgoing calls

Tested by

no test coverage detected