lua: add utils.format_json() function

Requested. Why not.
This commit is contained in:
wm4
2015-04-22 20:55:05 +02:00
parent 589533d97a
commit daabbe3640
2 changed files with 26 additions and 0 deletions

View File

@@ -639,6 +639,14 @@ strictly part of the guaranteed API.
trailing text is returned as 3rd return value. (The 3rd return value is
always there, but with ``trail`` set, no error is raised.)
``utils.format_json(v)``
Format the given Lua table (or value) as a JSON string and return it. On
error, returns ``nil, error``. (Errors usually only happen on value types
incompatible with JSON.)
The argument value uses similar conventions as ``mp.set_property_native()``
to distinguish empty objects and arrays.
``utils.to_string(v)``
Turn the given value into a string. Formats tables and their contents. This
doesn't do anything special; it is only needed because Lua is terrible.