示例#1
0
 public static LuaValue Wrap(LuaValue[] args)
 {
     LuaFunction f = args[0] as LuaFunction;
     LuaCoroutine c = new LuaCoroutine(f);
     LuaFunction f2 = new LuaFunction(new LuaFunc(delegate(LuaValue[] args2) { return LuaBoolean.From(c.Resume(args2)); }));
     return f2;
 }
示例#2
0
 public static LuaValue Create(LuaValue[] args)
 {
     LuaFunction func = args[0] as LuaFunction;
     if (func == null)
         throw new ArgumentException("Function expected, got '" + args[0].Value.GetType().Name + "'");
     LuaCoroutine c = new LuaCoroutine(func);
     return c;
 }
示例#3
0
 public bool Resume(LuaValue[] args)
 {
     if (thread == null)
     {
         thread = new Thread(new ThreadStart(delegate()
                                             {
                                                 try {
                                                     _status = "running";
                                                     func.Invoke(args);
                                                     _status = "dead";
                                                     Running = null;
                                                 } catch (Exception) {
                                                     _status = "dead";
                                                 }
                                             }));
         thread.SetApartmentState(ApartmentState.MTA);
         thread.Start();
     }
     else
     {
         if (_status == "dead")
             throw new Exception("Error: coroutine is dead, it cannot be resumed!");
         try {
             if (_status == "suspended")
                 thread.Resume();
             else
             thread.Start();
             _status = "running";
         } catch (Exception ex) {
             _status = "dead";
             throw ex;
         }
     }
     Running = this;
     return true;
 }
示例#4
0
 public bool Resume(LuaValue[] args)
 {
     if (thread == null)
     {
         thread = new Thread(new ThreadStart(delegate()
                                             {
                                                 try {
                                                     _status = "running";
                                                     func.Invoke(args);
                                                     _status = "dead";
                                                     Running = null;
                                                 } catch (Exception e) {
                                                     A8Console.WriteLine("Coroutine exception: " + e.GetType().Name + " - " + e.Message + "\n" + e.StackTrace);
                                                     _status = "dead";
                                                 }
                                             }));
         //thread.SetApartmentState(ApartmentState.MTA);
         thread.Start();
     }
     else
     {
         if (_status == "dead")
             throw new Exception("Error: coroutine is dead, it cannot be resumed!");
         try {
             if (_status == "suspended")
                 lock (thread)
                 {
                     Monitor.Pulse(thread);
                 }
             else
             {
                 thread.Start();
             }
             _status = "running";
         } catch (Exception ex) {
             _status = "dead";
             throw ex;
         }
     }
     Running = this;
     return true;
 }