MCPcopy Create free account
hub / github.com/defold/defold / json_enum_option

Function json_enum_option

engine/script/src/luacjson/lua_cjson.c:290–313  ·  view source on GitHub ↗

Process enumerated arguments for a configuration function */

Source from the content-addressed store, hash-verified

288
289/* Process enumerated arguments for a configuration function */
290static 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.

Calls 4

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

Tested by

no test coverage detected