Can AutoHotKey 1.1.33.10v1 implement similar c# nameof() functions? That is, the function is to obtain the variable name

Post AHK_H specific scripts & libraries and discuss the usage and development of HotKeyIt's fork/branch
oldstone
Posts: 13
Joined: 28 Oct 2021, 07:29

Can AutoHotKey 1.1.33.10v1 implement similar c# nameof() functions? That is, the function is to obtain the variable name

Post by oldstone » 28 Oct 2021, 08:27

According to the viewpoint of online software engineering: https://bbs.csdn.net/topics/100114600 , the test and debugging time accounts for 30% ~ 40% of the time. Therefore, faster debugging output speed is very necessary. At present,, the ahklog. Info() function in ahkv1.ahk needs to enter the variable name manually twice, and ahkv1 needs faster debugging output speed. For example:

Code: Select all

aaa := "123"
ahklog.info("aaa: ", aaa)

But in c#, it needs only one time:
public static void printvar(string var_name)
{
   string tips = nameof(var_name);
   Console.WriteLine(tips + " is: " + var_name);
}
string aaa = "123";
printvar(aaa);
Printvar (aaa) in c#; Compared with ahklog.info ("aaa:", aaa) in ahkv1, it saves typing one time of an aaa variable, which is faster and less error produced.

HotKeyIt
Posts: 2364
Joined: 29 Sep 2013, 18:35
Contact:

Re: Can AutoHotKey 1.1.33.10v1 implement similar c# nameof() functions? That is, the function is to obtain the variable

Post by HotKeyIt » 28 Oct 2021, 15:29

Code: Select all

aaa:="123"
printvar(aaa)
printvar(ByRef var_name:=""){
  static _AHkVar,var
  if !var
    _AHkVar:="{Int64 ContentsInt64,Double ContentsDouble,PTR object},{char *mByteContents,LPTSTR CharContents},{UINT_PTR Length,_AHKVar *AliasFor},{UINT_PTR Capacity,UINT_PTR BIV},BYTE HowAllocated,BYTE Attrib,BYTE mScope,BYTE Type,LPTSTR Name",var:=Struct(_AhkVar)
  if IsByRef(var_name){
      var[]:=getvar(var_name)
      MsgBox % var.AliasFor.name " is: " var_name
  } else
      MsgBox (value) is: %var_name%
}

oldstone
Posts: 13
Joined: 28 Oct 2021, 07:29

Re: Can AutoHotKey 1.1.33.10v1 implement similar c# nameof() functions? That is, the function is to obtain the variable

Post by oldstone » 01 Nov 2021, 18:05

Thanks a lot.It works perfectly. There are more functions in version H, which is very necessary for me.

oldstone
Posts: 13
Joined: 28 Oct 2021, 07:29

Re: Can AutoHotKey 1.1.33.10v1 implement similar c# nameof() functions? That is, the function is to obtain the variable

Post by oldstone » 15 Mar 2022, 03:03

But I tested this function with an array and failed.

Code: Select all

bbb := [1,2,3]								
ccc := {key:"value"}		
printvar(ccc)               ;unsuccess 
printvar(bbb)               ;unsuccess

Post Reply

Return to “AutoHotkey_H”