AutoHotkey Community

It is currently May 26th, 2012, 8:38 pm

All times are UTC [ DST ]




Post new topic This topic is locked, you cannot edit posts or make further replies.  [ 1036 posts ]  Go to page Previous  1 ... 9, 10, 11, 12, 13, 14, 15 ... 70  Next
Author Message
 Post subject:
PostPosted: May 11th, 2009, 8:22 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7502
Location: Australia
It would be difficult without full unicode support. Since full unicode support will take a lot of work, I don't want to spend much time on "partial" support. (It will likely be a long while before I begin work on full unicode support.)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 12th, 2009, 1:19 am 
Offline

Joined: January 2nd, 2008, 4:47 am
Posts: 150
Location: Freenode IRC
Hey Lexikos, what would you think about these?

---
Add Variables A_SecondInstance and A_Reloaded, or A_LoadReason

These would compliment the OnExit A_ExitReason values (second/reload), but would allow the new instance of the script to know the reason that it started. You might approach this using the same Window Messages created for this purpose, or by appending a command-line switch that can be accessed via %1% %2% etc.

This will allow a script to display a configuration dialog or uninstall dialog for a normally invisible script, or to resume a possibly interrupted process.

---
Allow SetTimer to call Functions()
This would allow Timers to be used in #includes, without the Timer Label interrupting the auto-execute section of a script. It would also allow Timers to take advantage of Static variables. Cleaner!

Add GetTimer() Function to check if a Timer exists and get its current state.
---

Let RegExMatch support the option g), which would make it as powerful as StringSplit for building arrays. I'm not sure why RegExMatch is restricted to the first match. :S
---

Add Str(string,repetitions) for building strings. eg: Str("Abc",4) = AbcAbcAbcAbc

Add Int(value) which is the same as Floor(positive-value) and Ceil(negative-value), simply put, strip off any decimal points.
Int(1.5) = 1, Floor(1.5) = 1, Ceil(1.5) = 2 ... Int(-1.5) = -1, Floor(-1.5) = -2, Ceil(-1.5) = -1

Add Max(val1,val2 [,val3,val4,etc]) and Min(val1,val2 [,val3,val4,etc])
Returns the Max or Min value of the parameters passed.
Eg: Max(7,42,9,29,27) = 42 and Min(7,42,9,29,27) = 7
---

You should really come back to the IRC channel. I misses you! :D

_________________
Image

Need help right away? Get live support on IRC.
Already have an IRC client installed? /join #ahk


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 12th, 2009, 9:38 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7502
Location: Australia
Raccoon wrote:
Add Variables A_SecondInstance and A_Reloaded, or A_LoadReason
What would be the possible values of these variables? Btw,
Code:
If InStr(DllCall("GetCommandLine","str"),"/restart")
    MsgBox Script was probably restarted.
else
    MsgBox Script starting afresh.
I say "probably" because if "/restart" appears after the first unrecognized switch, it is treated as a script parameter. (For AutoHotkey.exe, the first unrecognized switch is used as the filename.) Also, "/R" has the same effect as "/restart".
Quote:
Allow SetTimer to call Functions()
This is something I've wanted for a while, but doesn't come up often. I don't have much idea of how best to implement it, but I haven't looked into the SetTimer code yet.
Quote:
This would allow Timers to be used in #includes, without the Timer Label interrupting the auto-execute section of a script. It would also allow Timers to take advantage of Static variables.
This is already possible:
Quote:
A function may contain externally-called subroutines such as timers, GUI g-labels, and menu items. This is generally done to encapsulate them in a separate file for use with #Include, which prevents them from interfering with the script's auto-execute section. However, the following limitations apply:
  • Such subroutines should use only static and global variables (not locals) if their function is ever called normally. This is because a subroutine thread that interrupts a function-call thread (or vice versa) would be able to change the values of local variables seen by the interrupted thread. Furthermore, any time a function returns to its caller, all of its local variables are made blank to free their memory.
  • Such subroutines should use only global variables (not static variables) as GUI control variables.
  • When a function is entered by a subroutine thread, any references to dynamic variables made by that thread are treated as globals (including commands that create arrays).
