I've come up with a variant Deref function, all the 'variables' are derived from an object, passed to a function. It would not suffer from issues to do with local v. global. Also, I thought that a 'variable' '%%' might be dereferenced to a percent sign.
I want to eliminate continuation sections from all of my scripts, because they are awkward for parsing and conversion to AHK v2 etc. At the same time, I may want some of my continuation sections to use command style variables within expressions, as some of them currently do.
(However in principle, I'm not against continuation sections at all, and I would like to see a 'verbatim' 'command' for one-line 'continuation sections', to work much like the current continuation sections do now, for storing text verbatim (or semi-verbatim, its workings based on an options parameter). It could look similar to a command, although it would be a bit like the curly brackets array notation ('obj := {}') ... unique.)
[EDIT:] (Continuation sections are very useful for temporary and single-purpose small scripts, especially for pasting in a list of CRLF-delimited items verbatim.)
Code: Select all
q:: ;continuation section alternative
;e.g.
vText = ;continuation section
(Join`r`n
a
b
c
)
MsgBox, % vText
;to
vText := ""
. "a" "`r`n"
. "b" "`r`n"
. "c"
MsgBox, % vText
return
==================================================
Code: Select all
;q:: ;dereference, and continuation section alternatives
oArray := {vDir:"C:\MyDir", vNameNoExt:"New Text Document", vNum:3, vExt:".txt"}
vPath := "%vDir%\%vNameNoExt% (%vNum%)%vExt%"
MsgBox, % JEE_Deref2(vPath, oArray)
vDir:="C:\MyDir", vNameNoExt:="New Text Document", vNum:=3, vExt:=".txt"
vPath := vDir "\" vNameNoExt " (" vNum ")" vExt
MsgBox, % JEE_Deref2(vPath, oArray)
vPath := A_AhkPath
SplitPath, vPath, vName, vDir, vExt, vNameNoExt, vDrive
vList := "Path,Name,Dir,Ext,NameNoExt,Drive"
oArray := {}
Loop, Parse, vList, % ","
oArray["v" A_LoopField] := v%A_LoopField%
vText := ""
. "path: %vPath%`r`n"
. "name: %vName%`r`n"
. "dir: %vDir%`r`n"
. "ext: %vExt%`r`n"
. "name no ext: %vNameNoExt%`r`n"
. "drive: %vDrive%"
MsgBox, % JEE_Deref2(vText, oArray)
vText := ""
. "path: " vPath "`r`n"
. "name: " vName "`r`n"
. "dir: " vDir "`r`n"
. "ext: " vExt "`r`n"
. "name no ext: " vNameNoExt "`r`n"
. "drive: " vDrive
MsgBox, % vText
a := 10, b := 20
vText := a "% of " b
MsgBox, % vText
vText := "%a%%% of %b%"
oArray := {a:10,b:20}
MsgBox, % JEE_Deref2(vText, oArray)
vText := "%a%%PS% of %b%"
oArray := {a:10,b:20,ps:"%"}
MsgBox, % JEE_Deref2(vText, oArray)
return
;==================================================
JEE_Deref2(vText, oArray)
{
vOutput := ""
VarSetCapacity(vOutput, StrLen(vText)*2)
Loop, Parse, vText, % "%"
if (A_Index & 1)
vOutput .= A_LoopField
else if (A_LoopField = "")
vOutput .= "%"
else
vOutput .= oArray[StrSplit(A_LoopField, ".")*]
return vOutput
}