Jump to content

Recommended Posts

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

Posted (edited)

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
  • Developers
Posted (edited)

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

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

au3stripper doesn't know about all udf that possibly have a func name as parameter. Only internal functions are checked:

Expand  

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

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

Posted

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

 

  Reveal hidden contents

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)

Posted
  On 11/29/2020 at 12:27 AM, 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.

Expand  

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

  On 11/28/2020 at 9: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:

Expand  

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

Posted (edited)
  On 11/29/2020 at 4:20 AM, JockoDundee said:

Which way do you think is best and why?

Expand  

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
  • Developers
Posted (edited)
  On 11/28/2020 at 11:52 PM, JockoDundee said:

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

Expand  

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

  • 1 month later...
Posted (edited)

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
Posted (edited)
  On 1/11/2021 at 10:36 AM, LukeWCS said:

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

Expand  

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.

Expand  

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:

  Reveal hidden contents

Signature last update: 2023-04-24

  • Developers
Posted
  On 1/11/2021 at 10:36 AM, 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?

Expand  

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

  • Developers
Posted (edited)
  On 1/11/2021 at 11:45 AM, mLipok said:

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

Expand  

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

Posted
  On 1/11/2021 at 11:45 AM, 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.
 

Expand  

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.

 

  On 1/11/2021 at 3:29 PM, Jos said:

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

Expand  

I relate that to your two answers:

 

  On 11/28/2020 at 9: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:

Expand  

 

  On 11/29/2020 at 12: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.

Expand  

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.

 

  On 1/11/2021 at 3:29 PM, Jos said:

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

Expand  

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.

 

 

Posted
  On 1/12/2021 at 11:00 AM, 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

Expand  

 

  On 1/11/2021 at 3:32 PM, 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.

Expand  

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:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

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.

  Reveal hidden contents

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)

  • Developers
Posted (edited)
  On 1/12/2021 at 11:00 AM, 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.

Expand  

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

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

Posted

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

 

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
  • Recently Browsing   0 members

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