Source: Functions
As I see it, passing a function to SetTimer would only be of benefit if you could also specify values for the function's parameters. Otherwise I imagine it would be fairly simple to implement.
Quote:
Add GetTimer() Function to check if a Timer exists and get its current state.
Should the return value be similar to the "Period" parameter of SetTimer? Since "Off" is considered true in an expression and 0 is a legitimate period for an enabled timer, an empty string could be used to indicate the timer is disabled.

It would also be feasible to add some indication that the timer's subroutine is running. Would that be useful?
Quote:
Let RegExMatch support the option g)
Would it offer much benefit over grep()?

A few nights ago I wasted (not spent) several hours trying to determine how one might allow it to return every captured subpattern instead of just the last one. (Such a feature would likely be dependent upon the implementation of "proper" arrays.) Come to think of it, that feature could be adapted to achieve the same effect as g). Anyway, I'm likely to avoid further PCRE-related activities for a good while...
Quote:
I'm not sure why RegExMatch is restricted to the first match. :S
Naturally, not implementing the "g" option was simpler than implementing it. It isn't difficult to get more matches using a loop, as grep() shows. Here's a simple (possibly inadequate) example:
Code:
h := "grab each word."
n := "\w+"
p := 1
While p := RegExMatch(h, n, m, p) + StrLen(m)
    MsgBox % m


I'm open to suggestions, but I'd like to avoid building-in features which are easy to script. The function's you've suggested are perhaps good candidates for a standard library.

However, I think "Str" is a poor choice of name for that function because in my mind it looks like a type-cast and there's no connection to repeating a string. "Int" also seems like a type-cast, but in that case is appropriate; I'm used to int(n) having the effect you describe, but in another language, where it really is a type-cast.

Max(a,b) and Min(a,b) are very easy to script, but it's not as easy with more parameters. Rather than implementing these functions, I'd like to focus on implementing features that make scripting easier, especially for more advanced tasks. For instance:
Code:
Max(...) {
    Loop % A_Params.Count
        if A_Params[A_Index] > max
            max := A_Params[A_Index]
    return max
}
Unfortunately it's much more complicated than it looks. I'm confident of one thing: when I implement it, it won't be pretty. ;) Of course, the following would be better from a usability perspective:
Code:
Max(...) {
    ForEach param in A_Params
        if (param > max)
            max := param
}
...but I suppose that's even more complicated.
Quote:
You should really come back to the IRC channel.
I disabled my IRC client in an attempt to free up time to actually develop, but instead I've been "wasting" more time on the forums. ;) Expect to see me idling in #ahk soon.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 19th, 2009, 4:59 am 
Offline

Joined: January 2nd, 2008, 4:47 am
Posts: 150
Location: Freenode IRC
Lexikos wrote:
Raccoon wrote:
Add Variables A_SecondInstance and A_Reloaded, or A_LoadReason
What would be the possible values of these variables? Btw,
Code:
If InStr(DllCall("GetCommandLine","str"),"/restart")
    MsgBox Script was probably restarted.
else
    MsgBox Script starting afresh.
I say "probably" because if "/restart" appears after the first unrecognized switch, it is treated as a script parameter. (For AutoHotkey.exe, the first unrecognized switch is used as the filename.) Also, "/R" has the same effect as "/restart".

