Ejemplo n.º 1
0
            public override object Run(Hashtable xc)
            {
                var list = xc.GetCSVariable <Glist>("params");

                Gdebug.WriteLine(list.Count.ToString());
                if (list.Count == 1)
                {
                    string s1 = xc.GetCSVariable <object>("this").ToString();
                    string s2 = list[0].value.ToString();
                    return(new Variable(s1.LastIndexOf(s2)));
                }
                else if (list.Count == 2)
                {
                    string s1 = xc.GetCSVariable <object>("this").ToString();
                    string s2 = list[0].value.ToString();
                    int    i  = Convert.ToInt32(list[1].value);
                    return(new Variable(s1.LastIndexOf(s2, i)));
                }
                else
                {
                    throw new Exceptions.RunException(Exceptions.EXID.参数错误, "参数错误");
                }
            }
Ejemplo n.º 2
0
            public System_Lib()
            {
                myThing.Add("GetType", new Variable(new System_Function_Gettype()));
                myThing.Add("Exit", new Variable(new System_Function_Exit()));
                myThing.Add("Const", new Variable(new System_Function_Const()));
                myThing.Add("const", new Variable(new System_Function_Const()));
                myThing.Add("GetInterpreterVersion", new Variable(new DFunction {
                    IInformation = "get the version of interpreter", dRun = (xc) => new Variable(GIInfo.GIVersion)
                }));
                myThing.Add("GetInterpreter", new Variable(new DFunction {
                    IInformation = "get the name of interpreter", dRun = (xc) => new Variable("GI")
                }));
                myThing.Add("GetPlatform", new Variable(new DFunction {
                    IInformation = "get the paltform", dRun = (xc) => new Variable(GIInfo.Platform)
                }));
                myThing.Add("GetFolderPath", new Variable(new System_Function_GetFolderPath()));
                #region 获取时间
                myThing.Add("GetTime", new Variable(new DFunction
                {
                    IInformation = @"get the time.
[val(string)]:
y or year
m or month
d or day
h or hour
min or minute
s or second
date
time",
                    str_xcname   = "val",
                    dRun         = (xc) =>
                    {
                        DateTime dateTime = DateTime.Now;
                        string val        = Variable.GetTrueVariable <object>(xc, "val").ToString().ToLower();
                        switch (val)
                        {
                        case "y":
                        case "year":
                            return(new Variable(dateTime.Year));


                        case "m":
                        case "month":
                            return(new Variable(dateTime.Month));

                        case "d":

                        case "day":
                            return(new Variable(dateTime.Day));

                        case "h":

                        case "hour":
                            return(new Variable(dateTime.Hour));

                        case "min":

                        case "minute":
                            return(new Variable(dateTime.Minute));

                        case "s":

                        case "second":
                            return(new Variable(dateTime.Second));

                        case "date":
                            return(new Variable(dateTime.ToLongDateString()));

                        case "time":
                            return(new Variable(dateTime.ToLongTimeString()));

                        default:
                            return(null);
                        }
                    }
                }));
                #endregion
                myThing.Add("Debug", new Variable(new DFunction {
                    IInformation = "output when debugging", str_xcname = "str", dRun = (xc) => { Gdebug.WriteLine(xc.GetVariable <object>("str").ToString()); return(new Variable(0)); }
                }));
                myThing.Add("Help", new Variable(new DFunction
                {
                    IInformation = "return the help of \'in\'",
                    str_xcname   = "in",
                    dRun         = (xc) =>
                    {
                        object o = xc.GetCSVariable <object>("in");
                        if (o is IFunction)
                        {
                            var function = o as IFunction;
                            return(new Variable($"function \n param : {function.Istr_xcname} \n is a reffun : {function.Iisreffunction} \n information : {function.IInformation}"));
                        }
                        return(new Variable(0));
                    }
                }));
                myThing.Add("async", new Variable(new Asyncfunc()));
                myThing.Add("await", new Variable(new System_Function_Await()));
                myThing.Add("wait", new Variable(new System_Function_Wait()));
                myThing.Add("Shell", new Variable(new System_Function_Shell()));
                myThing.Add("GetAppPath", new Variable(new System_Function_GetAppPath()));
                myThing.Add("GetResourcesPath", new Variable(new System_Function_GetResourcesPath()));
                myThing.Add("ObjEqual", new Variable(new DFunction
                {
                    IInformation = "compare the object",
                    str_xcname   = "o1,o2",
                    dRun         = (xc) =>
                    {
                        IOBJ o1 = xc.GetVariable <IOBJ>("o1"), o2 = xc.GetVariable <IOBJ>("o2");
                        if (o1.IGetCSValue() == null)
                        {
                            return(new Variable(o1.Equals(o2)));
                        }
                        else
                        {
                            return(new Variable(o1.IGetCSValue().Equals(o2.IGetCSValue())));
                        }
                    }
                }));
            }
Ejemplo n.º 3
0
        static void Getfunandvar(XmlDocument codes)
        {
            if (!codes.HasChildNodes)
            {
                Gdebug.WriteLine("bugging");
            }
            XmlNode root = null;

            foreach (XmlNode i in codes.ChildNodes)
            {
                if (i.Name == "code")
                {
                    root = i;
                }
            }
            int minversion = Convert.ToInt32(root.Attributes["minversion"].InnerText);

            if (minversion > GIInfo.GIVersion)
            {
                Gdebug.ThrowWrong("version not support");
            }
            foreach (XmlNode i in root.ChildNodes)
            {
                var    code = i;
                string name = code.Name;
                if (name == "lib")
                {
                    string libname = code.GetAttribute("name");
                    if (!libs.ContainsKey(libname))
                    {
                        libs.Add(libname, new UserLib());
                    }
                    foreach (XmlNode libcontent in code.ChildNodes)
                    {
                        if (libcontent.Name == "get")
                        {
                            libs[libname].waittoadd.Add(libcontent.GetAttribute("value"));
                        }
                        else if (libcontent.Name == "var")
                        {
                            libs[libname].myThing.Add(libcontent.GetAttribute("value"), new Variable(0));
                        }
                        else if (libcontent.Name == "cls")
                        {
                            var            x_cls          = libcontent;
                            GClassTemplate gClassTemplate = new GClassTemplate(x_cls.GetAttribute("name"), libname);
                            var            parent         = x_cls.GetAttribute("parent");
                            var            iscvf          = x_cls.GetAttribute("cvf");

                            gClassTemplate.iscvf = Convert.ToBoolean(iscvf);
                            gClassTemplate.LoadContent(x_cls.ChildNodes);
                            gClassTemplate.parentclassname = parent;
                            libs[libname].myThing.Add(libcontent.GetAttribute("name"), new Variable(gClassTemplate));
                        }
                        else if (libcontent.Name == "deffun")
                        {
                            Function.New_User_Function new_User_Function = new Function.New_User_Function(libcontent, libname);
                            libs[libname].myThing.Add(libcontent.GetAttribute("funname"), new Variable(new_User_Function));
                        }
                        else
                        {
                            throw new Exceptions.RunException(Exceptions.EXID.未知);
                        }
                    }
                }
                else
                {
                    throw new Exceptions.RunException(Exceptions.EXID.未知);
                }
            }
        }