/// <summary>
		/// Finds a symbol in the expression
		/// </summary>
		/// <param name="context">The context.</param>
		/// <returns></returns>
		public SymbolRef FindSymbol(ScriptExecutionContext context)
		{
			this.CheckScriptOwnership(context.GetScript());

			if (m_Exp != null)
				return m_Exp.FindDynamic(context);
			else
				return null;
		}
		/// <summary>
		/// Evaluates the expression
		/// </summary>
		/// <param name="context">The context.</param>
		/// <returns></returns>
		public DynValue Evaluate(ScriptExecutionContext context = null)
		{
			context = context ?? OwnerScript.CreateDynamicExecutionContext();

			this.CheckScriptOwnership(context.GetScript());

			if (m_Constant != null)
				return m_Constant;

			return m_Exp.Eval(context);
		}
Esempio n. 3
0
        /// <summary>
        /// Resumes the coroutine
        /// </summary>
        /// <param name="context">The ScriptExecutionContext.</param>
        /// <param name="args">The arguments.</param>
        /// <returns></returns>
        public DynValue Resume(ScriptExecutionContext context, params object[] args)
        {
            DynValue[] dargs = new DynValue[args.Length];

            for (int i = 0; i < dargs.Length; i++)
            {
                dargs[i] = DynValue.FromObject(context.GetScript(), args[i]);
            }

            return(Resume(context, dargs));
        }
Esempio n. 4
0
        /// <summary>
        /// Invokes the callback function
        /// </summary>
        /// <param name="executionContext">The execution context.</param>
        /// <param name="args">The arguments.</param>
        /// <param name="isMethodCall">if set to <c>true</c> this is a method call.</param>
        /// <returns></returns>
        public DynValue Invoke(ScriptExecutionContext executionContext, IList <DynValue> args, bool isMethodCall = false)
        {
            if (isMethodCall)
            {
                var colon = executionContext.GetScript().Options.ColonOperatorClrCallbackBehaviour;

                if (colon == ColonOperatorBehaviour.TreatAsColon)
                {
                    isMethodCall = false;
                }
                else if (colon == ColonOperatorBehaviour.TreatAsDotOnUserData)
                {
                    isMethodCall = (args.Count > 0 && args[0].Type == DataType.UserData);
                }
            }

            return(ClrCallback(executionContext, new CallbackArguments(args, isMethodCall)));
        }
Esempio n. 5
0
        /// <summary>
        /// Gets the specified argument as a string, calling the __tostring metamethod if needed, in a NON
        /// yield-compatible way.
        /// </summary>
        /// <param name="executionContext">The execution context.</param>
        /// <param name="argNum">The argument number.</param>
        /// <param name="funcName">Name of the function.</param>
        /// <returns></returns>
        /// <exception cref="ScriptRuntimeException">'tostring' must return a string to '{0}'</exception>
        public string AsStringUsingMeta(ScriptExecutionContext executionContext, int argNum, string funcName)
        {
            if ((this[argNum].Type == DataType.Table) && (this[argNum].Table.MetaTable != null) &&
                (this[argNum].Table.MetaTable.RawGet("__tostring") != null))
            {
                var v = executionContext.GetScript().Call(this[argNum].Table.MetaTable.RawGet("__tostring"), this[argNum]);

                if (v.Type != DataType.String)
                {
                    throw new ScriptRuntimeException("'tostring' must return a string to '{0}'", funcName);
                }

                return(v.ToPrintString());
            }
            else
            {
                return(this[argNum].ToPrintString());
            }
        }