Lua is the worst language to write glue code between mpv and mpd protocol.
Why?
Playlist position numbers.
In mpd, they're 0-based.
In mpv, they're 0-based.
But when you're iterating the playlist in lua, you're iterating a lua table. Its indexes are 1-based.
And the worst things you don't have types that'd tell you if a particular number is 0-based or 1-based, and force you to use the correct conversion functions.