https://github.com/sancarn/CGUI
One thing I noticed is that if you include CGUI at the top of your script like:
Code: Select all
#include CGUI.ahk
;do stuff
return
Code: Select all
;do stuff
return
#include CGUI.ahk
Code: Select all
#include CGUI.ahk
;do stuff
return
Code: Select all
;do stuff
return
#include CGUI.ahk
Code: Select all
Goto End_CGUI
#NoEnv
Class CGUI
{
...
...
...
}
#include %A_LineFile%\..\gdip.ahk
#include %A_LineFile%\..\CControl.ahk
#include %A_LineFile%\..\CFileDialog.ahk
#include %A_LineFile%\..\CFolderDialog.ahk
#include %A_LineFile%\..\CEnumerator.ahk
#include %A_LineFile%\..\CMenu.ahk
End_CGUI:
After the script has been loaded, it begins executing at the top line, continuing until a Return, Exit, hotkey/hotstring label, or the physical end of the script is encountered (whichever comes first).
Personally I always prefer to have all my includes at the top, mainly because that's how I'd do it in any other language (C/C#/Ruby/Node/Python/...). I assume others are the same. Anyway this is besides the point. The point is, the library should be designed in such a way that it just works however you include it. As is, the library works sometimes and not others... That's terrible library design imo.
Indeed I did this in CMenu.ahk. My only concern there is the amount of refactoring it might entail... I don't know the full code base yet so couldn't say for certain how much CGUI uses global variables, goto statements etc. So yeah currently am a little hesitant to go down that route....
Ay! That is a great quick fix! I'll definitely give this one a go as it seems to be the easiest quick fix there is! Thanks!swagfag wrote: ↑05 Jun 2019, 14:08assuming those labels are handlers and not actually something that needs autoinitializingCode: Select all
Goto End_CGUI #NoEnv Class CGUI { ... ... ... } #include %A_LineFile%\..\gdip.ahk #include %A_LineFile%\..\CControl.ahk #include %A_LineFile%\..\CFileDialog.ahk #include %A_LineFile%\..\CFolderDialog.ahk #include %A_LineFile%\..\CEnumerator.ahk #include %A_LineFile%\..\CMenu.ahk End_CGUI:
Code: Select all
;do stuff
return
#include CGUI.ahk
someFunc(){
}
Code: Select all
Goto End_CGUI
#NoEnv
Class CGUI
{
...
...
...
}
#include %A_LineFile%\..\gdip.ahk
#include %A_LineFile%\..\CControl.ahk
#include %A_LineFile%\..\CFileDialog.ahk
#include %A_LineFile%\..\CFolderDialog.ahk
#include %A_LineFile%\..\CEnumerator.ahk
#include %A_LineFile%\..\CMenu.ahk
End_CGUI:
_:=_
Code: Select all
#Warn
_:=_
Thanks for the heads up. I think long term I'll be refactoring the code to use functions like you suggestedjeeswg wrote: ↑05 Jun 2019, 18:34This would trigger an error:As would var2 := var1, if var1 was not previously assigned.Code: Select all
#Warn _:=_
Handling #Warn is something worth considering if sharing your scripts widely. I.e. assigning variables, and using 'local' in functions, where appropriate, to avoid triggering #Warn errors.
I suggested goto only if there was an actual need to have the library at the top, eg, for static var initialisation order. Using work arounds such as those suggested here, only for the reason of having the include at the top, are terrible program design imo.I always prefer to have all my includes at the top
If you must have it point to something useless, use an empty block instead, or put the label above the code you actually want to execute_:=_
Users browsing this forum: No registered users and 372 guests