internal static DynValue ConvertIterator(Script script, IEnumerator enumerator)
        {
            EnumerableWrapper ei = new EnumerableWrapper(script, enumerator);

            return(DynValue.NewTuple(
                       DynValue.NewCallback(clr_iterator_next),
                       UserData.Create(ei),
                       DynValue.Nil));
        }
        private static DynValue clr_iterator_next(ScriptExecutionContext executionContext, CallbackArguments args)
        {
            DynValue userdata = args.AsType(0, "clr_iterator_next", DataType.UserData);
            DynValue prev     = args[1];

            UserData          ud       = userdata.UserData;
            EnumerableWrapper iterator = ud.Object as EnumerableWrapper;

            if (iterator == null)
            {
                throw ScriptRuntimeException.BadArgument(0, "clr_iterator_next",
                                                         (ud.Object != null) ? ud.Object.GetType().FullName : "null",
                                                         typeof(EnumerableWrapper).FullName,
                                                         false);
            }

            return(iterator.GetNext(prev));
        }
示例#3
0
		internal static DynValue ConvertIterator(Script script, IEnumerator enumerator)
		{
			EnumerableWrapper ei = new EnumerableWrapper(script, enumerator);
			return DynValue.NewTuple(UserData.Create(ei), DynValue.Nil, DynValue.Nil);
		}
        internal static DynValue ClrObjectToComplexMoonSharpValue(Script script, object obj)
        {
            DynValue v = TryClrObjectToSimpleMoonSharpValue(script, obj);

            if (v != null)
            {
                return(v);
            }

            v = UserData.Create(obj);

            if (v != null)
            {
                return(v);
            }

            if (obj is Type)
            {
                v = UserData.CreateStatic(obj as Type);
            }

            if (v != null)
            {
                return(v);
            }

            if (obj is Delegate)
            {
                return(DynValue.NewCallback(CallbackFunction.FromDelegate(script, (Delegate)obj)));
            }

            if (obj is MethodInfo)
            {
                MethodInfo mi = (MethodInfo)obj;

                if (mi.IsStatic)
                {
                    return(DynValue.NewCallback(CallbackFunction.FromMethodInfo(script, mi)));
                }
            }


            if (obj is System.Collections.IList)
            {
                Table t = ConvertIListToTable(script, (System.Collections.IList)obj);
                return(DynValue.NewTable(t));
            }

            if (obj is System.Collections.IDictionary)
            {
                Table t = ConvertIDictionaryToTable(script, (System.Collections.IDictionary)obj);
                return(DynValue.NewTable(t));
            }

            if (obj is System.Collections.IEnumerable)
            {
                var enumer = (System.Collections.IEnumerable)obj;
                return(EnumerableWrapper.ConvertIterator(script, enumer.GetEnumerator()));
            }

            if (obj is System.Collections.IEnumerator)
            {
                var enumer = (System.Collections.IEnumerator)obj;
                return(EnumerableWrapper.ConvertIterator(script, enumer));
            }

            throw ScriptRuntimeException.ConvertObjectFailed(obj);
        }
        internal static DynValue ConvertIterator(Script script, IEnumerator enumerator)
        {
            var ei = new EnumerableWrapper(script, enumerator);

            return(DynValue.NewTuple(UserData.Create(ei), DynValue.Nil, DynValue.Nil));
        }