コード例 #1
0
ファイル: TestReg.cs プロジェクト: lightszero/cslightcore
        public static void Reg(CSLE.ICLS_Environment env)
        {
            CSEvilTestor.testfunc.CSLEConvert.env = env;
            ////传统的注册方法,只适用于class,不支持注册委托
            //env.RegType(new CSLE.RegHelper_Type(typeof(Debug)));
            //env.RegType(new CSLE.RegHelper_Type(typeof(testfunc.CSLEConvert)));

            //env.RegType(new CSLE.RegHelper_Type(typeof(TestDele)));
            //env.RegType(new CSLE.RegHelper_Type(typeof(Program)));

            //新的注册方法,只适用于class,不支持注册委托
            env.RegType(CSLE.RegHelper_Type.MakeType(typeof(Debug), null));
            env.RegType(CSLE.RegHelper_Type.MakeType(typeof(testfunc.CSLEConvert), null));

            env.RegType(CSLE.RegHelper_Type.MakeType(typeof(TestDele), null));
            env.RegType(CSLE.RegHelper_Type.MakeType(typeof(Program), null));
            //新的注册方法,参数一样的,
            env.RegType(CSLE.RegHelper_Type.MakeType(typeof(MyJson), "MyJson"));
            env.RegType(CSLE.RegHelper_Type.MakeType(typeof(MyJson.JsonNode_ValueNumber), "MyJson.JsonNode_ValueNumber"));
            env.RegType(CSLE.RegHelper_Type.MakeType(typeof(MyJson.IJsonNode), "MyJson.IJsonNode"));
            env.RegType(CSLE.RegHelper_Type.MakeType(typeof(MyJson.JsonNode_ValueString), "MyJson.JsonNode_ValueString"));
            env.RegType(CSLE.RegHelper_Type.MakeType(typeof(MyJson.JsonNode_Object), "MyJson.JsonNode_Object"));
            env.RegType(CSLE.RegHelper_Type.MakeType(typeof(MyJson.JsonNode_Array), "MyJson.JsonNode_Array"));


            //显式区分注册class 和delegate,其实是一码事
            env.RegType(CSLE.RegHelper_Type.MakeType(typeof(MyClass2), "MyClass2"));
            env.RegType(CSLE.RegHelper_Type.MakeType(typeof(Action<MyClass2>), "Action<MyClass2>"));

            env.RegType(CSLE.RegHelper_Type.MakeType(typeof(TestDele.myup), "TestDele.myup"));
            env.RegType(CSLE.RegHelper_Type.MakeType(typeof(TestDele.myup), "TestDele.myup"));
            env.RegType(CSLE.RegHelper_Type.MakeType(typeof(Action<int>), "Action<int>"));
            env.RegType(CSLE.RegHelper_Type.MakeType(typeof(Action<int, string>), "Action<int,string>"));

            //统一用make,不管是什么东西
            env.RegType(CSLE.RegHelper_Type.MakeType(typeof(Action), "Action"));
            env.RegType(CSLE.RegHelper_Type.MakeType(typeof(Color), "Color"));



            env.RegType(CSLE.RegHelper_Type.MakeType(typeof(Color), "Color"));

            env.RegType(CSLE.RegHelper_Type.MakeType(typeof(KeyValuePair<,>), "KeyValuePair"));
            env.RegType(CSLE.RegHelper_Type.MakeType(typeof(HashSet<object>), "HashSet<object>"));

            env.RegType(CSLE.RegHelper_Type.MakeType(typeof(int[]), "int[]"));

            env.RegType(CSLE.RegHelper_Type.MakeType(typeof(config), "config"));
            env.RegType(CSLE.RegHelper_Type.MakeType(typeof(Math), "Math"));

            env.RegType(CSLE.RegHelper_Type.MakeType(typeof(Exception), "Exception"));
            env.RegType(CSLE.RegHelper_Type.MakeType(typeof(NotSupportedException), "NotSupportedException"));
            env.RegType(CSLE.RegHelper_Type.MakeType(typeof(NotImplementedException), "NotImplementedException"));
            env.RegType(CSLE.RegHelper_Type.MakeType(typeof(TestClass), "TestClass"));
            env.RegType(CSLE.RegHelper_Type.MakeType(typeof(StateMgr), "StateMgr"));

        }
