Exemplo n.º 1
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())));
                        }
                    }
                }));
            }
Exemplo n.º 2
0
        public static T GetCSVariable <T>(this Hashtable hashtable, string varname)
        {
            IOBJ io = ((Variable)hashtable[varname]).value;

            return((T)io.IGetCSValue());
        }