Esempio n. 1
0
        public override void Execute(ScriptRuntimeContext context)
        {
            if (context.VariableExists(identifier))
            {
                //You cannot declare a local variable to shadow an existing global
                throw new ScriptRuntimeException($"Variable already declared in this context: {identifier}");
            }

            object defaultValue;

            if (initializer == null)
            {
                defaultValue = valueType.GetDefaultValue();
            }
            else
            {
                defaultValue = initializer.GetAs <object>(context);

                if (!valueType.IsAssignableFrom(initializer.GetValueType()))
                {
                    defaultValue = Convert.ChangeType(defaultValue, valueType);
                }
            }

            context.DeclareVariable(identifier, valueType, defaultValue);
        }
Esempio n. 2
0
        /// <summary>
        /// Creates declared variables in the script context
        /// </summary>
        /// <param name="context"></param>
        /// <exception cref="ScriptRuntimeException"></exception>
        public ScriptRuntimeContext PrepareScript(GlobalRuntimeContext context)
        {
            ScriptRuntimeContext scriptContext = new ScriptRuntimeContext(context, this);

            foreach (ScriptDeclaration declaration in scriptDeclarations)
            {
                declaration.Execute(scriptContext);
            }

            return(scriptContext);
        }
Esempio n. 3
0
        /// <summary>
        /// Executes the named function
        /// </summary>
        /// <exception cref="ScriptRuntimeException"></exception>
        public void ExecuteFunction(
            string functionName,
            ScriptRuntimeContext context,
            params object[] arguments)
        {
            if (!scriptFunctions.ContainsKey(functionName))
            {
                throw new ScriptRuntimeException($"Unable to find function {functionName} for external invocation.");
            }

            scriptFunctions[functionName].Execute(context, arguments);
        }
        public override void Execute(ScriptRuntimeContext context)
        {
            if (context.VariableExists(identifier))
            {
                throw new ScriptRuntimeException($"Variable already declared in this context: {identifier}");
            }

            if (context.GlobalVariableExists(identifier))
            {
                //Adding an indirect reference to the existing variable
                context.DeclareExistingGlobal(identifier, valueType);

                //Not running initialization because it exists
                return;
            }

            if (IsExtern)
            {
                throw new ScriptRuntimeException($"Extern Variable does not already exist: {identifier}");
            }

            object defaultValue;

            if (initializer == null)
            {
                defaultValue = valueType.GetDefaultValue();
            }
            else
            {
                defaultValue = initializer.GetAs <object>(context);

                if (!valueType.IsAssignableFrom(initializer.GetValueType()))
                {
                    defaultValue = Convert.ChangeType(defaultValue, valueType);
                }
            }

            context.DeclareNewGlobal(identifier, valueType, defaultValue);
        }
 public FunctionRuntimeContext(
     ScriptRuntimeContext scriptContext,
     in FunctionSignature functionSignature,
 public abstract void Execute(ScriptRuntimeContext context);