useful_programs
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
useful_programs [2020/01/10 09:33] – [Universal Timer (TON / TOFF)] emozolyak | useful_programs [2020/02/21 13:48] – [Debug printing] emozolyak | ||
---|---|---|---|
Line 140: | Line 140: | ||
<code lua> | <code lua> | ||
- | function DBG( ...) -- ... accepts multiple arguments in a table arg | + | function DBG(...) |
- | + | local tc = tabToStr | |
- | local table_sign | + | |
- | local table_sign_found = false | + | function align2s(s1, s2) -- appends space to smaller string |
- | local tab_s_index = 0 | + | |
- | + | ||
- | if ENABLE_DEBUG then -- should be global in the calling script | + | |
- | + | ||
- | -- find divider | + | |
- | for i = 1, #arg do | + | |
- | if arg[i] | + | |
- | table_sign_found = true | + | |
- | tab_s_index = i | + | |
- | break | + | |
- | end | + | |
- | end | + | |
| | ||
- | if not table_sign_found | + | if (d ~= 0) then |
- | | + | |
- | else | + | local Lp, Rp = 0, 0 |
- | local header_t, value_t | + | |
- | + | ||
- | for k = 1, tab_s_index - 1 do | + | |
- | header_t[k] = arg[k] | + | |
- | end | + | |
- | for j = tab_s_index + 1, #arg do | + | |
- | value_t[j - tab_s_index] = tostring(arg[j]) | + | |
- | end | + | |
| | ||
- | if (#header_t ~= #value_t) then | + | if ((ad % 2) == 0) then |
- | ERROR("column count differs!") | + | Lp = ad / 2 ; Rp = Lp ; INFO("even parts, L R = " |
else | else | ||
- | | + | |
- | local delta = # | + | |
- | if delta ~= 0 then | + | |
- | if (delta > 0) then | + | |
- | value_t[g] | + | |
- | else | + | |
- | header_t[g] = header_t[g] | + | |
- | end | + | |
- | end | + | |
- | end -- for | + | |
- | INFO(tabToStr(header_t)) ; INFO(tabToStr(value_t)) | + | |
end | end | ||
+ | return (((d > 0) and {s1, s:rep(Lp) .. s2 .. s: | ||
+ | or | ||
+ | | ||
+ | else | ||
+ | return {s1, s2} | ||
end | end | ||
- | end -- if ENABLE_DEBUG | + | end |
- | + | ||
- | return true | + | |
- | end -- DBG | + | |
+ | if ENABLE_DEBUG then | ||
+ | local arg_str = tc(arg) | ||
+ | local t_s_pos = string.find(arg_str, | ||
+ | |||
+ | if not t_s_pos then | ||
+ | INFO(arg_str) | ||
+ | else | ||
+ | local h_row, v_row = {}, {} | ||
+ | -- header | ||
+ | for w in string.gmatch(arg[1], | ||
+ | h_row[# | ||
+ | end | ||
+ | -- values | ||
+ | for i = 3, #arg do | ||
+ | v_row[# | ||
+ | end | ||
+ | |||
+ | if (#h_row ~= #v_row) then | ||
+ | ERROR(" | ||
+ | INFO(" | ||
+ | return | ||
+ | else | ||
+ | for g = 1, #h_row do | ||
+ | h_row[g], v_row[g] = unpack(align2s(h_row[g], | ||
+ | end | ||
+ | end | ||
+ | INFO(tc(h_row)) ; INFO(tc(v_row)) | ||
+ | end | ||
+ | end | ||
+ | end | ||
+ | |||
function tabToStr(t) | function tabToStr(t) | ||
local s = "" | local s = "" | ||
for i = 1, #t do | for i = 1, #t do | ||
- | s = s .. tostring(t[i]) .. ' ' | + | |
+ | | ||
end -- for | end -- for | ||
return s | return s | ||
- | end | + | end |
</ | </ |
useful_programs.txt · Last modified: 2024/03/19 09:39 by emozolyak