コード例 #2
0
 public override void MemberValueSet(CSLE.CLS_Content content, object object_this, string valuename, object value)
 {
     if (valuename == "name")
     {
         ((GameObject)object_this).name = value as string;
         return;
     }
     base.MemberValueSet(content, object_this, valuename, value);
 }
コード例 #3
0
 public override CSLE.CLS_Content.Value StaticCall(CSLE.CLS_Content environment, string function, IList<CSLE.CLS_Content.Value> _params)
 {
     if(function=="Log")
     {
         Debug.Log(_params[0].value as string);
         return CSLE.CLS_Content.Value.Void;
     }
     return base.StaticCall(environment, function, _params);
 }
コード例 #4
0
    public void Reset(CSLE.ICLS_Logger logger)
    {
        if(logger ==null)
        {
            logger =new ScriptLogger(); 

        }
        scriptEnv = new CSLE.CLS_Environment(logger);
        RegTypes();
        projectLoaded = false;
    }
コード例 #5
0
ファイル: TestReg.cs プロジェクト: GraphicGame/CSLightStudio
        public static void Reg(CSLE.ICLS_Environment env)
        {
            env.RegType(new CSLE.RegHelper_Type(typeof(Debug)));

            env.RegType(new CSLE.RegHelper_Type(typeof(TestDele)));
            env.RegType(new CSLE.RegHelper_Type(typeof(Program)));

            env.RegType(new CSLE.RegHelper_DeleAction<int,string>(typeof(Action<int,string>),"Action<int,string>"));
            env.RegType(new CSLE.RegHelper_Type(typeof(MyClass2)));
            env.RegType(new CSLE.RegHelper_DeleAction<MyClass2>(typeof(Action<MyClass2>), "Action<MyClass2>"));

            env.RegType(new CSLE.RegHelper_DeleAction<int>(typeof(Action<int>), "Action<int>"));
            env.RegType(new CSLE.RegHelper_DeleAction(typeof(Action),"Action"));
            env.RegType(new CSLE.RegHelper_DeleAction(typeof(TestDele.myup), "TestDele.myup"));

            env.RegType(new CSLE.RegHelper_Type(typeof(object), "object"));
            //env.RegType(new CSLE.RegHelper_Type(typeof(List<object>), "List<object>"));
            //env.RegType(new CSLE.RegHelper_Type(typeof(Dictionary<int,int>), "Dictionary<int,int>"));
            //env.RegType(new CSLE.RegHelper_Type(typeof(Dictionary<short, Action<int>>), " Dictionary<short, Action<int>> "));
            //env.RegType(new CSLE.RegHelper_Type(typeof(Dictionary<int, Action<int>>), " Dictionary<int, Action<int>> "));


            Type t = Type.GetType("System.Collections.Generic.List`1");
            env.RegType(new CSLE.RegHelper_Type(t, "List"));
            Type t2 = Type.GetType("System.Collections.Generic.Dictionary`2");
            env.RegType(new CSLE.RegHelper_Type(t2, "Dictionary"));
            Type t3 = Type.GetType("System.Collections.Generic.KeyValuePair`2");
            env.RegType(new CSLE.RegHelper_Type(t3, "KeyValuePair"));
            env.RegType(new CSLE.RegHelper_Type(typeof(HashSet<object>), "HashSet<object>"));

            env.RegType(new CSLE.RegHelper_Type(typeof(List<string>), "List<string>"));
            env.RegType(new CSLE.RegHelper_Type(typeof(int[]), "int[]"));

            env.RegType(new CSLE.RegHelper_Type(typeof(List<int>), "List < int>"));
            env.RegType(new CSLE.RegHelper_Type(typeof(List<List<int>>), "List<List<int>>"));
            env.RegType(new CSLE.RegHelper_Type(typeof(List<List<List<double>>>), "List<List<List<double>>>"));
            env.RegType(new CSLE.RegHelper_Type(typeof(List<List<List<int>>>), "List<List<List<int>>>"));

            env.RegType(new CSLE.RegHelper_Type(typeof(config)));
            env.RegType(new CSLE.RegHelper_Type(typeof(Math)));

            env.RegType(new CSLE.RegHelper_Type(typeof(Exception)));
            env.RegType(new CSLE.RegHelper_Type(typeof(NotSupportedException)));
            env.RegType(new CSLE.RegHelper_Type(typeof(NotImplementedException)));
            env.RegType(new CSLE.RegHelper_Type(typeof(TestClass)));
            env.RegType(new CSLE.RegHelper_Type(typeof(StateMgr)));

        }
