decorator or docstring or "introspection"?

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
Lorien
Posts: 33
Joined: 10 Dec 2019, 11:16

decorator or docstring or "introspection"?

Post by Lorien » 28 Sep 2021, 07:08

I would like to #Include a file, and have information about what entry points (hotkey/string or menu callable functions) in that file available to the running AHK instance... without having to parse the source. I could (as I did under v1.0) define special comments, then read the files looking for those comments. On launch, I built menus for hotkeys, hotstring, and both left and right tray by adding a comment on the same line as a label.

But I would rather have AHK execute some piece of code that adds information into a global object. Some way to give a short little description for a label and a suggested default hotkey/hotstring. So, something like this [not valid] code would add the function, description, and suggestion to the global.

Code: Select all

addEntry("Take over the world.", "#p")
pinkyAndBrain() {
	....
}
Also, AFAIK, there is no way to list defined functions, right? You can test if a given name is a function, but you can't scan an Array/Map of objects/functions in the running instance.

I can picture how I could maybe to do this in Python (it's been a while)... but this isn't Python, and Lexikos has already poo-pooed docstrings viewtopic.php?p=330673#p330673.


EDIT: The idea is that a GUI would be filled with this information. Then functions could be assigned to menus. Hotkeys (and hotstrings) could be assigned/changed by way of HotKey() and Hotstring().


EDIT 2:
Umm... This "works"...

Code: Select all

myfunction.desc := "Hello"
myfunction() {
    return 5
}

msgbox myfunction.Name "  " myfunction.desc

User avatar
kczx3
Posts: 1640
Joined: 06 Oct 2015, 21:39

Re: decorator or docstring or "introspection"?

Post by kczx3 » 28 Sep 2021, 13:39

Sure, functions are objects in v2 so you can attach pretty much any property you'd like. I don't understand why that needs to actually be in the code as part of the object though.

swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: decorator or docstring or "introspection"?

Post by swagfag » 28 Sep 2021, 15:40

for methods viewtopic.php?p=422588#p422588

Lorien wrote:
28 Sep 2021, 07:08
Also, AFAIK, there is no way to list defined functions, right? You can test if a given name is a function, but you can't scan an Array/Map of objects/functions in the running instance.
u could if u read ur own process memory, found some global var structs and rifled through them, but ud be handicapping urself since every new release could potentially break it. there's no ahk native method to enumerate them

Lorien
Posts: 33
Joined: 10 Dec 2019, 11:16

Re: decorator or docstring or "introspection"?

Post by Lorien » 29 Sep 2021, 06:38

kczx3 wrote:
28 Sep 2021, 13:39
Sure, functions are objects in v2 so you can attach pretty much any property you'd like. I don't understand why that needs to actually be in the code as part of the object though.
It doesn't. It was just weird to see that work. But it doesn't solve the problem of finding the functions. I tried adding a __New and __Init to Function.Prototype, but they do not execute just for defining a function.


@swagfag Nope. Not going there. No even (really) tempted. I think the only "reasonable" way to get access to those structs would be to expose them with some API.... which would be implementing introspection (at least somewhat).

swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: decorator or docstring or "introspection"?

Post by swagfag » 29 Sep 2021, 07:36

Lorien wrote:
29 Sep 2021, 06:38
I think the only "reasonable" way to get access to those structs would be to expose them with some API.... which would be implementing introspection (at least somewhat).
i agree

Lorien
Posts: 33
Joined: 10 Dec 2019, 11:16

Re: decorator or docstring or "introspection"?

Post by Lorien » 30 Sep 2021, 07:04

swagfag wrote:
29 Sep 2021, 07:36
Lorien wrote:
29 Sep 2021, 06:38
I think the only "reasonable" way to get access to those structs would be to expose them with some API.... which would be implementing introspection (at least somewhat).
i agree
Huh. Random thought... Expose the debugging interface to the running instance somehow? (I just cringed. It might expose the variables, but controlling your own execution!?!?!?)

swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: decorator or docstring or "introspection"?

Post by swagfag » 08 Oct 2021, 19:54

sure, anything's possible. u have the source, change it, expose whatever u want exposed, recompile an exe and off u go!
idk about controlling ur execution though. maybe possible, but probably not from within the controlled-to-be script itself

Post Reply

Return to “Ask for Help (v2)”