diff options
author | wm4 <wm4@nowhere> | 2015-04-22 20:55:05 +0200 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2015-04-22 20:55:05 +0200 |
commit | daabbe364007fc7546df63981422b53b9a20c6fc (patch) | |
tree | 44a2ab9c1d7fc02efeac374862a4f0e8829cff91 /player | |
parent | 589533d97ad0bf861a555b7402410297541bf96c (diff) | |
download | mpv-daabbe364007fc7546df63981422b53b9a20c6fc.tar.bz2 mpv-daabbe364007fc7546df63981422b53b9a20c6fc.tar.xz |
lua: add utils.format_json() function
Requested. Why not.
Diffstat (limited to 'player')
-rw-r--r-- | player/lua.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/player/lua.c b/player/lua.c index 51c0e1a752..4ef772fd84 100644 --- a/player/lua.c +++ b/player/lua.c @@ -1255,6 +1255,23 @@ static int script_parse_json(lua_State *L) return 3; } +static int script_format_json(lua_State *L) +{ + void *tmp = mp_lua_PITA(L); + struct mpv_node node; + makenode(tmp, &node, L, 1); + char *dst = talloc_strdup(tmp, ""); + if (json_write(&dst, &node) >= 0) { + lua_pushstring(L, dst); + lua_pushnil(L); + } else { + lua_pushnil(L); + lua_pushstring(L, "error"); + } + talloc_free_children(tmp); + return 2; +} + #define FN_ENTRY(name) {#name, script_ ## name} struct fn_entry { const char *name; @@ -1303,6 +1320,7 @@ static const struct fn_entry utils_fns[] = { FN_ENTRY(join_path), FN_ENTRY(subprocess), FN_ENTRY(parse_json), + FN_ENTRY(format_json), {0} }; |