Skip to main content
Participating Frequently
August 8, 2024
Answered

Recursing keyword's children in Lua creates stack overflow

  • August 8, 2024
  • 1 reply
  • 209 views

Having progressed my keywording script, I've one task left which is to extend a function that creates a map of keyword name -> id so that it handles child keywords. I naively tried:

 

local function find_all_keywords()
    local all_keywords = {}

    local function find (keyword)
       all_keywords[keyword:getName()]=keyword.localIdentifier
       for _, child in ipairs (keyword:getChildren()) do find (keyword) end
    end

    for _, keyword in ipairs (catalog:getKeywords ()) do find (keyword) end
    return all_keywords
end

 

However, when executing this, it creates a stack overflow which I don't understand. My keywords are only about 5 deep, and I think my logic would only attempt to find children of parents which should terminate at each leaf node? 

 

?:0: stack overflow

 

This topic has been closed for replies.
Correct answer johnrellis

The sixth line should be:

       for _, child in ipairs (keyword:getChildren()) do find (child) end

1 reply

johnrellis
johnrellisCorrect answer
Legend
August 9, 2024

The sixth line should be:

       for _, child in ipairs (keyword:getChildren()) do find (child) end
Participating Frequently
August 9, 2024

🤦 Doh. I was certain I'd hit some slightly wierd Lua perculiarty. But no, after 25 years of profession software engineering, it was a stupid typo. Thanks.

 

My script is now ready to process my 15k of images that I've exported out of C1. 

 

Thank you again.