示例#1
0
 /// <summary>
 /// Attempts to resume this generator.
 /// All this does is check that the state is valid (not already running
 /// or dead) and raises exceptions if in an invalid state.
 /// The state is set to <c>State.RUNNING</c> on success.
 /// Returns false if exceptions were thrown, true otherwise.
 /// </summary>
 /// <param name="state"></param>
 /// <returns></returns>
 protected bool TryResume(LayeState state)
 {
     if (this.state == State.RUNNING)
     {
         state.RaiseException("Attempt to resume a running generator.");
         return false;
     }
     if (this.state == State.DEAD)
     {
         state.RaiseException("Attempt to resume a dead generator.");
         return false;
     }
     this.state = State.RUNNING;
     return true;
 }
示例#2
0
文件: KitStd.cs 项目: LayeLang/Laye
        private LayeObject Callback__require(LayeState state, LayeObject ths, params LayeObject[] args)
        {
            // Vars we need:
            LayeKit thisKit = null;
            string originalRequirePath = null;

            // Try to get these:
            if (args.Length < 2)
                throw new ArgumentException("args"); // TODO throw an exception in the state.

            thisKit = args[0] as LayeKit;
            originalRequirePath = (args[1] as LayeString)?.value;

            // Check if we succeeded:
            if (thisKit == null || originalRequirePath == null)
                throw new ArgumentException("kit || requirePath"); // TODO throw an exception in the state.

            // Get the name of the kit:

            // Load up the kit, or error if no kit can be found:
            LayeKit kit;
            switch (originalRequirePath)
            {
                case "std": kit = state.std; break;
                default:
                    // Determine the actual path to require:
                    var requirePath = originalRequirePath.Replace('.', '\\') + ".laye";
                    var newRequirePath = Path.Combine(thisKit.fileLocation, requirePath);
                    if (File.Exists(newRequirePath))
                    {
                        // Compile the kit and run it:
                        try
                        {
                            Compile(newRequirePath, null, out kit);
                        }
                        catch (CompilerException e)
                        {
                            e.log.Print();
                            throw e;
                        }
                        kit.Run(state);
                    }
                    else
                    {
                        state.RaiseException("Failed to load kit '{0}'.", originalRequirePath);
                        return NULL;
                    }
                    break;
            }

            // Load that kit into this kits global state:
            thisKit.Use(state, kit, originalRequirePath);

            // This is void.
            return NULL;
        }