Exemple #1
0
        ///////////////////////////////////////////////////////////////////////

        #region Static "Factory" Methods
        internal static IObjectData CreateForSharing(
            Interpreter interpreter1,
            Interpreter interpreter2,
            IObjectData objectData
#if DEBUGGER && DEBUGGER_ARGUMENTS
            , ArgumentList executeArguments
#endif
            )
        {
            IObjectData result = new ObjectData(objectData);

            ///////////////////////////////////////////////////////////////////

            //
            // NOTE: If the interpreters are in different application domains,
            //       it may be impossible to share the type information.
            //
            if (AppDomainOps.IsCross(interpreter1, interpreter2))
            {
                result.Type = null;
            }

            ///////////////////////////////////////////////////////////////////

            //
            // NOTE: This object will be shared between interpreters.  Flag it
            //       as such.
            //
            result.ObjectFlags |= ObjectFlags.SharedObject;

            ///////////////////////////////////////////////////////////////////

            //
            // NOTE: The reference counts for a given opaque object handle are
            //       always per-interpreter.  Therefore, this one will start
            //       with counts of zero.
            //
            result.ReferenceCount          = 0;
            result.TemporaryReferenceCount = 0;

            ///////////////////////////////////////////////////////////////////

#if NATIVE && TCL
            //
            // NOTE: The associated native Tcl interpreter name is also dealt
            //       with on a per-interpreter basis.
            //
            result.InterpName = null;
#endif

            ///////////////////////////////////////////////////////////////////

#if DEBUGGER && DEBUGGER_ARGUMENTS
            //
            // NOTE: This should record the script arguments used when the
            //       object was shared (e.g. via the [interp shareobject]
            //       sub-command).
            //
            result.ExecuteArguments = executeArguments;
#endif

            ///////////////////////////////////////////////////////////////////

            return(result);
        }
Exemple #2
0
            ///////////////////////////////////////////////////////////////////

            #region IExecute Members
            public override ReturnCode Execute(
                Interpreter interpreter,
                IClientData clientData,
                ArgumentList arguments,
                ref Result result
                )
            {
                if (interpreter == null)
                {
                    result = "invalid interpreter";
                    return(ReturnCode.Error);
                }

                if (arguments == null)
                {
                    result = "invalid argument list";
                    return(ReturnCode.Error);
                }

                if (arguments.Count < 2)
                {
                    result = String.Format(
                        "wrong # args: should be \"{0} option ?arg ...?\"",
                        this.Name);

                    return(ReturnCode.Error);
                }

                ReturnCode code;
                string     subCommand = arguments[1];
                bool       tried      = false;

                code = ScriptOps.TryExecuteSubCommandFromEnsemble(
                    interpreter, this, clientData, arguments, true,
                    false, ref subCommand, ref tried, ref result);

                if ((code == ReturnCode.Ok) && !tried)
                {
                    switch (subCommand)
                    {
                    case "about":
                    {
                        if (arguments.Count == 2)
                        {
                            IPlugin plugin = this.Plugin;

                            if (plugin != null)
                            {
                                code = plugin.About(
                                    interpreter, ref result);
                            }
                            else
                            {
                                result = "invalid sub-command plugin";
                                code   = ReturnCode.Error;
                            }
                        }
                        else
                        {
                            result = String.Format(
                                "wrong # args: should be \"{0} {1}\"",
                                this.Name, subCommand);

                            code = ReturnCode.Error;
                        }
                        break;
                    }

                    case "isolated":
                    {
                        if (arguments.Count == 2)
                        {
                            IPlugin plugin = this.Plugin;

                            if (plugin != null)
                            {
                                result = AppDomainOps.IsCross(
                                    interpreter, plugin);

                                code = ReturnCode.Ok;
                            }
                            else
                            {
                                result = "invalid sub-command plugin";
                                code   = ReturnCode.Error;
                            }
                        }
                        else
                        {
                            result = String.Format(
                                "wrong # args: should be \"{0} {1}\"",
                                this.Name, subCommand);

                            code = ReturnCode.Error;
                        }
                        break;
                    }

                    case "options":
                    {
                        if (arguments.Count == 2)
                        {
                            IPlugin plugin = this.Plugin;

                            if (plugin != null)
                            {
                                code = plugin.Options(
                                    interpreter, ref result);
                            }
                            else
                            {
                                result = "invalid sub-command plugin";
                                code   = ReturnCode.Error;
                            }
                        }
                        else
                        {
                            result = String.Format(
                                "wrong # args: should be \"{0} {1}\"",
                                this.Name, subCommand);

                            code = ReturnCode.Error;
                        }
                        break;
                    }

                    default:
                    {
                        ICommand command = this.Command;

                        if (command != null)
                        {
                            //
                            // BUGFIX: Use the entity execution wrapper
                            //         provided by the interpreter so
                            //         that hidden commands are handled
                            //         correctly.
                            //
                            code = interpreter.Execute(
                                command.Name, command, clientData,
                                arguments, ref result);
                        }
                        else
                        {
                            result = ScriptOps.BadSubCommand(
                                interpreter, null, null, subCommand,
                                this, null, null);

                            code = ReturnCode.Error;
                        }
                        break;
                    }
                    }
                }

                return(code);
            }