Obsolete test build - Functions and Objects as Labels (etc.)

Community news and information about new or upcoming versions of AutoHotkey
lexikos
Posts: 5817
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: New test build - Functions and Objects as Labels (and m

06 Jan 2015, 16:45

evilC wrote:Just a heads up - Bind() does not like being a class method.
What are you talking about? There is no problem making bind() a class method.

If what you want is a different method named "bind" which automatically binds to this of the object it is being called on, then you need to change the code to include this in the list of parameters being bound.
Lex - I take it Bind() is gonna be a built-in, so no point making it a class method anyway?
It will be a method of Func. There is no point making it a method of any other class unless you a) want that class to imitate a Func, or b) want to change the behaviour.
lexikos
Posts: 5817
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: New test build - Functions and Objects as Labels (and m

09 Jan 2015, 22:06

Is anyone using this test build?
Coco
Posts: 771
Joined: 29 Sep 2013, 20:37
GitHub: cocobelgica

Re: New test build - Functions and Objects as Labels (and m

09 Jan 2015, 22:18

Yep, working fine here. Btw, I assume I can't do Gui, Add, Button, w100 h30 g%Object%, Hello, where Object is an object? Edit: To use an object, you need to use GuiControl with the third parameter being a single %variable% deref (the object):
User avatar
evilC
Posts: 4016
Joined: 27 Feb 2014, 12:30

Re: New test build - Functions and Objects as Labels (and m

09 Jan 2015, 22:45

Having problems with my ADHD library.
All scripts written with it crash when you try to make certain bindings (eg RButton) when running this version.

I think the cause is something to do with how I have detected hotkeys.
I have an Input running which captures most keyboard keys, with appropriate use of EndKeys.

I then use an #if block to listen for extra buttons not supported by Input and if detected, set a variable and send the Escape key (which is an EndKey for the input):

Code: [Select all] [Expand] [Download] (Script.ahk)GeSHi © Codebox Plus


With this test version, the script hangs.

Any ideas?
Coco
Posts: 771
Joined: 29 Sep 2013, 20:37
GitHub: cocobelgica

Re: New test build - Functions and Objects as Labels (and m

09 Jan 2015, 22:49

Will this be changed/fixed?
lexikos wrote:Use objects with timers sparingly (or not at all) - as timers cannot be deleted, each time you register a new timer more memory will be allocated. Even if you turn off the timer, neither the timer nor the object will be freed.
User avatar
evilC
Posts: 4016
Joined: 27 Feb 2014, 12:30

Re: New test build - Functions and Objects as Labels (and m

09 Jan 2015, 22:50

Interestingly, a code snippet I wrote that uses the above #if technique works fine with this version.

It must be something else I am doing, but I have no idea what.
lexikos
Posts: 5817
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: New test build - Functions and Objects as Labels (and m

09 Jan 2015, 23:08

Coco wrote:Will this be changed/fixed?
How would you suggest it be changed/fixed?
I wrote:The problem is that the Priority setting needs to remain even after turning off the timer.


evilC wrote:All scripts written with it crash
...
With this test version, the script hangs.
Which is it? I interpret "crashing" to mean the program abruptly exits and Windows gives a "AutoHotkey has stopped working" message. If the script is hanging, which line is it hanging at, or when? Since you mentioned Input; note ErrorLevel will never be EndKey:A with this release, but EndKey:a.
GeekDude
Posts: 783
Joined: 02 Oct 2013, 22:13

Re: New test build - Functions and Objects as Labels (and m

09 Jan 2015, 23:14

Is this feature likely to make it into the official branch? I'm eager to put it to use in place of complicated and buggy custom SetTimer functions for polling events in my IRC bot
Coco
Posts: 771
Joined: 29 Sep 2013, 20:37
GitHub: cocobelgica

Re: New test build - Functions and Objects as Labels (and m

09 Jan 2015, 23:23

lexikos wrote:How would you suggest it be changed/fixed?
I'm not really familiar w/ the internals, perhaps something like SetTimer, %ObjRef%, Release? OR SetTimer, %ObjRef%, Off then ObjRelease(&ObjRef) / ObjRef := ""?
lexikos
Posts: 5817
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: New test build - Functions and Objects as Labels (and m

10 Jan 2015, 00:42

GeekDude wrote:Is this feature likely to make it into the official branch?
Yes. I was just concerned that some things (syntax) might need to be changed, or that I've introduced some bugs.
lexikos
Posts: 5817
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: New test build - Functions and Objects as Labels (and m

10 Jan 2015, 21:34

evilC wrote:Having problems with my ADHD library.
I think your problems are caused by a bug which was introduced in v1.1.19.00 and fixed in v1.1.19.01. The test build was based on .00. I have updated it with the latest fixes, including several new changes which I've detailed in the first post. The download has been updated.
GeekDude
Posts: 783
Joined: 02 Oct 2013, 22:13

Re: New test build - Functions and Objects as Labels (and m

10 Jan 2015, 23:49

This release seems to work great with GeekBot (under WINE on a VM I just made). Nothing appears to be broken, and I sucessfully implemented SetTimer to allow for arbitrarily timed plugin calls (with parameters too, thanks to Bind()) as defined in my Settings.ini file.
User avatar
evilC
Posts: 4016
Joined: 27 Feb 2014, 12:30

Re: New test build - Functions and Objects as Labels (and m

11 Jan 2015, 12:10

lexikos wrote:
evilC wrote:Having problems with my ADHD library.
I think your problems are caused by a bug which was introduced in v1.1.19.00 and fixed in v1.1.19.01. The test build was based on .00. I have updated it with the latest fixes, including several new changes which I've detailed in the first post. The download has been updated.

Just did a quick test and I am unable to replicate the crash with 1.1.19.01 yet.

Thanks Lex, I think you nailed it!
lexikos
Posts: 5817
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: New test build - Functions and Objects as Labels (and m

13 Jan 2015, 03:54

Update

I've updated the build with a new experimental feature:

Code: [Select all] [Download] GeSHi © Codebox Plus

^a::
^b::
pressing_ctrl_a_or_b_calls_this_function() {
MsgBox %A_ThisHotkey%
}
This was previously prohibited by load-time validation. There can be many hotkeys or (#If) hotkey variants stacked above the function definition. Regular labels and hotstring labels pointing at function definitions are still prohibited. Having any other executable line (like an assignment) between the hotkey and the function definition will cause the hotkey to behave as before. The function name must, as always, be unique.

This is not equivalent:

Code: [Select all] [Download] GeSHi © Codebox Plus

^a::
^b::
pressing_ctrl_a_or_b_calls_this_function()
return
pressing_ctrl_a_or_b_calls_this_function() {
MsgBox %A_ThisHotkey%
}
Specifically, if execution "falls into" the hotkey label from above, it will skip over the first form but not the second form. The exception is that the script's first hotkey always acts like return (because the loader inserts one to end the auto-execute section).

These forms are not supported and will act as before:

Code: [Select all] [Download] GeSHi © Codebox Plus

^a::fun()  ; Function call.
{ ; Empty block which will never execute.
}

^b::fun2() { ; Function call followed by unexpected "{".
}


Forward Compatibility

Currently when a function is used with a hotkey, timer, GUI control, etc. the function is allowed to define optional parameters. If a script does this and relies on the fact that hotkeys, timers, etc. don't pass any parameters, we won't be able to later add parameters without breaking the script. Therefore, before these features are merged into the main branch, we must decide whether to pass any parameters, and exactly what parameters to pass. Alternatively, functions which accept parameters could be prohibited for now to preserve forward-compatibility.

Backward Compatibility

When the program searches for a label or function by name, functions which require parameters are skipped over. This is mainly for simplicity, but also has implications for backward-compatibility.
  • If a function GuiClose(x) is defined, the GUI does not call it -- as before.
  • If a function GuiClose() is defined and a GuiClose: label is not, the GUI calls the function on closing, which might be unexpected.

If an older script specifies a label name and a function also exists by that name, the behaviour changes from "label does not exist" to calling the function instead. I think the chance of this occurring is very small, and it would only be a problem if the script is designed to expect the "label does not exist" exception.
lexikos
Posts: 5817
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: New test build - Functions and Objects as Labels (and m

13 Jan 2015, 05:44

Update (yes, another one)

SetTimer %Object%, Delete deletes the timer. All kinds of timers can be deleted, but it's only really needed for objects. Deleting a timer frees its reference to the object and a small amount of memory. If you turn a timer Off and back On, it retains its Period and Priority, so SetTimer %Object%, Off cannot release the object.

This build is v1.1.19.01-17+gbb7abfb.
GeekDude
Posts: 783
Joined: 02 Oct 2013, 22:13

Re: New test build - Functions and Objects as Labels (and m

13 Jan 2015, 09:02

I'm not so sure about that hotkey calling function definition thing. I'm having trouble thinking of a situation that would make the code easier to predict.
Coco
Posts: 771
Joined: 29 Sep 2013, 20:37
GitHub: cocobelgica

Re: New test build - Functions and Objects as Labels (and m

13 Jan 2015, 09:13

@lexikos, with the new "Hotkey calling function def" feature, will it be possible sometime in the future to support inline/anonymous/lambda functions?
guest3456
Posts: 2281
Joined: 09 Oct 2013, 10:31

Re: New test build - Functions and Objects as Labels (and m

13 Jan 2015, 15:01

GeekDude wrote:I'm not so sure about that hotkey calling function definition thing. I'm having trouble thinking of a situation that would make the code easier to predict.


same :crazy: Image

lexikos
Posts: 5817
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: New test build - Functions and Objects as Labels (and m

13 Jan 2015, 16:29

GeekDude, guest3456: I don't know what you're talking about. Why should it make the code more or less easy to predict?

Coco: I thought about simply allowing braces in v2 for denoting a "hotkey function", but it would break scripts in v1. If we ever have block-scoped variables, there'll be no need for an anonymous hotkey function. OTOH, a named one can make the hotkey's purpose immediately clear, if you name it well, and it also allows the function to be called from elsewhere.

Return to “Announcements”

Who is online

Users browsing this forum: SirRFI and 3 guests