History

TOOLS: add a stupid test program for Lua async commands

wm4 committed 8 years ago

Commit be5e4621 parent 15937991 file · +53 −0Browse files

Unified · Split

TOOLS/lua/command-test.lua+53−0
@@ -0,0 +1,53 @@
1+-- Test script for some command API details.
2+
3+local utils = require("mp.utils")
4+
5+function join(sep, arr, count)
6+ local r = ""
7+ if count == nil then
8+ count = #arr
9+ end
10+ for i = 1, count do
11+ if i > 1 then
12+ r = r .. sep
13+ end
14+ r = r .. utils.to_string(arr[i])
15+ end
16+ return r
17+end
18+
19+mp.observe_property("vo-configured", "bool", function(_, v)
20+ if v ~= true then
21+ return
22+ end
23+
24+ print("async expand-text")
25+ mp.command_native_async({"expand-text", "hello ${path}!"},
26+ function(res, val, err)
27+ print("done async expand-text: " .. join(" ", {res, val, err}))
28+ end)
29+
30+ -- make screenshot writing very slow
31+ mp.set_property("screenshot-format", "png")
32+ mp.set_property("screenshot-png-compression", "9")
33+
34+ timer = mp.add_periodic_timer(0.1, function() print("I'm alive") end)
35+ timer:resume()
36+
37+ print("Slow screenshot command...")
38+ res, err = mp.command_native({"screenshot"})
39+ print("done, res: " .. utils.to_string(res))
40+
41+ print("Slow screenshot async command...")
42+ res, err = mp.command_native_async({"screenshot"}, function(res)
43+ print("done (async), res: " .. utils.to_string(res))
44+ timer:kill()
45+ end)
46+ print("done (sending), res: " .. utils.to_string(res))
47+
48+ print("Broken screenshot async command...")
49+ mp.command_native_async({"screenshot-to-file", "/nonexistent/bogus.png"},
50+ function(res, val, err)
51+ print("done err scr.: " .. join(" ", {res, val, err}))
52+ end)
53+end)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t