\pdfminorversion=4
\pdfobjcompresslevel=0
\pdfcompresslevel=0

\documentclass{article}
\nofiles
\pagestyle{empty} % no fonts, please.
\usepackage{luacode}

\begin{luacode*}
  function xmp_1()
    local xmpobj = pdf.obj{
       type='stream',
       immediate=true,
       attr='/Type/Metadata/Subtype/XML',
       compresslevel=0,
       string='*** XMP matadata supposed to be inserted here ***'
    }
    pdf.refobj(xmpobj)
    local meta=string.format('/Metadata %d 0 R', xmpobj)
    tex.print('\\pdfcatalog{'..meta..'}')
  end

  function xmp_2()
    local xmpobj = pdf.obj{
       type='stream',
       immediate=true,
       attr='/Type/Metadata/Subtype/XML',
       compresslevel=0,
       string='*** XMP matadata supposed to be inserted here ***'
    }
    pdf.refobj(xmpobj)
    local meta=string.format('/Metadata %d 0 R', xmpobj)
    pdf.catalog(meta)
  end
\end{luacode*}

\directlua{xmp_1 ()} % <======== adapt =========

\begin{document}
\leavevmode\rule{240bp}{180bp} % Hannover at night.
\end{document}
