internal ScriptExecutionContext(Processor p, CallbackFunction callBackFunction, SourceRef sourceRef, bool isDynamic = false)
		{
			IsDynamicExecution = isDynamic;
			m_Processor = p;
			m_Callback = callBackFunction;
			CallingLocation = sourceRef;
		}
Beispiel #2
0
        /// <summary>
        /// Registers a module type to the specified table
        /// </summary>
        /// <param name="gtable">The table.</param>
        /// <param name="t">The type</param>
        /// <returns></returns>
        /// <exception cref="System.ArgumentException">If the module contains some incompatibility</exception>
        public static Table RegisterModuleType(this Table gtable, Type t)
        {
            Table table = CreateModuleNamespace(gtable, t);

            foreach (MethodInfo mi in Framework.Do.GetMethods(t).Where(__mi => __mi.IsStatic))
            {
                if (mi.GetCustomAttributes(typeof(MoonSharpModuleMethodAttribute), false).ToArray().Length > 0)
                {
                    MoonSharpModuleMethodAttribute attr = (MoonSharpModuleMethodAttribute)mi.GetCustomAttributes(typeof(MoonSharpModuleMethodAttribute), false).First();

                    if (!CallbackFunction.CheckCallbackSignature(mi, true))
                    {
                        throw new ArgumentException(string.Format("Method {0} does not have the right signature.", mi.Name));
                    }

#if NETFX_CORE
                    Delegate deleg = mi.CreateDelegate(typeof(Func <ScriptExecutionContext, CallbackArguments, DynValue>));
#else
                    Delegate deleg = Delegate.CreateDelegate(typeof(Func <ScriptExecutionContext, CallbackArguments, DynValue>), mi);
#endif

                    Func <ScriptExecutionContext, CallbackArguments, DynValue> func =
                        (Func <ScriptExecutionContext, CallbackArguments, DynValue>)deleg;


                    string name = (!string.IsNullOrEmpty(attr.Name)) ? attr.Name : mi.Name;

                    table.Set(name, DynValue.NewCallback(func, name));
                }
                else if (mi.Name == "MoonSharpInit")
                {
                    object[] args = new object[2] {
                        gtable, table
                    };
                    mi.Invoke(null, args);
                }
            }

            foreach (FieldInfo fi in Framework.Do.GetFields(t).Where(_mi => _mi.IsStatic && _mi.GetCustomAttributes(typeof(MoonSharpModuleMethodAttribute), false).ToArray().Length > 0))
            {
                MoonSharpModuleMethodAttribute attr = (MoonSharpModuleMethodAttribute)fi.GetCustomAttributes(typeof(MoonSharpModuleMethodAttribute), false).First();
                string name = (!string.IsNullOrEmpty(attr.Name)) ? attr.Name : fi.Name;

                RegisterScriptField(fi, null, table, t, name);
            }

            foreach (FieldInfo fi in Framework.Do.GetFields(t).Where(_mi => _mi.IsStatic && _mi.GetCustomAttributes(typeof(MoonSharpModuleConstantAttribute), false).ToArray().Length > 0))
            {
                MoonSharpModuleConstantAttribute attr = (MoonSharpModuleConstantAttribute)fi.GetCustomAttributes(typeof(MoonSharpModuleConstantAttribute), false).First();
                string name = (!string.IsNullOrEmpty(attr.Name)) ? attr.Name : fi.Name;

                RegisterScriptFieldAsConst(fi, null, table, t, name);
            }

            return(gtable);
        }
Beispiel #3
0
		/// <summary>
		/// Gets an execution context exposing only partial functionality, which should be used for
		/// those cases where the execution engine is not really running - for example for dynamic expression
		/// or calls from CLR to CLR callbacks
		/// </summary>
		internal ScriptExecutionContext CreateDynamicExecutionContext(CallbackFunction func = null)
		{
			return new ScriptExecutionContext(m_MainProcessor, func, null, isDynamic : true);
		}
Beispiel #4
0
 /// <summary>
 /// Gets an execution context exposing only partial functionality, which should be used for
 /// those cases where the execution engine is not really running - for example for dynamic expression
 /// or calls from CLR to CLR callbacks
 /// </summary>
 internal ScriptExecutionContext CreateDynamicExecutionContext(CallbackFunction func = null)
 {
     return(new ScriptExecutionContext(m_MainProcessor, func, null, isDynamic: true));
 }
Beispiel #5
0
 internal Coroutine(CallbackFunction function)
 {
     Type          = CoroutineType.ClrCallback;
     m_ClrCallback = function;
     OwnerScript   = null;
 }
Beispiel #6
0
 internal Coroutine(CallbackFunction function)
 {
     Type          = CoroutineType.ClrCallback;
     m_ClrCallback = function;
 }
Beispiel #7
0
 internal Coroutine(CallbackFunction function)
 {
     this.Type        = CoroutineType.ClrCallback;
     _clrCallback     = function;
     this.OwnerScript = null;
 }