From bc94292b70be41cecd2bd151b1fffcfa59480118 Mon Sep 17 00:00:00 2001 From: Mark Pulford Date: Sun, 1 May 2011 16:26:44 +0930 Subject: Improve encoding exception error format Was: Cannot serialise : Now: Cannot serialise : --- lua_cjson.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/lua_cjson.c b/lua_cjson.c index 24b9704..e5e7d1c 100644 --- a/lua_cjson.c +++ b/lua_cjson.c @@ -209,13 +209,13 @@ static void json_create_config(lua_State *l) /* ===== ENCODING ===== */ -static void json_encode_type_exception(lua_State *l, strbuf_t *json, - char *location, int lindex) +static void json_encode_exception(lua_State *l, strbuf_t *json, int lindex, + const char *reason) { strbuf_free(json); - luaL_error(l, "Cannot serialise %s: %s", location, - lua_typename(l, lua_type(l, lindex))); + luaL_error(l, "Cannot serialise %s: %s", + lua_typename(l, lua_type(l, lindex)), reason); } /* JSON escape a character if required, or return NULL */ @@ -388,7 +388,8 @@ static void json_append_object(lua_State *l, json_config_t *cfg, json_append_string(l, json, -2); strbuf_append_string(json, ": "); } else { - json_encode_type_exception(l, json, "table key", -2); + json_encode_exception(l, json, -2, + "table key must be a number or string"); /* never returns */ } @@ -439,7 +440,7 @@ static void json_append_data(lua_State *l, json_config_t *cfg, strbuf_t *json) default: /* Remaining types (LUA_TFUNCTION, LUA_TUSERDATA, LUA_TTHREAD, * and LUA_TLIGHTUSERDATA) cannot be serialised */ - json_encode_type_exception(l, json, "value", -1); + json_encode_exception(l, json, -1, "type not supported"); /* never returns */ } } -- cgit v1.2.3-55-g6feb