コード例 #1
0
 public static IEnumerator EnumLuaCoroutine(LuaOnStackThread lthd)
 {
     if (lthd != null)
     {
         using (lthd)
         {
             while (true)
             {
                 lthd.DoResume();
                 var l   = lthd.L;
                 var rvc = l.gettop();
                 if (lthd.IsDone)
                 {
                     l.settop(0);
                     yield break;
                 }
                 else if (rvc > 0)
                 {
                     var result = l.GetLua(1);
                     if (rvc >= 2 && l.toboolean(2))
                     {
                         l.settop(0);
                         if (result is IEnumerator)
                         {
                             var etor = result as IEnumerator;
                             while (etor.MoveNext())
                             {
                                 yield return(etor.Current);
                             }
                         }
                         else if (result is IEnumerable)
                         {
                             var enumerable = result as IEnumerable;
                             foreach (var obj in enumerable)
                             {
                                 yield return(obj);
                             }
                         }
                         else
                         {
                             yield return(result);
                         }
                     }
                     else
                     {
                         l.settop(0);
                         yield return(result);
                     }
                 }
                 else
                 {
                     yield return(null);
                 }
             }
         }
     }
 }
コード例 #2
0
 public static IEnumerator EnumLuaCoroutine(LuaOnStackThread lthd)
 {
     if (lthd != null)
     {
         while (true)
         {
             var results = lthd.Resume();
             if (results != null)
             {
                 var result = results.UnwrapReturnValues();
                 if (results.Length >= 2 && results[1].UnwrapDynamic <bool>())
                 {
                     if (result is IEnumerator)
                     {
                         var etor = result as IEnumerator;
                         while (etor.MoveNext())
                         {
                             yield return(etor.Current);
                         }
                     }
                     else if (result is IEnumerable)
                     {
                         var enumerable = result as IEnumerable;
                         foreach (var obj in enumerable)
                         {
                             yield return(obj);
                         }
                     }
                     else
                     {
                         yield return(result);
                     }
                 }
                 else
                 {
                     yield return(result);
                 }
             }
             else
             {
                 yield break;
             }
         }
     }
 }