summaryrefslogtreecommitdiff
path: root/src/script/lua_api
diff options
context:
space:
mode:
Diffstat (limited to 'src/script/lua_api')
-rw-r--r--src/script/lua_api/l_util.cpp10
1 files changed, 8 insertions, 2 deletions
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) {