diff --git a/Docs/src/var.but b/Docs/src/var.but index e2007e53..10566673 100644 --- a/Docs/src/var.but +++ b/Docs/src/var.but @@ -10,14 +10,17 @@ User variables can be declared with the \R{var}{Var} command. You can use these \S2{var} Var -\c var_name +\c [/GLOBAL] var_name -Declare a user variable. Allowed characters for variables names: [a-z][A-Z][0-9] and '_'. Variables cannot be declared in sections or functions. +Declare a user variable. Allowed characters for variables names: [a-z][A-Z][0-9] and '_'. All defined variables are global, even if defined in a section or a function. To make this clear, variables defined in a section or a function must use the /GLOBAL flag. The /GLOBAL flag is not required outside of sections and functions. \c Var example \c \c Function testVar +\c Var /GLOBAL example2 +\c \c StrCpy $example "example value" +\c StrCpy $example2 "another example value" \c FunctionEnd \S1{varother} Other Writable Variables diff --git a/Examples/UserVars.nsi b/Examples/UserVars.nsi index e1621d86..5362dcd5 100644 --- a/Examples/UserVars.nsi +++ b/Examples/UserVars.nsi @@ -40,6 +40,14 @@ Section "Dummy Section" SecDummy SectionEnd +Section "Another Section" + + Var /GLOBAL "AnotherVar" + + StrCpy $AnotherVar "test" + +SectionEnd + ;-------------------------------- ; Uninstaller diff --git a/Source/script.cpp b/Source/script.cpp index 96580e94..150733f3 100644 --- a/Source/script.cpp +++ b/Source/script.cpp @@ -5329,10 +5329,28 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) // Added by ramon 3 jun 2003 case TOK_DEFVAR: { - SCRIPT_MSG("VAR \"%s\"\n",line.gettoken_str(1)); - int res = DeclaredUserVar(line.gettoken_str(1)); - if (res != PS_OK) - return res; + int a=1; + + if (!strcmpi(line.gettoken_str(1),"/GLOBAL")) + { + a++; + } + + if (build_cursection) + { + if (a==1) + { + ERROR_MSG("Var: currently, only global variables can be defined.\n"); + PRINTHELP(); + } + } + + SCRIPT_MSG("Var: \"%s\"\n",line.gettoken_str(a)); + + int res = DeclaredUserVar(line.gettoken_str(a)); + if (res != PS_OK) + return res; + } return PS_OK; diff --git a/Source/tokens.cpp b/Source/tokens.cpp index 5ad2d666..7c52fb1c 100644 --- a/Source/tokens.cpp +++ b/Source/tokens.cpp @@ -258,7 +258,7 @@ static tokenType tokenlist[TOK__LAST] = // Added by ramon 23 May 2003 {TOK_ALLOWSKIPFILES,"AllowSkipFiles",1,0,"(off|on)",TP_ALL}, // Added by ramon 3 jun 2003 -{TOK_DEFVAR,"Var",1,0,"VarName",TP_GLOBAL}, +{TOK_DEFVAR,"Var",1,1,"[/GLOBAL] var_name",TP_ALL}, // Added by ramon 6 jun 2003 {TOK_VI_ADDKEY,"VIAddVersionKey",2,1,"/LANG=lang_id keyname value",TP_GLOBAL}, {TOK_VI_SETPRODUCTVERSION,"VIProductVersion",1,0,"[version_string_X.X.X.X]",TP_GLOBAL},