Exemple #1
0
        static void Main(string[] args)
        {
            FDelegate fd = Square;

            fd += drawTrian;
            fd(ConsoleColor.Red, 10, '*');
        }
 protected void CallMethod(Protocal protocal, ByteBuffer buffer)
 {
     if (func == null)
     {
         func = LuaEnvSingleton.Instance.Global.GetInPath <FDelegate>("Network.OnReceiveMessageQueue");
     }
     func(protocal, buffer);
 }
Exemple #3
0
        // Use this for initialization
        void Start()
        {
            luaenv = new LuaEnv();
            luaenv.DoString(script);

            Debug.Log("_G.a = " + luaenv.Global.Get <int>("a"));
            Debug.Log("_G.b = " + luaenv.Global.Get <string>("b"));
            Debug.Log("_G.c = " + luaenv.Global.Get <bool>("c"));


            DClass d = luaenv.Global.Get <DClass>("d");//映射到有对应字段的class,by value

            Debug.Log("_G.d = {f1=" + d.f1 + ", f2=" + d.f2 + "}");

            Dictionary <string, double> d1 = luaenv.Global.Get <Dictionary <string, double> >("d");//映射到Dictionary<string, double>,by value

            Debug.Log("_G.d = {f1=" + d1["f1"] + ", f2=" + d1["f2"] + "}, d.Count=" + d1.Count);

            List <double> d2 = luaenv.Global.Get <List <double> >("d"); //映射到List<double>,by value

            Debug.Log("_G.d.len = " + d2.Count);

            ItfD d3 = luaenv.Global.Get <ItfD>("d"); //映射到interface实例,by ref,这个要求interface加到生成列表,否则会返回null,建议用法

            d3.f2 = 1000;
            Debug.Log("_G.d = {f1=" + d3.f1 + ", f2=" + d3.f2 + "}");
            Debug.Log("_G.d:add(1, 2)=" + d3.add(1, 2));
            Debug.Log("---------------------------------------------");

            LuaTable d4 = luaenv.Global.Get <LuaTable>("d");//映射到LuaTable,by ref

            Debug.Log("_G.d = {f1=" + d4.Get <int>("f1") + ", f2=" + d4.Get <int>("f2") + "}");

            Debug.Log("---------------------------------------------");

            Action e = luaenv.Global.Get <Action>("e");//映射到一个delgate,要求delegate加到生成列表,否则返回null,建议用法

            e();
            Debug.Log("---------------------------------------------");

            FDelegate f = luaenv.Global.Get <FDelegate>("f");
            DClass    d_ret;
            int       f_ret = f(100, "John", out d_ret);//lua的多返回值映射:从左往右映射到c#的输出参数,输出参数包括返回值,out参数,ref参数

            Debug.Log("ret.d = {f1=" + d_ret.f1 + ", f2=" + d_ret.f2 + "}, ret=" + f_ret);
            Debug.Log("---------------------------------------------");

            /*
             * GetE ret_e = luaenv.Global.Get<GetE>("ret_e");//delegate可以返回更复杂的类型,甚至是另外一个delegate
             * e = ret_e();
             * e();
             * Debug.Log("---------------------------------------------");
             * LuaFunction d_e = luaenv.Global.Get<LuaFunction>("e");
             * d_e.Call();
             *
             */
        }
Exemple #4
0
    private void Start()
    {
        luaEnv = new LuaEnv();
        luaEnv.DoString(script.text);
        print("_G.a = " + luaEnv.Global.Get <int>("a"));
        print("_G.b = " + luaEnv.Global.Get <string>("b"));
        print("_G.c = " + luaEnv.Global.Get <bool>("c"));

        DClass d = luaEnv.Global.Get <DClass>("d");

        print("_G.d = {f1 =" + d.f1 + " ,f2=" + d.f2 + "}");

        Dictionary <string, double> d1 = luaEnv.Global.Get <Dictionary <string, double> >("d");

        print("_G.d = {f1 =" + d1["f1"] + " ,f2=" + d1["f2"] + "  ,count " + d1.Count + " }");

        List <double> d2 = luaEnv.Global.Get <List <double> >("d");

        print("_G.d.len " + d2.Count);

        ItfD d3 = luaEnv.Global.Get <ItfD>("d");

        d3.f2 = 1000;
        print("_G.d = {f1 =" + d3.f1 + " ,f2=" + d3.f2 + "}");
        print("_G.d : add " + d3.add(d3.f1, d3.f2));

        LuaTable table = luaEnv.Global.Get <LuaTable>("d");

        Debug.Log("_G.d = {f1=" + table.Get <int>("f1") + ", f2=" + table.Get <int>("f2") + "}");

        Action e = luaEnv.Global.Get <Action>("e");//映射到一个delgate,要求delegate加到生成列表,否则返回null,建议用法

        e();

        FDelegate f = luaEnv.Global.Get <FDelegate>("f");
        DClass    d_ret;
        // 多值返回,可用out接收多余的参数
        // 输出 a 100 b John
        int f_ret = f(100, "John", out d_ret);//lua的多返回值映射:从左往右映射到c#的输出参数,输出参数包括返回值,out参数,ref参数

        // table只含有常量f1,所以f2赋值为0
        Debug.Log("ret.d = {f1=" + d_ret.f1 + ", f2=" + d_ret.f2 + "}, ret=" + f_ret);

        GetE ret_e = luaEnv.Global.Get <GetE>("ret_e");//delegate可以返回更复杂的类型,甚至是另外一个delegate

        e = ret_e();
        e();


        // 映射到 LuaFunction
        LuaFunction d_e = luaEnv.Global.Get <LuaFunction>("e");

        // Call 函数可以传任意类型,任意个数的参数
        d_e.Call();
    }
