From 1a5460be319ac29af31f201fbf9775340262ba9b Mon Sep 17 00:00:00 2001 From: Mark Pulford Date: Wed, 18 Jan 2012 20:00:09 +1030 Subject: Return boolean values from configuration functions Return boolean values from configuration functions to simplify usage in the common case. Eg,: if not cjson.encode_invalid_numbers() then .. end --- lua_cjson.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'lua_cjson.c') 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, /* Process enumerated arguments for a configuration function */ static int json_enum_option(lua_State *l, int optindex, int *setting, - const char **options, int bool_value) + const char **options, int bool_true) { static const char *bool_options[] = { "off", "on", NULL }; if (!options) { options = bool_options; - bool_value = 1; + bool_true = 1; } if (!lua_isnil(l, optindex)) { - if (lua_isboolean(l, optindex)) - *setting = lua_toboolean(l, optindex) * bool_value; + if (bool_true && lua_isboolean(l, optindex)) + *setting = lua_toboolean(l, optindex) * bool_true; else *setting = luaL_checkoption(l, optindex, NULL, options); } - lua_pushstring(l, options[*setting]); + if (bool_true && (*setting == 0 || *setting == bool_true)) + lua_pushboolean(l, *setting); + else + lua_pushstring(l, options[*setting]); return 1; } -- cgit v1.2.3-55-g6feb