1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Add 'minetest.write_json'

This commit is contained in:
ShadowNinja 2013-12-18 16:46:53 -05:00
parent 49cec3f782
commit 1ed90c90c3
5 changed files with 92 additions and 1 deletions

View file

@ -179,6 +179,32 @@ int ModApiUtil::l_parse_json(lua_State *L)
return 1;
}
// write_json(data[, styled]) -> string
int ModApiUtil::l_write_json(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;
bool styled = false;
if (!lua_isnone(L, 2)) {
styled = lua_toboolean(L, 2);
lua_pop(L, 1);
}
Json::Value root;
get_json_value(L, root, 1);
std::string out;
if (styled) {
Json::StyledWriter writer;
out = writer.write(root);
} else {
Json::FastWriter writer;
out = writer.write(root);
}
lua_pushlstring(L, out.c_str(), out.size());
return 1;
}
// get_dig_params(groups, tool_capabilities[, time_from_last_punch])
int ModApiUtil::l_get_dig_params(lua_State *L)
{
@ -249,6 +275,7 @@ void ModApiUtil::Initialize(lua_State *L, int top)
API_FCT(setting_save);
API_FCT(parse_json);
API_FCT(write_json);
API_FCT(get_dig_params);
API_FCT(get_hit_params);