From 5548c75e5507da6a0f9fb6a45a07a5cc6edd9393 Mon Sep 17 00:00:00 2001 From: wm4 Date: Sun, 19 Oct 2014 05:27:35 +0200 Subject: lua: expose JSON parser The JSON parser was introduced for the IPC protocol, but I guess it's useful here too. The motivation for this commit is the same as with 8e4fa5fc (again). --- DOCS/man/lua.rst | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'DOCS/man') diff --git a/DOCS/man/lua.rst b/DOCS/man/lua.rst index c49d2c388c..2eddbb8f2f 100644 --- a/DOCS/man/lua.rst +++ b/DOCS/man/lua.rst @@ -593,6 +593,20 @@ strictly part of the guaranteed API. In all cases, ``mp.resume_all()`` is implicitly called. +``utils.parse_json(str [, trail])`` + Parses the given string argument as JSON, and returns it as a Lua table. On + error, returns ``nil, error``. (Currently, ``error`` is just a string + reading ``error``, because there is no fine-grained error reporting of any + kind.) + + The returned value uses similar conventions as ``mp.get_property_native()`` + to distinguish empty objects and arrays. + + If the ``trail`` parameter is ``true`` (or any value equal to ``true``), + then trailing non-whitespace text is tolerated by the function, and the + trailing text is returned as 3rd return value. (The 3rd return value is + always there, but with ``trail`` set, no error is raised.) + Events ------ -- cgit v1.2.3