Page 1 of 1

LUA debug_output

Posted: Thu Jul 21, 2011 11:04 pm
by E Programmer
I recently upgraded ZEUS and had a LUA macro that worked fine. In the new ZEUS it does not work.

I went to debug (turned on debugging) and as soon as the code hits the debug_output function it crashed. debug_output used to work. In fact, I did not add the debug_output code, it had been there from when I wrote the function.

debug_output(string) successfully displays the string THEN it crashes.

For example, I run macro on this line
test line

start of function:
function replace_string()
local tab_length = 2
local tab_chars = ' ' -- equal tab_length spaces
-- write out the comment string
local ln=get_line_text()
debug_output(ln)
MoveLineHome()
Output ends with:
Debug: get_line_text
Debug: debug_output
test lineDebug: stop_macro
Macro script generated '10' Debug, Error and/or Warning message(s).
If I comment out the debug_output(ln) the Output continues as:
Debug: get_line_text
Debug: MoveLineHome
How can I get debugging of some kind working so I can fix my code?

Posted: Fri Jul 22, 2011 12:57 am
by jussij
How can I get debugging of some kind working so I can fix my code?
I can confirm this is a bug :(

This will be fixed in the next beta version out soon.

Cheers Jussi

Posted: Mon Jul 25, 2011 12:09 am
by jussij
This issue should now be fixed in the latest beta version 10 found here: http://www.zeusedit.com/z300/ze397g-beta.zip

This is the Lua code I uses as a test case:

Code: Select all

function test_output()
    -- get the current line
    local ln=get_line_text()

    -- enable debug output so next line actually does something
    debug_enable()

    -- send current line to the debug output window
    debug_output(ln)

    -- send current line to the status bar
    message(ln)

    debug_disable()
end

test_output() -- run the macro
Cheers Jussi

Found the associated problem

Posted: Tue Aug 02, 2011 9:02 pm
by E Programmer
I'm trying to get my program to put in tabs as it once did in the macro.

Here is a slimmed down part of the code:

Code: Select all

function replace_string()
    local ln=get_line_text()
    MoveLineHome()
    if(string.len(ln)>0)then
        -- delete the line, it will be replaced
        MarkBlockSet()
        MoveLineEnd()
        MarkBlockReset()
        MarkDeleteEx()
        print(ln)
    end
end
Just copy and print a line, it should not change the file at all.
it's OK if line has only spaces and characters
it's OK if line has only tabs and characters
Adds extra characters when the line has tabs THEN spaces
File before:

Code: Select all

abTABcd ef gh
TABa bc
Dump:

Code: Select all

0000: 61 62 09 63 64 20 65 66   20 67 68 0D 0A 09 61 20 | ab.cd ef gh...a  
0010: 62 63 0D 0A                                       | bc..

output [run twice, once on each line] is

Code: Select all

abTABcd  ef  gh
TABaTAB bc
Dump

Code: Select all

0000: 61 62 09 63 64 20 20 65   66 20 20 67 68 0D 0A 09 | ab.cd  ef  gh... 
0010: 61 09 20 62 63 0D 0A                              | a. bc..          
2 spaces where once there was one!
or a TAB space where there once was one space when the 1st character in the line is TAB!

Posted: Tue Aug 02, 2011 9:19 pm
by E Programmer
The above was when my tab spacing was set to 4 [and tabs as spaces is not checked]

If I set it to 6 it acts differently

Same starting file, same code, output is

Code: Select all

abTABcd    ef    gh
TABaTAB bc
Dump:

Code: Select all

0000: 61 62 09 63 64 20 20 20   20 65 66 20 20 20 20 67 | ab.cd    ef    g 
0010: 68 0D 0A 09 61 09 20 62   63 0D 0A                | h...a. bc..      
Could Zeus be trying to make the spaces into tabs?

Posted: Thu Aug 04, 2011 12:09 am
by jussij
This issue should now be fixed in the latest version found here: http://www.zeusedit.com/zforum/viewforum.php?f=6

Cheers Jussi

Posted: Tue Aug 09, 2011 7:33 pm
by E Programmer
Jussie. With each update there is a change. But still no cigar :)

Here is what I am trying to do. create a macro that gives 1/2 tab.

Now when the line begins with a tab, it should copy the tab and add 2,3,4 spaces depending on the tab setting (4 6 or 8 columns).

at 4 column tabs, it adds 5 spaces (should be 2 : 3 too many)
at 6 column tabs, it adds 8 spaces (should be 3 : 5 too many)
at 8 column tabs, it adds 11 spaces (should be 4 : 9 too many)

