Exemplo n.º 1
0
        public static void AddGlobalOrLocalVariable(string name, GetVarFunction function,
                                                    ParsingScript script = null, bool localIfPossible = false)
        {
            name = Constants.ConvertName(name);
            Utils.CheckLegalName(name, script);

            bool globalOnly = !localIfPossible && !LocalNameExists(name);
            Dictionary <string, ParserFunction> lastLevel = GetLastLevel();

            if (!globalOnly && lastLevel != null && s_lastExecutionLevel.IsNamespace && !string.IsNullOrWhiteSpace(s_namespace))
            {
                name = s_namespacePrefix + name;
            }

            function.Name            = Constants.GetRealName(name);
            function.Value.ParamName = function.Name;

            if (!globalOnly && !localIfPossible && script != null && script.StackLevel != null && !GlobalNameExists(name))
            {
                script.StackLevel.Variables[name] = function;
            }

            if (!globalOnly && s_locals.Count > StackLevelDelta &&
                (localIfPossible || LocalNameExists(name) || !GlobalNameExists(name)))
            {
                AddLocalVariable(function);
            }
            else
            {
                AddGlobal(name, function, false /* not native */);
            }
        }
Exemplo n.º 2
0
        public static void AddGlobal(string name, ParserFunction function,
                                     bool isNative = true)
        {
            Utils.CheckLegalName(name);
            name = Constants.ConvertName(name);
            NormalizeValue(function);
            function.isNative = isNative;

            var  handle = OnVariableChange;
            bool exists = handle != null && s_variables.ContainsKey(name);

            s_variables[name] = function;

            function.Name = Constants.GetRealName(name);
#if UNITY_EDITOR == false && UNITY_STANDALONE == false && __ANDROID__ == false && __IOS__ == false
            if (!isNative)
            {
                Translation.AddTempKeyword(name);
            }
#endif
            if (handle != null && function is GetVarFunction)
            {
                handle.Invoke(function.Name, ((GetVarFunction)function).Value, exists);
            }
        }
Exemplo n.º 3
0
        public static void UpdateFunction(string name, ParserFunction function)
        {
            name = Constants.ConvertName(name);
            Utils.CheckLegalName(name);
            lock (s_variables)
            {
                // First search among local variables.
                if (s_lastExecutionLevel != null && s_locals.Count > StackLevelDelta)
                {
                    Dictionary <string, ParserFunction> local = s_lastExecutionLevel.Variables;

                    if (local.ContainsKey(name))
                    {
                        // Local function exists (a local variable)
                        local[name] = function;
                        return;
                    }
                }
            }
            // If it's not a local variable, update global.
            s_variables[name] = function;
        }