I would take a look at the code where AHK sends either of these two window messages. You should be able to create a global variable (if there isn't one already) that can be returned by a call to A_LoadReason. In response to your question, I would use the same values as A_ExitReason, being "Single" and "Reload" (or something like that without looking).
Code:
AHK_EXIT_BY_RELOAD          := WM_USER+6
AHK_EXIT_BY_SINGLEINSTANCE  := WM_USER+7

Lexikos wrote:
Raccoon wrote:
Allow SetTimer to call Functions()
This is something I've wanted for a while, but doesn't come up often. I don't have much idea of how best to implement it, but I haven't looked into the SetTimer code yet.
Raccoon wrote:
This would allow Timers to be used in #includes, without the Timer Label interrupting the auto-execute section of a script. It would also allow Timers to take advantage of Static variables.
This is already possible:
Quote:
A function may contain externally-called subroutines such as timers, GUI g-labels, and menu items. This is generally done to encapsulate them in a separate file for use with #Include, which prevents them from interfering with the script's auto-execute section. {snip}


Ah, I didn't know this! Thank you. But yes, passing variables could be useful but in reality I'm not hurting for such a feature. I do believe in KISS, and whatever keeps AutoHotkeySC.bin as small as possible is always the best solution. What I really needed was a way to include labels in a single library file, without having to split it "MyLibrary_autoexecute.ahk" and "MyLibrary_below_the_return.ahk".

Lexikos wrote:
Raccoon wrote:
Add GetTimer() Function to check if a Timer exists and get its current state.
Should the return value be similar to the "Period" parameter of SetTimer? Since "Off" is considered true in an expression and 0 is a legitimate period for an enabled timer, an empty string could be used to indicate the timer is disabled.

It would also be feasible to add some indication that the timer's subroutine is running. Would that be useful?

I'm not sure that 0 is a legitimate period for a timer, at least not internally. I have not examined the source, but in any event I believe returning a "1" in instances where the user specified "0" should be fine, as they both create a timer with the same system clock interval (usually 1/64th a second or 1/100th a second is the fastest a timer can respond, depending on the system clock (see GetSystemTimeAdjustment())).

I would like GetTimer(n) to return the n'th timer's label. Perhaps both GetTimer(Label/n) methods just return the timer's label if True.

Lexikos wrote:
Raccoon wrote:
Let RegExMatch support the option g)
Would it offer much benefit over grep()?

The reason I suggested adding g) was because I thought it may have been overlooked and could be relatively simple to implement since StringSplit does a similar thing with arrays... but mainly because it would be much FASTER than a scripted loop. I thought the feature was actually built into the PCRE library, utilizing a callback function, but I may be mistaken?

Lexikos wrote:
However, I think "Str" is a poor choice of name for that function because in my mind it looks like a type-cast and there's no connection to repeating a string. "Int" also seems like a type-cast, but in that case is appropriate; I'm used to int(n) having the effect you describe, but in another language, where it really is a type-cast.

Now that you mention it, both Str and Int may be reserved namespace for DllCall and NumGet/Put to work properly. I know they are used in VisualBasic and mIRC Script in the way I mentioned above, but I wouldn't be opposed to something like RepeatStr(s,n) and Intr(n).

Lexikos wrote:
Max(a,b) and Min(a,b) are very easy to script, but it's not as easy with more parameters. Rather than implementing these functions, I'd like to focus on implementing features that make scripting easier, especially for more advanced tasks. {snip}

Well, to be honest, it's probably best to just script since I can come up with a dozen more functions similar to Min and Max come to think of it. I'm just used to having it built in other languages, but looking over the command lists of these other languages, we could do some serious damage to the size of AutoHotkey with little effort. Nobody would probably use them anyway. :)

Would it be possible to write a Min or Max func in AHK script using self-recursion in an optimum way? Is there any loss in passing say 20 empty variables in a recursive function, or is there a better way of determining how many parameters are actually passed to a function?

I have some other suggestions and bugs i'd like to address, but I think I'll do them in a separate post. Thanks for replying and actually coding on my behalf! f'ing cool of you.

_________________
Image

