Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8120665
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T05:13:02+00:00 2026-06-06T05:13:02+00:00

In Lua, I have a tree relationship structure between objects where an object can

  • 0

In Lua, I have a tree relationship structure between objects where an object can have multiple children, but only one parent object, i.e.

obj—obj1—obj2—objd3—obj4—obj5—obj6

If I want to know obj6’s ‘distant’ parents instead of just the immediate parent obj5, how can I achieve that? I just need a list of parents two or more levels above the current object, and the API I’m working with only has a obj.parent property.

Pseudo-code would also be helpful to get me in the right direction.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T05:13:04+00:00Added an answer on June 6, 2026 at 5:13 am

    Well, if your api supports .parent, can’t you do something like the following? I’m rusty with Lua but this should offer a start.

    local function GetAncestors(child)
    
        local ancestors = {};
    
        if child.parent then
            local i = 0;
            ancestors[0] = child.parent;
            while ancestors[i].parent do
                ancestors[i + 1] = ancestors[i].parent;
                i = i + 1;
            end
        end
    
        return ancestors;
    
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does Lua have a builtin sum() function? I can't seem to find one, and
I want to have C++ objects that I can read/write in both C++ &
I have lua embedded in my game engine and a directory structure of lua
If I have some lua code like this: doSomething(function() print(Hello!) end) How can I
I have C++ objects and I have Lua objects/tables. (Also have SWIG C++ bindings.)
I have trouble getting Application Data in Lua. I can't even find how to
I have an application in Lua, I want to communicate between the Lua application
I have a lua function which takes multiple parameters and returns as many values
I have created a Lua table in C , but I'm not sure how
I have succesfully installed mysql-proxy and understood the way working and lua scripting. But

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.