How is an alternative to registerAttributeExtractor

How is an alternative to registerAttributeExtractor of v1 in lua?
ie how to translate this space-script in a space-lua?

silverbullet.registerAttributeExtractor({tags: ["page"]}, (text) => {

    const titleRegex = /^#\s+(.*)$/m;  // "^" indica inizio riga, "(.*)" cattura il titolo, "m" per modalità multilinea
    const titleMatch = titleRegex.exec(text);

    // Inizializza le variabili di ritorno
    let itemName = text;
    let title = null;

    // Se trova un titolo, lo salva nella variabile title
    if (titleMatch) {
        title = titleMatch[1].trim();  // Estrae il titolo senza "# " e lo pulisce da eventuali spazi
    }
 
    // Se non è stato trovato alcun titolo, non restituisce nulla
    if (!title) {
        return null;  // Non restituisce alcun oggetto
    }
  
    // Restituisce l'oggetto con il nome dell'elemento, la data, il titolo e il testo originale
    return {
        name: itemName,  // Nome dell'elemento pulito dalla data e dall'emoji
        title: title    // Il primo titolo Markdown o null se non trovato
    };
});

Searching the SilverBullet V2 documentation I found index.index Objects(page, objects) which I think does the job.
However this code does not give me what I hoped for.

function saveAttr()
  local pagina = editor.getCurrentPage()
  local objects = {
    {tag = "page", ref = "displayName", content = "Write docs"}
  }
  index.indexObjects(pagina, objects)
end

If this function worked I would have thought to call it when saving the page.
But until it works..
Any idea where I am going wrong?