I tried some more and I think I got close, but still couldn’t get it right. Below the space are various things I tried, with comments on outcome:
for cat in pairs(cats) do modtree.addbranch = cat --add a branch for each module category for _,module in pairs(cats[cat]) do --iter thru each category and populate branches with modules local leaffunc = module.bindsettings modtree.addleaf1 = module.label -- iup.Message("",tostring(leaffunc)) --returns a different function each iteration like it should --[[ function modtree:executeleaf_cb(id) --automatically grabs current leaf's node id -- iup.Message(id,modtree.title) --test that prints mod name (SUCCESS) -- leaffunc(t) --OPENS SAME DLG -- module.bindsettings(t) --BROKEN end ]] -- modtree.executeleaf_cb = function(_) leaffunc(t) end --OPENS SAME DLG -- modtree.executeleaf_cb = function(_) module.bindsettings(t) end --OPENS SAME DLG -- modtree.executeleaf_cb = module.bindsettings(t) --BROKEN (spams mod dlgs on open and crashes) -- modtree.executeleaf_cb = leaffunc(t) --BROKEN (spam and crash) end end Something about nodes seems to keep the callbacks from sticking. Maybe because the object in question seems to be the tree rather than the nodes, I imagine the callback gets assigned to the whole tree instead. Then I tried making an array to store the info, but it’s making the app crash. I don’t think I’m handling calling a function with a parameter from an array correctly. I need to get “t” into module.bindsettings(). local modarray = {} for cat in pairs(cats) do modtree.addbranch = cat --add a branch for each module category table.insert(modarray, cat) --placeholders so leaf indices will match their IDs for _,module in pairs(cats[cat]) do local leaffunc = module.bindsettings -- iup.Message("",tostring(leaffunc)) --returns a different function id each iteration like it should modtree.addleaf1 = module.label table.insert(modarray, leaffunc) --is the name enough? It didn’t work when I tried adding parameters or wrapping the variable in an anonymous function end end modtree.executeleaf_cb = function(id) modarray[id](t) -- crashes here end From: Antonio Scuri I suggest you to store in each node some information that will allow you to retrieve the correct module and be able to show it. Best, Scuri Em seg., 29 de nov. de 2021 às 23:11, Kaz F <kaz.fox...@gmail.com> escreveu:
_______________________________________________ |
_______________________________________________ Iup-users mailing list Iup-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/iup-users