Need help right away? Get live support on IRC.
Already have an IRC client installed? /join #ahk


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 19th, 2009, 7:51 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7502
Location: Australia
Raccoon wrote:
I'm not sure that 0 is a legitimate period for a timer, at least not internally.
It is, or I would not have said so.
Quote:
in any event I believe returning a "1" in instances where the user specified "0" should be fine,
I agree.
Quote:
as they both create a timer with the same system clock interval
AutoHotkey uses only a single OS timer with an interval of 10 for all script timers. If a script timer's period is 0, it will fire at the next interval. If it is greater than 0, it might fire at the next interval. After that, any period less than the actual interval of the main timer will behave the same since each script timer can only fire once per interval of the main timer.
Quote:
I thought the feature was actually built into the PCRE library, utilizing a callback function, but I may be mistaken?
Maybe you mean callouts, which AutoHotkey_L supports in scripts. To get the effect you're after, a particular pattern must be added to the regular expression. For example, this calls g() once for each word:
Code:
; Requires AutoHotkey_L Revision 14+
RegExMatch("The string", "\w+(*SKIP)(?Cg)")
g(match) {
    MsgBox % match
    return 1 ; Force testing of other possibilities.
}
Lexikos wrote:
Now that you mention it, both Str and Int may be reserved namespace for DllCall and NumGet/Put to work properly.
They are not currently reserved. DllCall does not accept "keywords", but actual variable references. (Only "and", "or" and "not" are actually keywords in expressions; "true" and "false" are implemented as built-in variables). If the variable does not contain a valid type name, it tries to use the variable's name. It can be confusing if a variable "Str" contains the value "Int". ;) Currently variable and function names may overlap without conflict. NumGet/Put, on the other hand, requires quote marks around literal type strings.
Quote:
Would it be possible to write a Min or Max func in AHK script using self-recursion in an optimum way? Is there any loss in passing say 20 empty variables in a recursive function, or is there a better way of determining how many parameters are actually passed to a function?
Why not just use a loop? Script recursion has considerable overhead, and probably always will. Maybe someday tail-recursion will be supported, but i think realistically that won't happen.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 24th, 2009, 1:42 pm 
Offline

Joined: June 17th, 2008, 7:51 am
Posts: 243
Hi Lexikos,
I think, I found a difference between AHKv1.0.48.03 and AHK_Lv1.0.48.03 (and also between the previous versions).

The code out of this thread in the german forum [Funktion] Farbige Buttons ohne GDI+ only shows me colored buttons with AHKv1.0.48.03.

Image

With AHK_Lv1.0.48.03 the buttons remain gray.

_________________
Greetings
Rog


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 24th, 2009, 4:18 pm 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7502
Location: Australia
I get the same result when compiling from stock-standard v1.0.48.03 source as on my latest build.

It is caused by a bug in the script:
Code:
hDC := DllCall("CreateCompatibleDC")

CreateCompatibleDC requires a parameter:
Code:
hDC := DllCall("CreateCompatibleDC", "UInt", 0)

Because the script wasn't specifying the parameter, CreateCompatibleDC was popping something it shouldn't off the stack. With whatever compiler Chris uses (Visual C++ 2003, I think), I suppose this "something" happened to be zero, so the call succeeded. Visual C++ 2008 generates different code from the same source, and in this case the "something" probably looked like a handle, so the call failed.

DebugBIF picks this sort of error up very quickly; if you run the script on standard v1.0.48.03 with it active, as soon as CreateCompatibleDC is called, a message pops up:
Code:
---------------------------
~.ahk - Built-in Function Error
---------------------------
DllCall
   [1]: "CreateCompatibleDC"
   ret: 469832883

ErrorLevel = A-4
---------------------------
OK   
---------------------------
Unfortunately, it relies on LowLevel and is therefore not compatible with the current (public) version of AutoHotkey_L. Actually, I've fixed that for the next release, but DebugBIF is slightly less useful (than on v1.0.48.03 standard):
Code:
---------------------------
~.ahk - Built-in Function Error
---------------------------
DllCall
   [1]: 1977177332
   ret: 872484765

ErrorLevel = A-4
---------------------------
OK   
---------------------------
Anyone care to hazard a guess at what the difference is? ;)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 24th, 2009, 5:35 pm 
Offline
User avatar

Joined: May 5th, 2007, 7:24 pm
Posts: 1240
Location: Seville, Spain
So the next AHK_L version will preconvert literal DLL function names into addresses? :D

