• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
1

Recursing keyword's children in Lua creates stack overflow

Community Beginner ,
Aug 08, 2024 Aug 08, 2024

Copy link to clipboard

Copied

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

 

TOPICS
macOS , SDK

Views

90

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Aug 08, 2024 Aug 08, 2024

The sixth line should be:

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

Votes

Translate

Translate
LEGEND ,
Aug 08, 2024 Aug 08, 2024

Copy link to clipboard

Copied

The sixth line should be:

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 08, 2024 Aug 08, 2024

Copy link to clipboard

Copied

LATEST

🤦 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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines