summaryrefslogtreecommitdiffstats
path: root/TOOLS/lua
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2018-05-10 15:26:56 +0200
committerwm4 <wm4@nowhere>2018-05-24 19:56:34 +0200
commitbe5e46222ba4adccc5a557375beea29d23969a81 (patch)
tree44b8a8e30f0df1d2ef2fd276eeb75d7425c23a07 /TOOLS/lua
parent159379980ec8c79608b1adada4b66b1d8c016e4a (diff)
downloadmpv-be5e46222ba4adccc5a557375beea29d23969a81.tar.bz2
mpv-be5e46222ba4adccc5a557375beea29d23969a81.tar.xz
TOOLS: add a stupid test program for Lua async commands
Diffstat (limited to 'TOOLS/lua')
-rw-r--r--TOOLS/lua/command-test.lua53
1 files changed, 53 insertions, 0 deletions
diff --git a/TOOLS/lua/command-test.lua b/TOOLS/lua/command-test.lua
new file mode 100644
index 0000000000..5fb8c7b0d7
--- /dev/null
+++ b/TOOLS/lua/command-test.lua
@@ -0,0 +1,53 @@
+-- Test script for some command API details.
+
+local utils = require("mp.utils")
+
+function join(sep, arr, count)
+ local r = ""
+ if count == nil then
+ count = #arr
+ end
+ for i = 1, count do
+ if i > 1 then
+ r = r .. sep
+ end
+ r = r .. utils.to_string(arr[i])
+ end
+ return r
+end
+
+mp.observe_property("vo-configured", "bool", function(_, v)
+ if v ~= true then
+ return
+ end
+
+ print("async expand-text")
+ mp.command_native_async({"expand-text", "hello ${path}!"},
+ function(res, val, err)
+ print("done async expand-text: " .. join(" ", {res, val, err}))
+ end)
+
+ -- make screenshot writing very slow
+ mp.set_property("screenshot-format", "png")
+ mp.set_property("screenshot-png-compression", "9")
+
+ timer = mp.add_periodic_timer(0.1, function() print("I'm alive") end)
+ timer:resume()
+
+ print("Slow screenshot command...")
+ res, err = mp.command_native({"screenshot"})
+ print("done, res: " .. utils.to_string(res))
+
+ print("Slow screenshot async command...")
+ res, err = mp.command_native_async({"screenshot"}, function(res)
+ print("done (async), res: " .. utils.to_string(res))
+ timer:kill()
+ end)
+ print("done (sending), res: " .. utils.to_string(res))
+
+ print("Broken screenshot async command...")
+ mp.command_native_async({"screenshot-to-file", "/nonexistent/bogus.png"},
+ function(res, val, err)
+ print("done err scr.: " .. join(" ", {res, val, err}))
+ end)
+end)