AutoHotkey Community

It is currently May 27th, 2012, 12:31 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: June 21st, 2005, 8:26 am 
Offline

Joined: June 9th, 2005, 8:27 am
Posts: 31
Location: Germany near Cologne
Tried to write a library (or other module) that contains everything in one script, so that the user does not have to edit or install the script (and if possible also without generating additional scripts on the disk (also automatically) to be #Included).

The only thing that he should do is: #Include lib_Script.AHK

Problem: sometime you need to include the same e.g. function (like an INIT and may be GLOBAL definitions) in many of your provided lib-functions and if you have to change these, you have to change all occurences. It would be great if these includes could reside inside lib_Script.AHK.

What I would like to to is:
Code:
; File: lib_Script.AHK
libFunc1( a, b )
{
   #IncludeAgain ,,[Globals]   ; incl this section from current script
   #IncludeAgain ,,[fInit]
   ...
   Var := ...
   Return %Var%
}

libFunc2( c, d )
{
   #IncludeAgain ,,[Globals]   ; incl this section from current script
   #IncludeAgain ,,[fInit]
   ...
   Var := ...
   Return %Var%
}

[Globals]
Global globVar1, globVar2

[fInit]
; maybe something like
if ( ! globVar1 )   ; if not init by the user, provide a default
   globVar1 := True
...



(Anyone any idea: Is there a possibility to do this without the wish [Sections] ?)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 21st, 2005, 12:44 pm 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
This is related to the proposal that preprocessor macros be supported. It's a somewhat advanced area that would have to be carefully designed to avoid disrupting existing script syntax, while being useful and flexible enough to justify the effort.

A system of simple substitutions might be worthwhile:
Code:
#define DeclareGlobals
(
global x, y, z
global LogFileName
)
...
MyFunc(a, b)
{
    %%DeclareGlobals%%   ; Perhaps %% can be used to increase uniqueness.
    ...
}

But even this seems difficult because the program must recognize and replace the string DeclareGlobals only in proper contexts, and it must do so at a stage earlier than when the lines are parsed and semi-compiled. This might add considerable complexity and code size.

Even so, I think it's worthwhile enough to plan to add it at some point. Thanks for illustrating its usefulness.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 21st, 2005, 2:29 pm 
Offline

Joined: June 9th, 2005, 8:27 am
Posts: 31
Location: Germany near Cologne
Thank for your detailed explanation.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 2 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group