Opened 13 years ago
Closed 12 years ago
#2385 closed Feature Request (Rejected)
@include
| Reported by: | anonymous | Owned by: | |
|---|---|---|---|
| Milestone: | Component: | AutoIt | |
| Version: | Severity: | None | |
| Keywords: | Cc: |
Description
A new makro that would be very easy to implement:
Before executing or "compiling" the AutoIt script, the preprocessor replaces @include with False in the main script and with True in every include.
Example (MyUDF.au3)
#include-once If (Not @include) Then _MyUDF__Example() Func _MyUDF__Example() ; GUI to test/demonstrate all the functions in this UDF EndFunc Func _MyUDF_Function1(...) ;... EndFunc ;...
Attachments (0)
Change History (14)
comment:1 by , 13 years ago
comment:2 by , 13 years ago
@FireFox, from what I gather, this would allow a UDF file to know whether it has been included or not.
follow-up: 6 comment:3 by , 13 years ago
Firstly, it was not my TICKET
Second, thought about, and I made an example of what the applicant wanted to achieve, or at least I think that was it.
local $fDeclared1 = IsDeclared('__IELoadWaitTimeout')
If $fDeclared1 = 1 Then
ConsoleWrite('<ie.au3> is included' & @CRLF)
Else
ConsoleWrite('<ie.au3> is not included yet' & @CRLF)
#include <ie.au3>
local $fDeclared2 = IsDeclared('__IELoadWaitTimeout')
If $fDeclared2 = 1 Then
ConsoleWrite('<ie.au3> now is included' & @CRLF)
Else
ConsoleWrite('<ie.au3> still is not included' & @CRLF)
EndIf
EndIf
Unfortunately does not work, but I think explains the idea.
comment:4 by , 13 years ago
James is right. I have tried to explain it two times in the past few days, but my posts always vanish.
@mlipok I guess we mean the same thing, but your solution is very messy and I don't want to call any functions to achive that.
comment:5 by , 13 years ago
it's not supposed to be running the script, and the only example showing IDEA
follow-up: 7 comment:6 by , 13 years ago
Replying to mlipok:
Else #include <ie.au3>Unfortunately does not work, but I think explains the idea.
You cannot use #include in an if clause, that's why it is not working.
comment:7 by , 13 years ago
comment:8 by , 13 years ago
I'm at a loss trying to figure out what the point of this is myself. What exactly would this achieve, and what benefit would it have to anyone?
comment:9 by , 13 years ago
@BrewManNH, I guess it would mean that one file can act independently if it's not as a UDF or only provide a subset of functionality if it was.
comment:10 by , 13 years ago
I still don't understand the point of it. I'd declare a variable in the main script and check to see if it's declared in the UDF, if I were ever to have the need to do something like this myself. But, I suppose that might be too difficult for some.
comment:11 by , 13 years ago
Im confused on the implementation. From the example posted and assuming that would be an include, if the preprocessor replaces @include with true you would end up with this correct?
If (Not True) Then _MyUDF__Example()
follow-up: 13 comment:12 by , 13 years ago
Basically, the op is looking for something similar to pythons if __name__ == __main__ which is used fairly often in python modules.
This allows a module to be a program and a library in the same file. So in the op's example, running the include file directly would run some tests, or examples or something, whereas running another file that included it would do nothing.
Mlipok, that's not what the op was looking for, and relies on runtime includes in addition to this. It's somewhat unnecessary as well when we already have #include-once.
I think without a lot of the other reflection/runtime features other languages have this feature would not be particularly useful.
comment:13 by , 12 years ago
@Beege Correct.
@Mat Even without additional features it would be useful for managing a lot of includes (because they would not need additional files for examples) and demonstrating their usage to others. Another advantage would be that it would be easy to implement.
comment:14 by , 12 years ago
| Resolution: | → Rejected |
|---|---|
| Status: | new → closed |

I don't understand the purpose of this, can you explain better what are the advantages to add this feature?