/// <summary> /// Searches the scope hierarchy for the given id, /// should return NoVariable if it is not found /// </summary> /// <param name="id"></param> /// <returns></returns> protected virtual object GetVariableInternal(string id, bool searchHierarchy) { if (vars.ContainsKey(id)) { return(vars[id]); } if (!searchHierarchy) { return(RuntimeHost.NoVariable); } IScriptScope scope = Parent; while (scope != null) { if (scope.HasVariable(id)) { return(scope.GetItem(id, true)); } scope = scope.Parent; } return(RuntimeHost.NoVariable); }
/// <summary> /// Searches the scope hierarchy for the given id, /// should return NoVariable if it is not found /// </summary> /// <param name="id"></param> /// <param name="searchHierarchy"></param> /// <returns></returns> protected virtual object GetVariableInternal(string id, bool searchHierarchy) { IValueReference result; if (_vars.TryGetValue(id, out result)) { return(result.Value); } if (!searchHierarchy) { return(RuntimeHost.NoVariable); } IScriptScope scope = Parent; while (scope != null) { if (scope.HasVariable(id)) { return(scope.GetItem(id, true)); } scope = scope.Parent; } return(RuntimeHost.NoVariable); }
public object Invoke(IScriptContext context, object[] args) { string id = (string)args[0]; IScriptScope scope = context.Scope; while (scope != null) { if (scope.HasVariable(id)) { return(true); } scope = scope.Parent; } return(false); }
/// <summary> /// Sets variable to the first scope in hierarchy which already has this variable /// </summary> /// <param name="id"></param> /// <param name="value"></param> /// <returns></returns> private static void SetToParentScope(IScriptScope parent, string id, object value) { IScriptScope scope = parent; while (scope != null) { if (scope.HasVariable(id)) { scope.SetItem(id, value); return; } scope = scope.Parent; } throw new ScriptIdNotFoundException(string.Format("Global name {0} was not found in scopes", id)); //parent.SetItem(id, value); }
private object GetIndentifierValue(IScriptContext context, string identifier) { //object result = context.GetItem(identifier, false); //if (result != RuntimeHost.NoVariable) return result; if (IsGlobal) { _variable = null; IScriptScope scope = context.Scope.Parent; while (scope != null) { if (scope.HasVariable(identifier)) { return(scope.GetItem(identifier, true)); } scope = scope.Parent; } } else { if (_variable != null && _variable.Value != null) { return(_variable.Value); } object result; _variable = CreateRef(identifier, context, true, out result); if (result != RuntimeHost.NoVariable) { return(result); } } return(RuntimeHost.HasType(identifier) ? (object)RuntimeHost.GetType(identifier) : NamespaceResolver.Get(identifier)); }