-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add support for mpv internal mp.input
function
#112
base: master
Are you sure you want to change the base?
Conversation
addons/find.lua
Outdated
input.get_user_input( fb.coroutine.callback(), { text = text, id = "find", replace = true } ) | ||
) | ||
elseif input then | ||
query, error = coroutine.yield( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Call input.terminate()
before this to ensure there is not another input already active. If another input is active, then console.lua
will abort the input.get
request without any feedback. That means our coroutine would never be resumed, causing a memory leak.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternatively, you could use the new coroutine.callback()
behaviour I'm adding in #113:
input.get({
prompt = text .. "\n>",
id = "find",
opened = fb.coroutine.callback(1.5),
submit = fb.coroutine.callback(),
})
local console_opened = coroutine.yield()
if not console_opened then return msg.warn('failed to open mp.input') end
local query = coroutine.yield()
input.terminate()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Upon inspecting the mp.input code it appears that mp.input discards all the old callbacks when a new input.get
request is created. This should discard the callback, which should discard the reference to the coroutine, and hence mean no memory leak. But you may still want to add a timeout to opened to provide a useful error message.
modules/utils.lua
Outdated
local success, input = pcall(require, 'mp.input') | ||
if not success then | ||
user_input_loaded, input = pcall(require, "user-input-module") | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This breaks the keybind expressions that use the input
field because they won't know which module is being used. The run-statement example would break for instance. I'm happy for you to replace input
in the expressions with the new mpv.input
for future compatibility, but mpv-user-input still needs to be provided, perhaps through a user_input
variable instead (here). The documentation will also need to be updated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't notice this usage before, undo change.
ref #111