setVariable method

void setVariable(
  1. String name,
  2. dynamic value
)

Sets a variable in the current scope.

If the current scope is the global scope, a new scope is automatically pushed before setting the variable. This ensures that variables are always set in the current scope, rather than the global scope.

@param name The name of the variable to set. @param value The value to assign to the variable.

Implementation

void setVariable(String name, dynamic value) {
  if (_variableStack.length == 1 &&
      _variableStack.last == _variableStack.first) {
    // If we're still in the global scope, automatically push a new scope
    pushScope();
  }
  _variableStack.last[name] = value;
}