Here is the code for 8 column tabs:

Code: Select all

function replace_string()
  local half_tab = 4
  local half_tab_chrs  = '    '  -- equal half_tab spaces
  -- get the line
  local data_line=get_line_text()
  debug_output("original:"..data_line.."\n")
  MoveLineHome()
  if(string.len(data_line)>0)then
  -- delete the line, it will be replaced
    MarkBlockSet()
    MoveLineEnd()
    MarkBlockReset()
    MarkDeleteEx()
    while string.len(data_line)>0 do
      debug_output("check 1st 2 characters:"..string.sub(data_line,1,half_tab).."\n")
      if(string.byte(data_line,1)==9)then -- a tab, copy this
        debug_output("tab found. Copy\n")
        print("\t")
        data_line=string.sub(data_line,2)
      elseif(string.sub(data_line,1,half_tab)==half_tab_chrs)then -- half_tab chars already here, replace with tab and done
        debug_output("half tab found. Tab and copy rest\n")
        debug_output("\t"..string.sub(data_line,half_tab+1).."\n")
        print("\t"..string.sub(data_line,half_tab+1))
        data_line=''
      else -- word: add half_tab chars and done.
        debug_output("string found, half tab and copy\n")
        debug_output(half_tab_chrs..data_line.."\n")
        print(half_tab_chrs..data_line)
        data_line=''
      end
      debug_output("Remaining Line:"..data_line.."\n")
    end
  end
end
The nice thing is, the debug output is perfect.

The error comes in the 7th line from the end:

Code: Select all

print(half_tab_chrs..data_line)
I test it by running it on a line that has characters like

ABC
1st run (b=blank):
bbbbABC
perfect

2nd run:
_ TAB_ _ABC
perfect

3rd run should be:
_ TAB_ _bbbbABC
but I get
_ TAB_ _bbbbbbbbbbbABC
way too many spaces. :(

Posted: Wed Aug 10, 2011 12:10 am
by jussij
Unfortunately I'm not seeing this :(

If I use this input file with the document type tabs as spaces and tab size set to 8, I get the result shown below for the original input also shown:

Code: Select all

Original:
_	_ _    ABC

Result of macro:
    _	_ _    ABC  |
The '|' indicates where the cursor was placed after the macro was run.

So for me the amount of white space is unchanged.

This is the debug output produced:

Code: Select all

Debug: Debug: Macro trace debugging is active.
Debug: debug_output
original:_	_ _    ABC
Debug: MoveLineHome
Debug: MarkBlockSet
Debug: MoveLineEnd
Debug: MarkBlockReset
Debug: MarkDeleteEx
Debug: debug_output
check 1st 2 characters:_	_
Debug: debug_output
string found, half tab and copy
Debug: debug_output
    _	_ _    ABC
Debug: debug_output
Remaining Line:
Are you seeing beta13 in the Help About box :?:

Cheers Jussi

Posted: Thu Sep 01, 2011 4:14 pm
by E Programmer
I think my example was confusing. :oops:

It may be working for you but I want to make sure you are using the proper example

Simple line with just ABC
ABC
Apply 1/2 tab macro get [4 spaces] ABC
ABC
Apply 1/2 tab macro get [tab] ABC
\tABC
Apply 1/2 tab macro should get [tab][4 spaces] ABC
\t ABC
But I get [tab][11 spaces] ABC
\t ABC

I am using Zeus 3.97g-beta 13
but I 'installed' it by just dropping the executable directory
into C:\WINDOWS\ZEUS [but not any of the sub directories]
in place of the old executable. The zip file really didn't seem to have an install.

Suggestion: it would be nice to have a page that tells one how to do an install without loosing your settings (like all my macros, keyboard shortcuts, keywords, toolbar settings, etc.) or have the install ask: New or Upgrade. Love the program, live an die by it :D

Posted: Mon Sep 05, 2011 12:00 am
by jussij
This bug should be fixed in the bete version 25 found here: http://www.zeusedit.com/z300/ze397g-beta.zip
Suggestion: it would be nice to have a page that tells one how to do an install without loosing your settings (like all my macros, keyboard shortcuts, keywords, toolbar settings, etc.)

See here: http://www.zeusedit.com/zforum/viewtopic.php?t=2719
Love the program, live an die by it.
:)

Cheers Jussi

Posted: Mon Sep 12, 2011 9:11 pm
by E Programmer
Works perfectly. Thanks.

You might want to set that upgrade page as a sticky. That way it would always be at the top of whatever forum you put it in.

Thanks again. :)