I have a tree and I've successfully used nested ipairs loops to grab a bunch of categories and their modules, then alphabetize them using arrays-- first by category names, then by mod names.
If I iterate over the final ay_modtree array, which holds the branches and leaves in the same order I want them to appear in the tree (so I can match node id to array index for leaf execution callbacks), the results are exactly what I want, but when I add "addbranch" and "addleaf1" into the loops, the resulting tree appears in reverse alphabetical order. What is causing the reverse results and how can I fix it? Here is the code: --------------------------------------------------------------------------------------------------- local modtree = iup.flattree{rastersize = "400x500"} modtree["addbranch-1"] = "MODULES" --add root node local ay_cats = {} --array to alphabetize categories for cat in pairs(cats) do --iterate thru all mod categories table.insert(ay_cats, cat) --assign each unique category to the array end table.sort(ay_cats, function(a, b) return a:lower() < b:lower() end) --alphabetize categories local ay_modtree = {} --array to collect categories and mods to populate tree in order for i,v in ipairs(ay_cats) do --iterate thru alphabetized category array table.insert(ay_modtree, v) --assign category to mod tree array modtree.addbranch = v --add category as branch to mod tree local sorter = {} --temporary array for sorting for k,module in pairs(cats[v]) do --iterate thru each category table.insert(sorter,module.label) --add module to temp table end table.sort(sorter, function(a, b) return a:lower() < b:lower() end) --alphabetize mods for _,val in ipairs(sorter) do --iterate thru alphabetized mods table.insert(ay_modtree, val) --put alphabetized mod into mod tree table modtree.addleaf1 = val --add mod name as leaf to mod tree end end _______________________________________________ Iup-users mailing list Iup-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/iup-users