HotKeyIt wrote:
'MsgBox % %a%' works.
That is due to an optimization: if an expression arg consists solely of a variable reference, it is converted to a simple input variable arg. If you wrap the double-deref in parentheses, it won't work.
Quote:
Is there a reason for that,
Code:
// Non-normal variables such as Clipboard and A_ScriptFullPath are not allowed to be
// generated from a double-deref such as A_Script%VarContainingFullPath% because:
// Update: The only good reason now is code simplicity. Reason #1 below could probably
// be solved via SYM_DYNAMIC.
// 1) Anything that needed their contents would have to find memory in which to store
// the result of Var::Get(), which would complicate the code since such handling would have
// to be added.
// 2) It doesn't appear to have much use, not even for passing them as a ByRef parameter to
// a function (since they're read-only [except Clipboard, but temporary memory would be
// needed somewhere if the clipboard contains files that need to be expanded to text] and
// essentially global by their very nature), and the value of catching unintended usages
// seems more important than any flexibilty that might add.
SYM_DYNAMIC has two parts:
- Potential environment variable or built-in variable.
- If it is a normal variable and is either not empty or no matching environment variable exists, it is pushed onto the stack as SYM_VAR.
- Otherwise it is evaluated (as a built-in or environment variable) and the resulting string is pushed onto the stack.
- Double-deref. Excluding error cases, the result is always SYM_VAR.
Many other parts of expression evaluation assume that SYM_VAR is a normal, read/write variable. For double-derefs to support built-in variables, similar processing must be done as for #1 above, i.e. to push the value onto the stack rather than the variable itself.
I have updated the
AutoHotkey_L downloads with
this patch for testing. It's almost entirely a Cut and Paste⢠solution.
Note that as an added benefit, the limitation described in the following comment has been removed:
Code:
// Even if it's an environment variable, it gets added as SYM_VAR. However, unlike other
// aspects of the program, double-derefs that resolve to environment variables will be seen
// as always-blank due to the use of Var::Contents() vs. Var::Get() in various places.
// This seems okay due to the extreme rarity of anyone intentionally wanting a double
// reference such as Array%i% to resolve to the name of an environment variable.
I guess there's a very slight chance this will break someone's script...