recursion - Lua: Taking a Recursive Action into a Single One -


i'm using lua create "plug-in" linux-based operating system. program contains c function recursive 1 (not intended is). @ moment, each time function called provides result 4-5 times.

i'd ask question concerning recursive function(s) , results. possible take multiple (same) results of recursive function , use 1 of set(s) of results?

example: (i'm going state "os function" point out coded operating system i'm integrating lua into)

function abc123() -- os function based in os     local names = os_names() -- os function     local index, var = os_rows() -- os function pull vars file     k,v in pairs(names)         index2, var2 = os_rows(k) -- os function pull vars file         if var2 ~= var             os_rows(k,var2,var) -- recursive os function             cnt = 1             while cnt <= 4                  data_tbl = file_info(x,y,z) -- personal function grab info , return table                  info_tbl[data_tbl.id]=data_tbl                  loop_erase(info_tbl) -- thoughts if possible                  cnt = cnt + 1             end         end     end end  function loop_erase(entry) -- can work????     local order = {[1]="",[2]="",[3]="",[4]=""}     k,v in ipairs(entry)         key,value in ipairs(order)             if key == k                 value = v             end         end     end end 

there 4 slave devices, , names maintained in os_names function. when particular file selected on of 4 slaves, os_rows function called , sets index, var location , name of file. @ point, for loop checks other devices set on them. if not match index, var selects var file on slave device.

right now, working should point if var2 ~= var. if variables don't match in 4 names, performs os_rows(k,var2,var) os function cause of problem. @ point, proper function performed 4 times. occurring on each of 4 files - 4 times exponential problem! recursive action i'm trying stop. ultimately, of information being transmitted outside slave devices (via ethernet) i'm afraid cause communication issues.

now know approach drawn out , can shortened expert programmer. right now, function abc123() returning 4 results (which good) 4 times in row (which bad). thoughts try put them table , if keys of table matched, overwrite them.

a) i'm unsure if possible since attempts far haven't worked

b) if possible, thought function loop_erase way go.

i'm thinking isn't possible since each time recursive function occurs, still calling upon other functions links to. i've been trying different methods , no go.


Popular posts from this blog