Is there a reliable way from inside a function I get a list of the parameters passed. In Python I would use their "introspection" features to get access to a hash table that contains the local parameters (the key is the name of the parameter, and the value is the value passed in). Is there any way to do this in AHK? I don't actually think there is, but thought I would ask anyway.
I know I could brute force it by looking at A_LineFile and A_ThisFunc to get access to the script (assuming it's not compiled), then parse out the parameter names and read them using %var%. I may go that route if there isn't an elegant solution, but I'm wondering if there is one that I'm missing.
Generic GetParameters Function
-
- Posts: 60
- Joined: 03 Oct 2013, 19:49
- Location: Seattle Area
- Contact:
- LinearSpoon
- Posts: 156
- Joined: 29 Sep 2013, 22:55
Re: Generic GetParameters Function
What do you need this for? Reading the script file for parameters and such is only going to work as long as the script isn't compiled...
If you want a set of parameters passed as keys associated with values, why not just use an associative array?
http://l.autohotkey.net/docs/Objects.ht ... ive_Arrays
Also possibly related are variadic functions. The downside to these is that parameters aren't given "meaningful" names and instead each parameter's key is just a number.
http://l.autohotkey.net/docs/Functions.htm#Variadic
If you want a set of parameters passed as keys associated with values, why not just use an associative array?
http://l.autohotkey.net/docs/Objects.ht ... ive_Arrays
Code: Select all
foo({greeting:"Hello world", pi:3.1415, path:A_WorkingDir})
foo(params)
{
for key,value in params
Msgbox % "params[" key "] = " value
}
http://l.autohotkey.net/docs/Functions.htm#Variadic
Code: Select all
foo("Hello world", 3.1415, A_WorkingDir)
foo(params*)
{
for key,value in params
Msgbox % "params[" key "] = " value
}
-
- Posts: 60
- Joined: 03 Oct 2013, 19:49
- Location: Seattle Area
- Contact:
Re: Generic GetParameters Function
I want it for debugging and crash messages. For example, if I have a generic exception handler that takes any unhandled exception, and wraps it up with a bunch of debugging information. I'd like to be able to have the names and values of the parameters, not just variadics, but all the parameters passed to the function.
One of the things I like about Python (although overall I like AHK a lot better) is that all that kind of stuff is readily available via introspection. You can get the local variables and parameters for every function on the call stack, which comes in handy. Just hoping I can do a light version of that with AHK.
One of the things I like about Python (although overall I like AHK a lot better) is that all that kind of stuff is readily available via introspection. You can get the local variables and parameters for every function on the call stack, which comes in handy. Just hoping I can do a light version of that with AHK.
- LinearSpoon
- Posts: 156
- Joined: 29 Sep 2013, 22:55
Re: Generic GetParameters Function
Well, AHK does have a debugger..viewing local variables as well as the stack should be possible. SciTE4AutoHotkey comes with support for it built in. The link and more info is in the manual here:
http://l.autohotkey.net/docs/AHKL_DBGPClients.htm
http://l.autohotkey.net/docs/AHKL_DBGPClients.htm
Re: Generic GetParameters Function
DBGP can only be used from a separate script or program.
You can probably do it with AutoHotkey.dll, which includes some functions for accessing low-level structures used by the interpreter. However, you can only access variables of the top-most instance of each function due to the way local variables work. This limitation also applies to DBGP.
You can probably do it with AutoHotkey.dll, which includes some functions for accessing low-level structures used by the interpreter. However, you can only access variables of the top-most instance of each function due to the way local variables work. This limitation also applies to DBGP.
In that case you would need to copy and paste the debugging code into each function, which sounds totally not worth doing.I know I could brute force it by looking at A_LineFile and A_ThisFunc to get access to the script (assuming it's not compiled), then parse out the parameter names and read them using %var%.
-
- Posts: 60
- Joined: 03 Oct 2013, 19:49
- Location: Seattle Area
- Contact:
Re: Generic GetParameters Function
That all makes sense, and pretty much what I expected. I've been putting the code in the gives me the information I want with editor macros which are pretty efficient, but not very pretty. Maybe one of these days I'll add a bit of introspection capabilities to AHK, but for the moment I'll just carry on as I've been doing.
Thanks for the help.
Thanks for the help.
Re: Generic GetParameters Function
That sounds like something I'd say, or might've said back when I wrote LowLevel.Wade Hatler wrote:Maybe one of these days I'll add a bit of introspection capabilities to AHK, but for the moment I'll just carry on as I've been doing.
-
- Posts: 60
- Joined: 03 Oct 2013, 19:49
- Location: Seattle Area
- Contact:
Re: Generic GetParameters Function
Didn't know about that. That's impressive work. I'll look at it a more closely.
Who is online
Users browsing this forum: Bing [Bot], mstrauss2021 and 313 guests