aboutsummaryrefslogtreecommitdiff
path: root/lua_cjson.c
diff options
context:
space:
mode:
Diffstat (limited to 'lua_cjson.c')
-rw-r--r--lua_cjson.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/lua_cjson.c b/lua_cjson.c
index b64ed62..0662414 100644
--- a/lua_cjson.c
+++ b/lua_cjson.c
@@ -235,23 +235,26 @@ static int json_integer_option(lua_State *l, int optindex, int *setting,
235 235
236/* Process enumerated arguments for a configuration function */ 236/* Process enumerated arguments for a configuration function */
237static int json_enum_option(lua_State *l, int optindex, int *setting, 237static int json_enum_option(lua_State *l, int optindex, int *setting,
238 const char **options, int bool_value) 238 const char **options, int bool_true)
239{ 239{
240 static const char *bool_options[] = { "off", "on", NULL }; 240 static const char *bool_options[] = { "off", "on", NULL };
241 241
242 if (!options) { 242 if (!options) {
243 options = bool_options; 243 options = bool_options;
244 bool_value = 1; 244 bool_true = 1;
245 } 245 }
246 246
247 if (!lua_isnil(l, optindex)) { 247 if (!lua_isnil(l, optindex)) {
248 if (lua_isboolean(l, optindex)) 248 if (bool_true && lua_isboolean(l, optindex))
249 *setting = lua_toboolean(l, optindex) * bool_value; 249 *setting = lua_toboolean(l, optindex) * bool_true;
250 else 250 else
251 *setting = luaL_checkoption(l, optindex, NULL, options); 251 *setting = luaL_checkoption(l, optindex, NULL, options);
252 } 252 }
253 253
254 lua_pushstring(l, options[*setting]); 254 if (bool_true && (*setting == 0 || *setting == bool_true))
255 lua_pushboolean(l, *setting);
256 else
257 lua_pushstring(l, options[*setting]);
255 258
256 return 1; 259 return 1;
257} 260}