MCPcopy Create free account
hub / github.com/AutoHotkey/AutoHotkey / FindOrAddVar

Method FindOrAddVar

source/script.cpp:7027–7046  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7025
7026
7027Var *Script::FindOrAddVar(LPCTSTR aVarName, size_t aVarNameLength, int aScope)
7028// Caller has ensured that aVarName isn't NULL.
7029// Returns the Var whose name matches aVarName. If it doesn't exist, it is created.
7030{
7031 if (!*aVarName)
7032 return NULL;
7033 ResultType result = OK; // Must set default.
7034 VarList *varlist;
7035 int insert_pos;
7036 Var *var;
7037 if (var = FindVar(aVarName, aVarNameLength, aScope, &varlist, &insert_pos, &result))
7038 return var;
7039 if (!result) // An error was displayed.
7040 return nullptr;
7041 // Otherwise, no match found, so create a new var.
7042 bool is_local = varlist != GlobalVars();
7043 // This will return NULL if there was a problem, in which case AddVar() will already have displayed the error:
7044 return AddVar(aVarName, aVarNameLength, varlist, insert_pos
7045 , (aScope & ~(VAR_LOCAL | VAR_GLOBAL)) | (is_local ? VAR_LOCAL : VAR_GLOBAL)); // When aScope == FINDVAR_DEFAULT, it contains both the "local" and "global" bits. This ensures only the appropriate bit is set.
7046}
7047
7048
7049

Callers 3

CreateClassMethod · 0.80
ExpressionToPostfixMethod · 0.80
AutoHotkey.cppFile · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected