Exemple #1
0
            public ItemData(ILuaEnvironment E, string name, Type baseType, Type[] _interfaces)
            {
                this.MethodArgs = new List <ILuaValue>();
                this.Methods    = new List <MethodInfo>();
                this.Constants  = new List <ILuaValue>();
                this.Names      = new HashSet <string>();
                this.Env        = E;
                this.FID        = 0;

                // Create the type builder.
                var ab = AppDomain.CurrentDomain.DefineDynamicAssembly(
                    new AssemblyName("DynamicAssembly2"),
                    AssemblyBuilderAccess.RunAndSave);

                this.AB = ab;
                ModuleBuilder mb = ab.DefineDynamicModule("DynamicAssembly2.dll");

                this.TB       = mb.DefineType(name, TypeAttributes.Class | TypeAttributes.BeforeFieldInit | TypeAttributes.Public, baseType, _interfaces);
                this.EnvField = TB.DefineField("$Env", typeof(ILuaEnvironment), FieldAttributes.Private);

                // public ctor(ILuaValue[] methods, ILuaValue[] initialValues, LuaEnvironment E, ILuaValue[] ctorArgs, ILuaValue ctor);
                {
                    var temp = new[] { typeof(ILuaValue[]), typeof(ILuaValue[]), typeof(ILuaEnvironment), typeof(ILuaValue[]), typeof(ILuaValue) };
                    ConstructorBuilder ctor = TB.DefineConstructor(
                        MethodAttributes.Public | MethodAttributes.HideBySig,
                        CallingConventions.Standard,
                        temp);
                    this.CtorGen = ctor.GetILGenerator();

                    // base();
                    CtorGen.Emit(OpCodes.Ldarg_0);
                    CtorGen.Emit(OpCodes.Call, (baseType ?? typeof(object)).GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[0], null));

                    // this.$Env = E
                    CtorGen.Emit(OpCodes.Ldarg_0);
                    CtorGen.Emit(OpCodes.Ldarg_3);
                    CtorGen.Emit(OpCodes.Stfld, EnvField);
                }
            }