TOOLS/lua/command-test.lua: use _name key for mp.command_native

This commit is contained in:
nanahi authored and Kacper Michajłow committed 2026-04-06 18:33:20 +02:00
1 parent dbd31fd9d3
commit b0f9279824
1 file changed
+9 -9
+9 -9
View File
@@ -52,7 +52,7 @@ mp.observe_property("vo-configured", "bool", function(_, v)
end)
mp.command_native_async({
name = "subprocess",
_name = "subprocess",
args = {"sh", "-c", "echo hi && sleep 10s"},
capture_stdout = true
},
@@ -60,7 +60,7 @@ mp.observe_property("vo-configured", "bool", function(_, v)
print("done subprocess: " .. join(" ", {res, val, err}))
end)
local x = mp.command_native_async({name = "subprocess", args = {"sleep", "inf"}},
local x = mp.command_native_async({_name = "subprocess", args = {"sleep", "inf"}},
function(res, val, err)
print("done sleep inf subprocess: " .. join(" ", {res, val, err}))
end)
@@ -70,7 +70,7 @@ mp.observe_property("vo-configured", "bool", function(_, v)
end)
-- (assuming this "freezes")
local y = mp.command_native_async({name = "sub-add", url = "-"},
local y = mp.command_native_async({_name = "sub-add", url = "-"},
function(res, val, err)
print("done sub-add stdin: " .. join(" ", {res, val, err}))
end)
@@ -80,19 +80,19 @@ mp.observe_property("vo-configured", "bool", function(_, v)
end)
mp.command_native_async({name = "subprocess", args = {"wc", "-c"},
mp.command_native_async({_name = "subprocess", args = {"wc", "-c"},
stdin_data = "hello", capture_stdout = true},
function(_, val)
print("Should be '5': " .. val.stdout)
end)
-- blocking stdin by default
mp.command_native_async({name = "subprocess", args = {"cat"},
mp.command_native_async({_name = "subprocess", args = {"cat"},
capture_stdout = true},
function(_, val)
print("Should be 0: " .. #val.stdout)
end)
-- stdin + detached
mp.command_native_async({name = "subprocess",
mp.command_native_async({_name = "subprocess",
args = {"bash", "-c", "(sleep 5s ; cat)"},
stdin_data = "this should appear after 5s.\n",
detach = true},
@@ -101,11 +101,11 @@ mp.observe_property("vo-configured", "bool", function(_, v)
end)
-- This should get killed on script exit.
mp.command_native_async({name = "subprocess", playback_only = false,
mp.command_native_async({_name = "subprocess", playback_only = false,
args = {"sleep", "inf"}}, function()end)
-- Runs detached; should be killed on player exit (forces timeout)
mp.command_native({_flags={"async"}, name = "subprocess",
mp.command_native({_flags={"async"}, _name = "subprocess",
playback_only = false, args = {"sleep", "inf"}})
end)
@@ -114,7 +114,7 @@ local function freeze_test(playback_only)
-- This "freezes" the script, should be killed via timeout.
counter = counter and counter + 1 or 0
print("freeze! " .. counter)
local x = mp.command_native({name = "subprocess",
local x = mp.command_native({_name = "subprocess",
playback_only = playback_only,
args = {"sleep", "inf"}})
print("done, killed=" .. utils.to_string(x.killed_by_us))