User Tools

Site Tools


useful_programs

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
useful_programs [2020/03/20 10:06] – [3-point control for a valve or servo] emozolyakuseful_programs [2020/06/03 12:00] – [Other handy functions] emozolyak
Line 228: Line 228:
   end    end 
  
 +</code>
 +
 +For complex tables print, you can use the following function:
 +<code lua>
 +function tprint(t, indent)
 +    if not indent then indent = 0 end 
 +    for k, v in pairs(t) do 
 +        local formatting = string.rep(' ', indent) .. k .. ': '
 +        if type(v) == "table" then 
 +            ERROR(formatting) 
 +            tprint(v, indent + 1) -- recursive call 
 +        else
 +            if type(v) == "boolean" then 
 +                v = v and "TRUE" or "FALSE"
 +            end 
 +            ERROR(formatting .. v) 
 +        end 
 +    end -- for 
 +end -- tprint 
 </code> </code>
  
Line 750: Line 769:
             return false -- nothing happened              return false -- nothing happened 
 end -- P_TRIG  end -- P_TRIG 
 +
 +function MulGetReg(...) -- multiple ids or aliases read, returns table, have to be unpack() 'ed
 +     local results = {} 
 +     for i = 1, #arg do 
 +         local param = arg[i]
 +        --  INFO("processing " .. param .. " paramter")
 +          results[i] = GetReg(param)
 +     end 
 +     if (#results == 1) then 
 +         return results[1]
 +     else 
 +         return results
 +     end 
 +end 
 </code> </code>
  
useful_programs.txt · Last modified: 2024/03/19 09:39 by emozolyak

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki