diff --git a/CMakeLists.txt b/CMakeLists.txt index df45fb9d8..282fea4df 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -277,7 +277,7 @@ endif() # Library pack find_package(GMP REQUIRED) -find_package(Json REQUIRED) +find_package(Json 1.0.0 REQUIRED) find_package(Lua REQUIRED) if(NOT USE_LUAJIT) add_subdirectory(lib/bitop) diff --git a/lib/tiniergltf/tiniergltf.hpp b/lib/tiniergltf/tiniergltf.hpp index 35440f5dd..06e2f5356 100644 --- a/lib/tiniergltf/tiniergltf.hpp +++ b/lib/tiniergltf/tiniergltf.hpp @@ -13,10 +13,17 @@ #include #include #include +#include // unique_ptr #include #include #include +#if JSONCPP_VERSION_HEXA < 0x01090000 /* 1.9.0 */ +namespace Json { + using String = JSONCPP_STRING; // Polyfill +} +#endif + namespace tiniergltf { static inline void check(bool cond) { @@ -1381,7 +1388,7 @@ static Json::Value readJson(Span span) { Json::CharReaderBuilder builder; const std::unique_ptr reader(builder.newCharReader()); Json::Value json; - JSONCPP_STRING err; + Json::String err; if (!reader->parse(span.ptr, span.end(), &json, &err)) throw std::runtime_error(std::string("invalid JSON: ") + err); return json; diff --git a/src/script/common/c_content.cpp b/src/script/common/c_content.cpp index 5355668f0..6367e53f3 100644 --- a/src/script/common/c_content.cpp +++ b/src/script/common/c_content.cpp @@ -2048,9 +2048,6 @@ bool read_tree_def(lua_State *L, int idx, const NodeDefManager *ndef, } /******************************************************************************/ -#if defined(JSONCPP_STRING) || !(JSONCPP_VERSION_MAJOR < 1 || JSONCPP_VERSION_MINOR < 9) -#define HAVE_JSON_STRING -#endif // Returns depth of json value tree static int push_json_value_getdepth(const Json::Value &value) @@ -2079,13 +2076,8 @@ static bool push_json_value_helper(lua_State *L, const Json::Value &value, lua_pushnumber(L, value.asDouble()); break; case Json::stringValue: { -#ifdef HAVE_JSON_STRING const auto &str = value.asString(); lua_pushlstring(L, str.c_str(), str.size()); -#else - const char *str = value.asCString(); - lua_pushstring(L, str ? str : ""); -#endif break; } case Json::booleanValue: @@ -2101,7 +2093,7 @@ static bool push_json_value_helper(lua_State *L, const Json::Value &value, case Json::objectValue: lua_createtable(L, 0, value.size()); for (auto it = value.begin(); it != value.end(); ++it) { -#ifdef HAVE_JSON_STRING +#if JSONCPP_VERSION_HEXA >= 0x01060000 /* 1.6.0 */ const auto &str = it.name(); lua_pushlstring(L, str.c_str(), str.size()); #else