コード例 #6
0
 public override CSLE.CLS_Content.Value StaticCall(CSLE.CLS_Content content, string function, IList<CSLE.CLS_Content.Value> _params)
 {
     if (function == "Log")//如果是Log函数
     {
         string logformscript = _params[0].value as string;//把第一个参数取出来改改
         if (content.CallType != null)//如果有类型,就有文件名
         {
             logformscript += "(scriptfile:" + content.CallType.filename + ")";
         }
         if(content.stackExpr.Count>0)//脚本堆栈里有东西,就有表达式,有表达式就有行数
         {
             logformscript += "(line:" + content.stackExpr.Peek().lineBegin + ")";
         }
         _params[0].value = logformscript;
     }
     return base.StaticCall(content, function, _params);
 }
コード例 #7
0
        public override CSLE.CLS_Content.Value StaticCall(CSLE.CLS_Content environment, string function, IList<CSLE.CLS_Content.Value> _params)
        {
            switch(function)
            {
                case "Destory":
                    GameObject.Destroy(_params[0].value as UnityEngine.Object);
                    return CSLE.CLS_Content.Value.Void;
                case "DestroyImmediate":
                    GameObject.DestroyImmediate(_params[0].value as UnityEngine.Object);
                    return CSLE.CLS_Content.Value.Void;
                case "Find":
                    {
                        CSLE.CLS_Content.Value v =new CSLE.CLS_Content.Value();
                        v.value=GameObject.Find(_params[0].value as string);
                        v.type = typeof(GameObject);
                        return v;
                    }
            }

            
            return base.StaticCall(environment, function, _params);
        }
コード例 #8
0
ファイル: Form1.cs プロジェクト: lightszero/cslightcore
 private void __Run(string code, CSLE.CLS_Content content)
 {
     var tokens = env.tokenParser.Parse(code);
     var expr = env.Expr_CompilerToken(tokens);
     env.Expr_Execute(expr, content);
 }
コード例 #9
0
        System.Reflection.MethodInfo GetMethodSlow(CSLE.CLS_Content content, bool bStatic, string funcname, IList<Type> types, IList<object> _params)
        {
            List<object> myparams = new List<object>(_params);
            if (slowCache == null)
            {
                System.Reflection.MethodInfo[] ms = this.type.GetMethods();
                slowCache = new Dictionary<string, IList<System.Reflection.MethodInfo>>();
                foreach (var m in ms)
                {
                    string name = m.IsStatic ? "s=" + m.Name : m.Name;
                    if (slowCache.ContainsKey(name) == false)
                    {
                        slowCache[name] = new List<System.Reflection.MethodInfo>();
                    }
                    slowCache[name].Add(m);
                }
            }
            IList<System.Reflection.MethodInfo> minfo = null;

            if (slowCache.TryGetValue(bStatic ? "s=" + funcname : funcname, out minfo) == false)
                return null;

            foreach (var m in minfo)
            {
                bool match = true;
                var pp = m.GetParameters();
                if (pp.Length < types.Count)//参数多出来,不匹配
                {
                    match = false;
                    continue;
                }
                for (int i = 0; i < pp.Length; i++)
                {
                    if (i >= types.Count)//参数多出来
                    {
                        if (!pp[i].IsOptional)
                        {

                            match = false;
                            break;
                        }
                        else
                        {
                            myparams.Add(pp[i].DefaultValue);
                            continue;
                        }
                    }
                    else
                    {
                        if (pp[i].ParameterType == types[i]) continue;

                        try
                        {
                            if (types[i] == null && !pp[i].ParameterType.IsValueType)
                            {
                                continue;
                            }
                            myparams[i] = content.environment.GetType(types[i]).ConvertTo(content, _params[i], pp[i].ParameterType);
                            if (myparams[i] == null)
                            {
                                match = false;
                                break;
                            }
                        }
                        catch
                        {
                            match = false;
                            break;
                        }
                    }
                    if (match)
                        break;
                }
                if (!match)
                {
                    continue;
                }
                else
                {
                    for (int i = 0; i < myparams.Count; i++)
                    {
                        if (i < _params.Count)
                        {
                            _params[i] = myparams[i];
                        }
                        else
                        {
                            _params.Add(myparams[i]);
                        }
                    }
                    return m;
                }

            }

            if (minfo.Count == 1)
                return minfo[0];

            return null;

        }
コード例 #10
0
ファイル: Form1.cs プロジェクト: lightszero/cslightcore
        void ShowExpNode(TreeNode node, CSLE.ICLS_Expression value)
        {
            if (value == null)
            {
                node.Text = "null";

            }
            else
            {
                node.Text = value.ToString();
                CSLE.ICLS_Expression exp = value as CSLE.ICLS_Expression;
                if (exp != null && exp.listParam != null)
                    foreach (var v in exp.listParam)
                    {
                        TreeNode subnode = new TreeNode();
                        ShowExpNode(subnode, v);
                        node.Nodes.Add(subnode);
                    }
            }
        }
コード例 #11
0
ファイル: Form1.cs プロジェクト: lightszero/cslightcore
        void ShowExp(CSLE.ICLS_Expression value)
        {
            treeViewExp.Nodes.Clear();
            if (value == null) return;
            TreeNode node = new TreeNode();
            ShowExpNode(node, value);
            treeViewExp.Nodes.Add(node);

            treeViewExp.ExpandAll();
        }
コード例 #12
0
        public override CSLE.CLS_Content.Value MemberValueGet(CSLE.CLS_Content environment, object object_this, string valuename)
        {
            if (valuename == "transform")
            {
                CSLE.CLS_Content.Value v = new CSLE.CLS_Content.Value();
                v.value=                ((GameObject)object_this).transform;
                v.type =typeof(Transform);

                return v;
            }
            return base.MemberValueGet(environment, object_this, valuename);
        }
コード例 #13
0
 public override CSLE.CLS_Content.Value StaticValueGet(CSLE.CLS_Content environment, string valuename)
 {
     if(valuename=="one")
     {
         CSLE.CLS_Content.Value v = new CSLE.CLS_Content.Value();
         v.value = Vector3.one;
         v.type = typeof(Vector3);
         return v;
     }
     return base.StaticValueGet(environment, valuename);
 }
コード例 #14
0
        public override void MemberValueSet(CSLE.CLS_Content content, object object_this, string valuename, object value)
        {
            switch(valuename)
            {
                case "localScale":
                    ((Transform)object_this).localScale = (Vector3)value;
                    return;
                case "parent":
                    ((Transform)object_this).parent = value as Transform;
                return;
            }

            base.MemberValueSet(content, object_this, valuename, value);
        }