Jump to content

Au3Stripper strips a used function


Factfinder
 Share

Recommended Posts

$Form = GUICreate("TEST", 500, 200, 200, 100, BitOR($WS_MAXIMIZEBOX, $WS_MINIMIZEBOX))
_Timer_SetTimer($Form, 2000, "Timertest")
GUISetState(@SW_SHOW)
While 1
WEnd

Func Timertest($hWnd, $iMsg, $iIDTimer, $iTime)
    #forceref $hWnd, $iMsg, $iIDTimer, $iTime
    Exit
EndFunc   ;==>TimeA

The above script works if not compiled or compiled without using Au3Stripper. When compiled with default Au3Stripper, it doesn't work because /sf removes the Timertest() function. By adding a dummy function (like If 1=2 then Timertest() ) to the script, the script works. I guess Au3Stripper doesn't regard the function "Timertest" called by _Timer_SetiTmer as a call to a function.

My apologies if I have posted this to the wrong section as I was not sure if this should be reported as an Autoit bug because it is related to the compiler and not AutoIt itself.

Link to comment
Share on other sites

Both ways are accepted, but you need to be careful about this if you intend to use AutoItStripper.  Using quotes (instead of naming the function directly) hides the function name to Stripper.  That is why in your snippet it was not working correctly.

Edited by Nine
Link to comment
Share on other sites

  • Developers

This is the best way of doing it as au3stripper doesn't know about all udf that possibly have a func name as parameter. Only internal functions are checked:

#include <WindowsConstants.au3>
#include <Timers.au3>
#Au3Stripper_Ignore_Funcs=Timertest
$Form = GUICreate("TEST", 500, 200, 200, 100, BitOR($WS_MAXIMIZEBOX, $WS_MINIMIZEBOX))
_Timer_SetTimer($Form, 2000, "Timertest")
GUISetState(@SW_SHOW)
While 1
WEnd

Func Timertest($hWnd, $iMsg, $iIDTimer, $iTime)
    #forceref $hWnd, $iMsg, $iIDTimer, $iTime
    Exit
EndFunc   ;==>TimeA

Jos

ps: please post a runnable script so it's easier to test... just like to ba lazy. ;) 

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Because functions are now first-class citizens, have two new recognized datatypes, whereas a string  argument may evaluate or not to a function.

So it's easy for AutoIt compiler, runtime executable and companion programs to detect that an argument is a function. Something evaluating to a string is not detectable in the general case.

_RunMeNative(10, _f)
_RunMeString(12, Chr(0x5F) & Chr(0x40 + 6))

ConsoleWrite(VarGetType(_f) & @TAB & VarGetType(Mod) & @TAB & VarGetType(Chr(0x5F) & Chr(0x40 + 6)) & @LF)

Func _RunMeNative($n, $fct)
    $fct($n)
EndFunc

Func _RunMeString($n, $fct)
    Call($fct, $n)
EndFunc

Func _f($i)
    ConsoleWrite(($i * $i) & @LF)
EndFunc

 

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

3 hours ago, jchd said:

Because functions are now first-class citizens, have two new recognized datatypes, whereas a string  argument may evaluate or not to a function.

That I understand, but my question was directed at Jos, since he said:

6 hours ago, Jos said:

This is the best way of doing it as au3stripper doesn't know about all udf that possibly have a func name as parameter. Only internal functions are checked:

Wherein he says the “best way” is to use a string and with the directive.  But if the function can be recognized directly without quoting, and without the need for a directive, then I would think that that would be the cleaner way.

Which way do you think is best and why?

Code hard, but don’t hard code...

Link to comment
Share on other sites

3 hours ago, JockoDundee said:

Which way do you think is best and why?

Not using quotes.  You will get immediate error without quotes:

#include <Timers.au3>
#include <GUIConstants.au3>

$Form = GUICreate("TEST", 500, 200, 200, 100, BitOR($WS_MAXIMIZEBOX, $WS_MINIMIZEBOX))
_Timer_SetTimer($Form, 2000, _Timertest)
GUISetState(@SW_SHOW)
While GUIGetMsg() <> $GUI_EVENT_CLOSE
WEnd

Func Timertest($hWnd, $iMsg, $iIDTimer, $iTime)
    #forceref $hWnd, $iMsg, $iIDTimer, $iTime
    Exit
EndFunc

Whereas using quotes, it will go undetected.  In a large program, it can be a pain to find the bug :

#include <Timers.au3>
#include <GUIConstants.au3>

$Form = GUICreate("TEST", 500, 200, 200, 100, BitOR($WS_MAXIMIZEBOX, $WS_MINIMIZEBOX))
_Timer_SetTimer($Form, 2000, "_Timertest")
GUISetState(@SW_SHOW)
While GUIGetMsg() <> $GUI_EVENT_CLOSE
WEnd

Func Timertest($hWnd, $iMsg, $iIDTimer, $iTime)
    #forceref $hWnd, $iMsg, $iIDTimer, $iTime
    Exit
EndFunc

I always preferred compilers to help me, instead of me helping compilers ;)

Edited by Nine
Link to comment
Share on other sites

  • Developers