Exemple #5
0
        void DrawGraphic(PaintEventArgs e, FDelegate f, Color color)
        {
            List <PointF> points = new List <PointF>();

            for (double i = -2 * Math.PI; i <= 2 * Math.PI; i += 0.1)
            {
                float x = (float)i * 50 + Width / 2;
                float y = -(float)f(i) * 50 + Width / 2;
                points.Add(new PointF {
                    X = x, Y = y
                });
            }

            e.Graphics.DrawCurve(new Pen(color, 1), points.ToArray());
        }
Exemple #6
0
 void OnDestroy()
 {
     if (luaOnDestroy != null)
     {
         luaOnDestroy();
     }
     luaEventDesktop = null;
     luaOnDestroy    = null;
     luaOnDisable    = null;
     luaLateUpdate   = null;
     luaFixedUpdate  = null;
     luaUpdate       = null;
     luaOnEnable     = null;
     luaStart        = null;
     scriptEnv.Dispose();
     gameObjects = null;
 }
Exemple #7
0
        //接收到消息
        void OnReceivedMessage(MemoryStream ms)
        {
            BinaryReader r = new BinaryReader(ms);

            byte[] message = r.ReadBytes((int)(ms.Length - ms.Position));
            //for (int i = 0; i < message.Length; i++)
            //    Debug.LogWarning((int)message[i]);
            ByteBuffer buffer = new ByteBuffer(message);

            if (func == null)
            {
                func = LuaEnvSingleton.Instance.Global.GetInPath <FDelegate>("Network.OnReceived");
            }
            Debug.LogWarning("接收到数据--->>>");
            //Debug.LogWarning(func);
            func(buffer);
            buffer.Close();
        }
Exemple #8
0
        //接收到消息
        void OnReceivedMessage(MemoryStream ms)
        {
            Debug.LogError("接收到数据--->>>");

            BinaryReader r = new BinaryReader(ms);

            byte[]     message = r.ReadBytes((int)(ms.Length - ms.Position));
            ByteBuffer buffer  = new ByteBuffer(message);

            const string command = @"
                Network = require 'Network'
            ";

            LuaEnvSingleton.Instance.DoString(command);
            FDelegate func = LuaEnvSingleton.Instance.Global.Get <FDelegate>("Network.OnReceived");

            func(buffer);
        }
Exemple #9
0
    // Use this for initialization
    void Start()
    {
        luaenv = new LuaEnv();
        luaenv.DoString(script);

        Debug.Log("_G.a = " + luaenv.Global.Get <int>("a"));
        Debug.Log("_G.b = " + luaenv.Global.Get <string>("b"));
        Debug.Log("_G.c = " + luaenv.Global.Get <bool>("c"));


        DClass d = luaenv.Global.Get <DClass>("d");//映射到有对应字段的class,by value

        Debug.Log("_G.d = {f1=" + d.f1 + ", f2=" + d.f2 + "}");

        //映射到Dictionary<string, double>,by value
        Dictionary <string, double> d1 = luaenv.Global.Get <Dictionary <string, double> >("d");

        Debug.Log("_G.d = {f1=" + d1["f1"] + ", f2=" + d1["f2"] + "}, d.Count=" + d1.Count);
        //只能映射出table中键值对<string, double>的属性,即上述的f1=12,f2=34

        //映射到List<double>,by value
        List <double> d2 = luaenv.Global.Get <List <double> >("d");

        Debug.Log("_G.d.len = " + d2.Count);
        //只能映射出table中类型为number的属性,即上述的1,2,3

        //映射到interface实例,by ref,这个要求interface加到生成列表即添加[CSharpCallLua]标签,否则会返回null,建议用法
        ItfD d3 = luaenv.Global.Get <ItfD>("d");

        d3.f2 = 1000;
        Debug.Log("_G.d = {f1=" + d3.f1 + ", f2=" + d3.f2 + "}");
        Debug.Log("_G.d:add(1, 2)=" + d3.add(1, 2));

        LuaTable d4 = luaenv.Global.Get <LuaTable>("d");//映射到LuaTable,by ref

        Debug.Log("_G.d = {f1=" + d4.Get <int>("f1") + ", f2=" + d4.Get <int>("f2") + "}");


        //映射到一个delgate,要求delegate加到生成列表,否则返回null,建议用法
        Action e = luaenv.Global.Get <Action>("e");

        e();

        //带参数的f函数映射到Action中,可以映射成功,但是函数体内参数值传递进来为nil
        Action fA = luaenv.Global.Get <Action>("f");

        fA();

        FDelegate f = luaenv.Global.Get <FDelegate>("f");
        DClass    d_ret;
        int       f_ret = f(100, "John", out d_ret);//lua的多返回值映射:从左往右映射到c#的输出参数,输出参数包括返回值,out参数,ref参数

        Debug.Log("ret.d = {f1=" + d_ret.f1 + ", f2=" + d_ret.f2 + "}, ret=" + f_ret);

        GetE   ret_e = luaenv.Global.Get <GetE>("ret_e");//delegate可以返回更复杂的类型,甚至是另外一个delegate
        Action e2    = ret_e();

        e2();

        LuaFunction d_e = luaenv.Global.Get <LuaFunction>("e");

        d_e.Call();
    }
Exemple #10
0
 public void ComplexFunc2(LuaFunction fun, FDelegate func1)
 {
     ///这里就不加判断了
     fun.Call(1);
     func1(1);
 }