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 [2019/07/31 12:56] – [Bit functions] emozolyak | useful_programs [2019/09/16 15:10] – [Bit functions] emozolyak | ||
---|---|---|---|
Line 47: | Line 47: | ||
end | end | ||
- | function outbit(condition, | + | function outbit(condition, |
if condition then | if condition then | ||
| | ||
Line 53: | Line 53: | ||
| | ||
| | ||
+ | end | ||
+ | |||
+ | function outBit(condition, | ||
+ | local new_value = outbit(condition, | ||
+ | | ||
end | end | ||
Line 135: | Line 140: | ||
<code lua> | <code lua> | ||
- | function DBG ( ... ) | + | function DBG( ...) -- ... accepts multiple |
- | | + | |
+ | local table_sign = '|' -- if there is divider sign, the values will be grouped in 2 rows | ||
+ | local table_sign_found = false | ||
+ | local tab_s_index = 0 | ||
if ENABLE_DEBUG then -- should be global in the calling script | if ENABLE_DEBUG then -- should be global in the calling script | ||
+ | |||
+ | -- find divider | ||
+ | for i = 1, #arg do | ||
+ | if arg[i] == table_sign then | ||
+ | table_sign_found = true | ||
+ | tab_s_index = i | ||
+ | break | ||
+ | end | ||
+ | end | ||
| | ||
- | local s = "" | + | |
- | for i = 1 , #arg do | + | INFO(tabToStr(arg)) -- outputs table values in a single row |
- | -- glue all and add spaces, use tostring to protect from nil argument | + | else |
- | | + | |
+ | |||
+ | for k = 1, tab_s_index - 1 do | ||
+ | | ||
end | end | ||
- | DEBUG ( s ) | + | for j = tab_s_index + 1, #arg do |
- | end -- if | + | value_t[j - tab_s_index] = tostring(arg[j]) |
+ | end | ||
+ | |||
+ | if (#header_t ~= #value_t) then | ||
+ | | ||
+ | else | ||
+ | for g = 1, #header_t do | ||
+ | local delta = # | ||
+ | | ||
+ | if (delta > 0) then | ||
+ | value_t[g] = value_t[g] .. string.rep(' | ||
+ | else | ||
+ | header_t[g] = header_t[g] .. string.rep(' | ||
+ | end | ||
+ | end | ||
+ | end -- for | ||
+ | INFO(tabToStr(header_t)) ; INFO(tabToStr(value_t)) | ||
+ | end | ||
+ | end | ||
+ | end -- if ENABLE_DEBUG | ||
+ | |||
+ | return true | ||
+ | end -- DBG | ||
+ | |||
+ | function tabToStr(t) | ||
+ | local s = "" | ||
+ | for i = 1, #t do | ||
+ | s = s .. tostring(t[i]) .. ' ' | ||
+ | end -- for | ||
+ | return s | ||
+ | end | ||
- | end -- DBG | ||
</ | </ | ||
+ | Then the print output can be enhanced like this: | ||
+ | {{ : | ||
The // | The // |
useful_programs.txt · Last modified: 2024/03/19 09:39 by emozolyak