_________________
fincs
Highly recommended: AutoHotkey_L (see why) (all my code snippets require it)
Formal request to polyethene - I support the unity of the AutoHotkey community
Get SciTE4AutoHotkey v3.0.00 (Release Candidate)
[My project list]


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 24th, 2009, 6:18 pm 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7502
Location: Australia
That's right. :) It can significantly improve performance in some cases. It also improves readability when the alternative is something like*:
Code:
MyAwfulFunc(SomeParam) {
    static SomeProc
    if !SomeProc
        SomeProc := DllCall("GetProcAddress", "uint", DllCall("GetModuleHandle", "str", "SomeDll"), "str", "SomeFunc")

    return DllCall(SomeFunc, "uint", SomeParam)
}
As you might expect, the first parameter must be a single literal quoted string, as in the examples in this post. Only functions which are already in memory when the script loads can be resolved, since loading a dll might have unwanted side-effects. Function names can't be validated (i.e. if SomeFunc can't be found, it can't show a useful load-time error) since some scripts may actually depend on DllCall to "fail safely". For instance,
Code:
if DllCall("IsWow64Process", "uint", DllCall("GetCurrentProcess"), "int*", isWow64process) && isWow64process
    MsgBox This OS is 64-bit.
If you run the script on something prior to XP SP2/Vista, that function won't exist, DllCall will return an empty string and the IF evaluates to false; i.e. the script works as intended. On my system, both functions are resolved at load-time. Strangely enough, "IsWow63Process" isn't...


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 24th, 2009, 9:48 pm 
Offline

Joined: June 17th, 2008, 7:51 am
Posts: 243
Thanks a lot. I would never find this.

_________________
Greetings
Rog


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 24th, 2009, 11:51 am 
Offline

Joined: April 22nd, 2009, 6:04 am
Posts: 29
Lexikos, i just want to say thanks to show my appreciation for all what you've given this Community.

:)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 25th, 2009, 6:31 pm 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7502
Location: Australia
Quote:
Revision 31 - September 26, 2009
  • Added: Object/array support and numerous minor changes to make this possible.
  • Added: Support for While(expression) with no delimiting space.
  • Added: Trim, LTrim, RTrim.
  • Added: A ~= B; equivalent to RegExMatch(A, B). May be removed in a future revision (feedback wanted).
  • Fixed: An incompatibility with LowLevel.
  • Changed: Characters [, ] and ? are no longer valid in variable names. Consequently, ? (ternary) no longer requires a space on either side.
  • Changed: Optional parameters may now be omitted at any position in the parameter list of a non-dynamic function call. Since this works by automatically inserting the parameter's default value at load-time, it is not supported or allowed for dynamic function-calls.
  • Debugger: Various minor changes to make program flow easier to follow while stepping through code.
  • Optimization: If DllCall's first parameter is a literal string which identifies a function already present in memory, it is replaced with the actual address of the function.
  • Updated from v1.0.48.03 to v1.0.48.04.

Be warned that object/array support is still very much a work in progress. (However, the documentation should be accurate for this revision.)

It's purely coincidental that this has come so shortly after v1.0.48.04. I was actually preparing to upload when I saw Chris' announcement. Btw, I've started using KDiff3 to merge Chris' changes; it is quite effective. :)

Edit: Don't replace your current version yet. There may be a crashing issue...
Edit: It appears to have been caused by some changes to SendMessage/PostMessage in v1.0.48.04. Revision 32 contains a fix.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 25th, 2009, 7:21 pm 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
Impressive release.

However, I'm disappointed that I wasn't invited to participate in the analysis and design for these major new features. While it's true I might have declined, the lack of any attempt at collaboration makes it harder to be interested in incorporating them in the AutoHotkey.com release.

Anyway, these new capabilities have been in demand a long time; I'm sure they'll be quite popular.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 25th, 2009, 7:29 pm 
Offline

Joined: December 17th, 2007, 6:39 pm
Posts: 235
Location: Galati, Romania
I totally agree with Chris.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 25th, 2009, 8:54 pm 
Offline
User avatar

Joined: May 5th, 2007, 7:24 pm
Posts: 1240
Location: Seville, Spain
YES
YES

Ok, I still support the idea of a directive that enables the object syntactic sugar because of backwards compatibility.

_________________
fincs
Highly recommended: AutoHotkey_L (see why) (all my code snippets require it)
Formal request to polyethene - I support the unity of the AutoHotkey community
Get SciTE4AutoHotkey v3.0.00 (Release Candidate)
[My project list]


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic This topic is locked, you cannot edit posts or make further replies.  [ 1036 posts ]  Go to page Previous  1 ... 9, 10, 11, 12, 13, 14, 15 ... 70  Next

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