MPV lua scripting: Print hello world

By xngo on February 21, 2019

Hello World in lua for mpv

  1. Save the script below(e.g. hello.lua) in ~/.config/mpv/scripts/ folder. If scripts folder doesn't exist, create it.
  2. Play a video with mpv.
  3. While the video is playing, press g key. It will print Hello World on your terminal
require 'os'
require 'io'
require 'string'
 
function print_hello_world()
    print("Hello World")
end
 
-- Set key bindings.
mp.add_key_binding("g", "print_hello_world", print_hello_world)

Here is a video showing the code above in action.

MPV Lua scripting hello world video

What next?

About the author

Xuan Ngo is the founder of OpenWritings.net. He currently lives in Montreal, Canada. He loves to write about programming and open source subjects.