12 hours ago, JockoDundee said:

I’m confused, why did removing the quotes work then?

That's simple: When removing the "" around the literal funcname it becomes a real variable, and since a while a variable notation can also refer to a UDF, hence au3stripper simply assumes that the parameter must be a reference to the func. ;) 

Still think it is better to instruct au3stripper not to strip those func's you always want to keep with the indicated directive.

Jos

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • 1 month later...

Very interesting. I didn't know that the function can be passed directly as a function name in this case. That is also one of the things that are not mentioned in the help. Or I haven't found it yet. ^^

@Jos
You favor the function name as a string together with the definition of an au3stripper directive. Is there also a technical background for this, or is it personal preference?

The background to my question: in one of my larger projects I have a large number of events and it would be very helpful for me if I could pass all the functions directly as function names for one simple reason: auto-completion. It is agony when I have to know exactly the function name that I want to call every time I define a new event. It would be much easier with autocomplete.

Edited by LukeWCS
Link to comment
Share on other sites

1 hour ago, LukeWCS said:

That is also one of the things that are not mentioned in the help

https://www.autoitscript.com/autoit3/docs/function_notes.htm

Quote

Function Notes

Functions in AutoIt are first class objects. Among other things, that means you can assign a function to a variable, pass it around as an argument or return from another function.

But I can agree that this section of HelpFile could be suplemented by additional examples.
 

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Link to comment
Share on other sites

  • Developers
4 hours ago, LukeWCS said:

@Jos
You favor the function name as a string together with the definition of an au3stripper directive. Is there also a technical background for this, or is it personal preference?

Not sure what you mean with favor function name as string?
Also not sure about the next part... so maybe a simple example snippet to show me what you mean?

Jos
 

 

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Developers
3 hours ago, mLipok said:

But I can agree that this section of HelpFile could be suplemented by additional examples.

More information doesn't always help making it better. Think that page is pretty clear as is as long as one knows what to look for an read it. ;) 

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

22 hours ago, mLipok said:

https://www.autoitscript.com/autoit3/docs/function_notes.htm

But I can agree that this section of HelpFile could be suplemented by additional examples.
 

Thanks for the hint. It took me a few minutes to find it in Help. Even if I had remembered it, I would not have linked this section to the Factfinder problem. Which is probably related to the fact that the example shown there with "MsgBox" does not explain what this is good for. A more detailed example would actually have made sense here. I only know something similar from other languages as an "anonymous function". But this seems to be something else.

 

19 hours ago, Jos said:

Not sure what you mean with favor function name as string?

I relate that to your two answers:

 

On 11/28/2020 at 10:43 PM, Jos said:

This is the best way of doing it as au3stripper doesn't know about all udf that possibly have a func name as parameter. Only internal functions are checked:

 

On 11/29/2020 at 1:48 PM, Jos said:

Still think it is better to instruct au3stripper not to strip those func's you always want to keep with the indicated directive.

From these two posts I can see that in this case you prefer the text variant plus au3stripper directive. And I wanted to know why you prefer that as I would rather prefer Nine's variant.

 

19 hours ago, Jos said:

Also not sure about the next part... so maybe a simple example snippet to show me what you mean?

In the help for the function that Factfinder uses it says:
 

_Timer_SetTimer ($ hWnd [, $ iElapse = 250 [, $ sTimerFunc = "" [, $ iTimerID = -1]]])

And in the help for the function, which is about in my case, it says:
 

GUISetOnEvent (specialID, "function" [, winhandle])

In both cases it is clearly a matter of a string that is to be passed in the parameter. So, of course, I assumed that this was the only variant. In the help, there is no indication that the function names can also be passed directly in the parameter, not just as text.

 

 

Link to comment
Share on other sites

1 hour ago, LukeWCS said:

Which is probably related to the fact that the example shown there with "MsgBox" does not explain what this is good for. A more detailed example would actually have made sense here

 

21 hours ago, Jos said:

More information doesn't always help making it better. Think that page is pretty clear as is as long as one knows what to look for an read it.

I try to propose something this week.

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Link to comment
Share on other sites

I've contributed a revised version of help about types and variables.  It's likely to appear with the next release but don't ask me when.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

  • Developers
3 hours ago, LukeWCS said:

From these two posts I can see that in this case you prefer the text variant plus au3stripper directive. And I wanted to know why you prefer that as I would rather prefer Nine's variant.

No preference, just explained the consequences and the difference. My stated preference is to add those functions to an  directive so they never will be stripped:

Quote
#Au3Stripper_Ignore_Funcs=                 Do not Strip these functions. FuncNames may end with an * to indicated matching FuncNames starting with the specified string.

Jos

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

I believe it is because most of the documentation was written before the addition of function as a variable type (appeared in 3.3.10.0 - end of dec. 2013).  After that it was common habit to use quotes around function to reference them as parameters.   But I cannot see any good reason to use them with quotes anymore.  Like it has already been said, using function as a variable gains multiple advantages :

1- Auto-completion

2- Recognition by Au3Check

3- Identification in Au3Stripper

4- Faster access to the function

5- Usage of function in variables

 

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...