"Double-deref" not working in Keysharp.
Issue #65
closed
ISSUE
Variables as described on dynamic variables docs page do not function as in AHK.
working ahk script
target := 42
second := "target"
MsgBox(second) ; Normal (single) variable reference => target
MsgBox(%second%) ; Double-deref => 42
With AHK the MsgBoxes display as per the comments. With Keysharp both display “target”.
Comments (7)
-
repo owner -
reporter class myclass { mymember1 := 123 } c := myclass() val := 1 MsgBox(c.mymember%val%) ; Shows 123
(Using the ‘new’ keyword here will throw on error)
I believe your explanation is right. You might consider this also:
MyArray1 := "A" MyArray2 := "B" MyArray3 := "C" MyArray4 := MyArray1 ;MyArray4 := %MyArray1% ; ERROR: Variable not found. Specifically: A Loop 4 MsgBox MyArray%A_Index% ; Shows A, then B, then C, then A
-
repo owner Sounds good. The first snippet was just pseudo code to illustrate the point. Sounds like we agree so I’ll get going on it.
-
repo owner I’ve committed a fix, as well as updated unit tests. Please test.
-
reporter All unit tests confirmed, also when modified to v2-like syntax. Marking resolved and closing. Excellent work, thank you!
-
reporter - changed status to resolved
Resolved
-
reporter - changed status to closed
Closed.
- Log in to comment
It appears that I attempted to implement this, but misunderstood the documentation. After revisiting the documentation, tell me if this is correct:
Scenario 1: what you listed above, where the variable is referenced by itself, and thus dereferences two levels deep: second => “target”, then target => 42
Scenario 2: the variable is used in conjunction with another value, to access a variable or property of an object, and thus dereferences only one level deep: %A_Index% => 1, 2 or 3, then concatenated with MyArray
\%val% => 1, then concatenated with mymember
So by itself, it goes two levels deep, but when being used as a member and/or with a partial variable name, it goes one level deep.