Skip to content
Shuanglei Tao edited this page Feb 9, 2024 · 5 revisions

This example demonstrates the usage of script messages that supported by dyn_menu.lua.

test.lua:

local utils = require('mp.utils')
local msg = require('mp.msg')

local menu = {
	type='submenu',
	submenu={
		{title='foo', cmd='show-text foo'},
		{title='bar', cmd='show-text bar'},
	},
}

mp.register_script_message('menu-get-reply', function(data)
	msg.info('reply: ' .. data)
end)

mp.register_script_message('menu-ready', function()
	mp.commandv('script-message-to', 'dyn_menu', 'get', 'audio-devices', mp.get_script_name())
	mp.commandv('script-message-to', 'dyn_menu', 'update', 'recent', utils.format_json(menu))
	mp.commandv('script-message-to', 'dyn_menu', 'update', 'chapters', utils.format_json(menu))
end)

input.conf:

_           ignore                            #menu: Audio Devices #@audio-devices
_           script-binding recentmenu/open    #menu: Recent #@recent
_           ignore                            #menu: Chapters #@chapters

See also: https://github.com/tsl0922/mpv-menu-plugin/tree/main/src/lua

Clone this wiki locally