Jump to content

Sriptname of the included script?


Recommended Posts

I have a single function to output data into console _debug.js:

#include-once
Func _debug($val, $lineNumber = @ScriptLineNumber, $scriptName = @ScriptName)
    ConsoleWrite($scriptName & ":" & $lineNumber & " " & $val & @CRLF);
EndFunc

It works fine, however it only shows "main" script name and not "included".
For example if main.au3 script is:

#include "_debug.au3"
#include "secondary.au3"
_debug("foo")

and secondary.au3 is:

_debug("bar")

The console shows:

main.au3:1 bar
main.au3:3 foo

The line numbers are correct, but the filename is not.

Expected:

secondary.au3:1 bar
main.au3:3 foo

Any suggestions how to make it show #include scriptname?

 

Thank you.

Link to comment
Share on other sites

12 minutes ago, VAN0 said:

Any suggestions how to make it show #include scriptname?

nope. but you could move the ScriptLine to the end:

;Func _debug($val, $lineNumber = @ScriptLineNumber, $scriptName = @ScriptName)
Func _debug($val, $scriptName = "", $lineNumber = @ScriptLineNumber)
    ConsoleWrite($scriptName & ":" & $lineNumber & " " & $val & @CRLF);
EndFunc

I don't see another solution so far.

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

5 minutes ago, VAN0 said:

why this was rejected?

no clue. I wish your code ( or a new macro ) worked. But for now what you can do is to add a global and on each function you have add the filename, that way, if the file is loaded in SciTE, it could jump to it. Idea:

Func _debug($val, $scriptName = $g__ThisScrptName, $lineNumber = @ScriptLineNumber)
    ;$g__ThisScrptName = "MyUDF.au3" ; add this to every function, but this one.
    ConsoleWrite($scriptName & ":" & $lineNumber & " " & $val & @CRLF);
EndFunc

 

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

  • Moderators

Just curious, did you do as it suggested and use Au3Stripper to make 1 file with all includes, then use a debug.au3 that you or either someone else created?  I remember I wrote one that after I stripped the file it put a _debug() console message in every function so I knew where it was failing and what called it before hand if I was having issues.

It's a band-aid at best, but it works.  I see JPM submitted a func that I never heard of 3 years ago for it called FuncGetStack() but I don't see any anything in the change logs that suggest it was implemented or if it was on how to utilize it.

Not much help I'm sure, but hope it leads you into a direction you could easily remedy it.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

My _debug() is more like console.log in javascript - it accepts optional 20 arguments and the last two arguments were supposed to capture automatically line number and filename.

Submitting hard coded filename with each call of that function is highly unwelcome.

I'm not sure how Au3Stripper could help with running uncompiled script

Link to comment
Share on other sites

  • Moderators

Well, you're only using the Au3Stripper to debug your code.  It takes MANY files (includes+main au3(s)) and makes them 1.  Therefore your @ScriptLineNumber is accurate.  Pretty simple.

This of course is before pushing your script(s) out, this is more for the initial creation or addition, not really practical in a live environment (well I did it in all my live projects, I just used a $gb_LiveEnvironmentDebug bool for a different way to present my errors).

As far as not being practical for every function... Why not?  If you're having issues, then it's more than practical, just set a global 

MyDebug.au3

#include-once

Global $gb_MyDebugGlobalVar = False
Global $gs_LastFunctionCall = ""

Func __myDebug_Initialize($bInitialize = False)
    $gb_MyDebugGlboalVar = $bInitialize
EndFunc

Func __myDebug_SomeName($sFunction, $vVal)
    Local $sLastFuncCall = $gs_LastFunctionCall
    ; some debug stuff here eg:
    ConsoleWrite("Last Func: " & $sLastFuncCall & " : Current Func: " & $sFunction & " :: Value: " & $vVal)
    $gs_LastFunctionCall = $sFunction
    ;etc
EndFunc

Then in the function(s) you're going to test:

Func _someThing()
    If $gb_MyDebugGlobalVar Then
        __myDebug_SomeName("_someThing", "Line: " & @ScriptLineNumber & " : before some loop / after some loop, etc")
    EndIf
    ; rest of my code here for the actual func
EndIf

There's negligible overhead during debugging that way.  This is just pseudo code type.  I believe my original file (which I was going to look for but forgot lol) was much more detailed.

Anyway, I remember the frustration with 30k line scripts and finding that needle in the haystack, I learned quickly to do a debug script in all my main projects from then on, it may be a bit time consuming now, but if you have an error you can't currently find, you really only have yourself to lean on.

You could parse your code with StringRegExp() to find all your funcs and put the debug code in with a regex-replace or something to make it easy for your current project.

Anyway, I'm not giving a perfect solution, so all I can do is wish you best of luck. 

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

I still don't see any reason going through all this, if you are going to submit all the information with each call of the debug function...

Also, if Au3Stripper combines everything into a single file, and debug shows line number from that file, then you'll need somehow determine which part of that file belongs to which file...that doesn't sound easier at all...

Link to comment
Share on other sites

  • Moderators

If you don't know what function belongs to what au3 include file then your naming schemes probably need some help.  Use Ctrl+F if you can't remember, I dunno, it's hard to help those that find fault in everything before even trying.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...