From e1f9ba435f8c0cca90f2d3df36e9aa82763e1da0 Mon Sep 17 00:00:00 2001 From: ShadowNinja Date: Wed, 18 Dec 2013 18:17:26 -0500 Subject: Don't throw a error when writing JSON fails --- src/script/lua_api/l_util.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'src/script/lua_api/l_util.cpp') diff --git a/src/script/lua_api/l_util.cpp b/src/script/lua_api/l_util.cpp index 9fa6fcb77..f9ec94db4 100644 --- a/src/script/lua_api/l_util.cpp +++ b/src/script/lua_api/l_util.cpp @@ -179,7 +179,7 @@ int ModApiUtil::l_parse_json(lua_State *L) return 1; } -// write_json(data[, styled]) -> string +// write_json(data[, styled]) -> string or nil and error message int ModApiUtil::l_write_json(lua_State *L) { NO_MAP_LOCK_REQUIRED; @@ -191,7 +191,13 @@ int ModApiUtil::l_write_json(lua_State *L) } Json::Value root; - get_json_value(L, root, 1); + try { + get_json_value(L, root, 1); + } catch (SerializationError &e) { + lua_pushnil(L); + lua_pushstring(L, e.what()); + return 2; + } std::string out; if (styled) { -- cgit v1.2.3