Esempio n. 1
0
 /// <summary>
 /// Called when the item is a class definition item.
 /// </summary>
 /// <param name="target">The object that was passed to IParseItem.Accept.</param>
 /// <returns>The passed target or a modification of it.</returns>
 public IParseItem Visit(ClassDefItem target)
 {
     // Do nothing.
     return target;
 }
        /// <summary>
        /// Called when the item is a class definition item.
        /// </summary>
        /// <param name="target">The object that was passed to IParseItem.Accept.</param>
        /// <returns>The passed target or a modification of it.</returns>
        /// <exception cref="System.ArgumentNullException">If target is null.</exception>
        public IParseItem Visit(ClassDefItem target)
        {
            if (target == null)
                throw new ArgumentNullException("target");

            ILGenerator gen = compiler.CurrentGenerator;

            // string[] loc = new string[{implements.Count}];
            LocalBuilder loc = compiler.CreateArray(typeof(string), target.Implements.Count);

            int i = 0;
            foreach (var item in target.Implements)
            {
                // loc[{i}] = {implements[i]};
                gen.Emit(OpCodes.Ldloc, loc);
                gen.Emit(OpCodes.Ldc_I4, (i++));
                gen.Emit(OpCodes.Ldstr, item);
                gen.Emit(OpCodes.Stelem, typeof(string));
            }

            // E.Runtime.CreateClassValue(loc, {name});
            gen.Emit(OpCodes.Ldarg_1);
            gen.Emit(OpCodes.Callvirt, typeof(ILuaEnvironment).GetMethod("get_Runtime"));
            gen.Emit(OpCodes.Ldloc, loc);
            gen.Emit(OpCodes.Ldstr, target.Name);
            gen.Emit(OpCodes.Callvirt, typeof(ILuaRuntime).GetMethod("CreateClassValue"));
            compiler.RemoveTemporary(loc);

            return target;
        }