AutoHotkey Community

It is currently May 27th, 2012, 11:45 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: June 9th, 2010, 8:15 pm 
Offline

Joined: June 18th, 2008, 8:36 am
Posts: 4923
Location: AHK Forum
While this works
Code:
b=Hello World
a=b
MsgBox % %a%
MsgBox % "" %a%

This does not
Code:
a=A_ScriptDir
MsgBox % %a% ;works fine
MsgBox % "" %a% ;does not work

_________________
AHK_H (2alpha) AHF TT _Struct WatchDir Yaml _Input ObjTree RapidHotkey DynaRun :wink:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 10th, 2010, 5:57 am 
Offline

Joined: August 24th, 2005, 5:29 pm
Posts: 549
Location: Berlin / Germany
The manual wrote:
Such a reference should not resolve to an environment variable, the clipboard, or any reserved/read-only variable. If it does, it is treated as an empty string.

_________________
nick :wink:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 10th, 2010, 6:42 am 
Offline

Joined: June 18th, 2008, 8:36 am
Posts: 4923
Location: AHK Forum
Thanks nick.

Is there a reason for that, especially since 'MsgBox % %a%' works.

Can this be changed/improved to work?

Moderator, can this thread be moved to Wish List?

_________________
AHK_H (2alpha) AHF TT _Struct WatchDir Yaml _Input ObjTree RapidHotkey DynaRun :wink:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 13th, 2010, 3:27 pm 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7503
Location: Australia
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:
  1. 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.
  2. 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...


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 19th, 2010, 9:28 pm 
Offline

Joined: June 18th, 2008, 8:36 am
Posts: 4923
Location: AHK Forum
Many thanks Lexikos, I will have a look at that ;)

Edit:
Seems to work fine, cool :D

_________________
AHK_H (2alpha) AHF TT _Struct WatchDir Yaml _Input ObjTree RapidHotkey DynaRun :wink:


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], Google Feedfetcher and 3 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group