Opened 11 years ago
Closed 11 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 Changed 11 years ago by FireFox
comment:2 Changed 11 years ago by James
@FireFox, from what I gather, this would allow a UDF file to know whether it has been included or not.
comment:3 follow-up: ↓ 6 Changed 11 years ago by mlipok
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 Changed 11 years ago by anonymous
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 Changed 11 years ago by mlipok
it's not supposed to be running the script, and the only example showing IDEA
comment:6 in reply to: ↑ 3 ; follow-up: ↓ 7 Changed 11 years ago by anonymous
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 in reply to: ↑ 6 Changed 11 years ago by mlipok
comment:8 Changed 11 years ago by BrewManNH
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 Changed 11 years ago by James
@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 Changed 11 years ago by BrewManNH
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 Changed 11 years ago by Beege
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()
comment:12 follow-up: ↓ 13 Changed 11 years ago by Mat
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 in reply to: ↑ 12 Changed 11 years ago by anonymous
@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 Changed 11 years ago by Jon
- Resolution set to Rejected
- Status changed from new to closed
Guidelines for posting comments:
- You cannot re-open a ticket but you may still leave a comment if you have additional information to add.
- In-depth discussions should take place on the forum.
For more information see the full version of the ticket guidelines here.
I don't understand the purpose of this, can you explain better what are the advantages to add this feature?