Esempio n. 1
0
    private void Start()
    {
        LuaScriptMgr luaScriptMgr = new LuaScriptMgr();

        luaScriptMgr.Start();
        luaScriptMgr.DoString(this.script);
    }
Esempio n. 2
0
    private bool LoadJValue(string sLuaFileName)
    {
        Util.ClearMemory();
        string       sLuaCode = File.ReadAllText(sLuaFileName);
        LuaScriptMgr mgr      = new LuaScriptMgr();

        mgr.DoString(sLuaCode);
        LuaFunction func = mgr.GetLuaFunction("GetJValueByLatticeIndex");

        if (null == func)
        {
            ShowErrorMessage("GetJValueByLatticeIndex function cannot been found.");
            mgr.Destroy();
            return(false);
        }

        for (int x = 0; x < m_iResolution; ++x)
        {
            for (int y = 0; y < m_iResolution; ++y)
            {
                object[] r = func.Call2(x, y);
                if (1 != r.Length || !(r[0] is double))
                {
                    ShowErrorMessage("Call function GetJValueByLatticeIndex failed, function may have error.");
                    mgr.Destroy();
                    return(false);
                }
                _jvalues[y * m_iResolution + x] = (float)(double)r[0];
            }
        }
        mgr.Destroy();
        SetJTexture(_jvalues);
        return(true);
    }
Esempio n. 3
0
    //非反射调用
    void Start()
    {
        LuaScriptMgr lua = new LuaScriptMgr();

        lua.Start();
        lua.DoString(script);
    }
Esempio n. 4
0
	//反射调用
	void Start () {
        //LuaState lua = new LuaState();
        //lua.DoString(script);
        LuaScriptMgr lua = new LuaScriptMgr();
        lua.Start();
        lua.DoString(script);
    }
	// Use this for initialization
	void Start () {
        LuaScriptMgr mgr = new LuaScriptMgr();
        mgr.Start();
        mgr.DoString(script);

        LuaFunction func = mgr.GetLuaFunction("TestClick");
        func.Call(button.gameObject);
	}
Esempio n. 6
0
	// Use this for initialization
	void Start () {
        LuaScriptMgr mgr = new LuaScriptMgr();
        mgr.Start();
        mgr.DoString(script);

        LuaFunction f = mgr.GetLuaFunction("testDelegate");
        f.Call(gameObject);     //将自己对象传给lua
	}
Esempio n. 7
0
    private bool LoadJXValue(string sLuaFileName)
    {
        Util.ClearMemory();
        string       sLuaCode = File.ReadAllText(sLuaFileName);
        LuaScriptMgr mgr      = new LuaScriptMgr();

        mgr.DoString(sLuaCode);

        LuaFunction func1 = mgr.GetLuaFunction("GetJxPeroidLength");

        if (null == func1)
        {
            ShowErrorMessage("GetJxPeroidLength function cannot been found.");
            mgr.Destroy();
            return(false);
        }

        object[] r1 = func1.Call();
        if (1 != r1.Length || !(r1[0] is double))
        {
            ShowErrorMessage("GetJxPeroidLength function should return a number.");
            mgr.Destroy();
            return(false);
        }

        //The 2.0f multipler is For Runge–Kutta, we need t + dt and t + 0.5 dt both!
        int iStepLength = Mathf.RoundToInt((float)(double)r1[0] * 2.0f);

        float[] jxvalue = null;
        if (iStepLength > 0)
        {
            LuaFunction func2 = mgr.GetLuaFunction("GetJxValueInPeroid");
            if (null == func2)
            {
                ShowErrorMessage("GetJxValueInPeroid function cannot been found.");
                mgr.Destroy();
                return(false);
            }

            jxvalue = new float[iStepLength];
            for (int y = 0; y < iStepLength; ++y)
            {
                object[] r2 = func2.Call(y / (float)iStepLength);
                if (1 != r2.Length || !(r2[0] is double))
                {
                    ShowErrorMessage("GetJxValueInPeroid function should return a number.");
                    mgr.Destroy();
                    return(false);
                }

                jxvalue[y] = (float)(double)r2[0];
            }
        }
        mgr.Destroy();
        SetJXTexture(iStepLength, jxvalue);
        return(true);
    }
Esempio n. 8
0
 // Use this for initialization
 void Start()
 {
     //        LuaState l = new LuaState();
     string str = "print('hello world 世界')";
     //        l.DoString(str);
     LuaScriptMgr l = new LuaScriptMgr();
     l.Start ();
     l.DoString (str);
 }
Esempio n. 9
0
        private void DoScript(FormulaConfig config)
        {
//			Debug.Log(config);
            if (!string.IsNullOrEmpty(config.script))
            {
//				lua.DoString(config.script);
                luaManager.DoString(config.script);
            }
        }
Esempio n. 10
0
	void Awake () 
    {
        lua  = new LuaScriptMgr();
        lua.Start();
        lua.DoString(script);        
        LuaFunction f = lua.GetLuaFunction("myFunc");
        f.Call();
        f.Release();
	}
Esempio n. 11
0
    static int DoString(IntPtr L)
    {
        LuaScriptMgr.CheckArgsCount(L, 2);
        LuaScriptMgr obj  = LuaScriptMgr.GetNetObject <LuaScriptMgr>(L, 1);
        string       arg0 = LuaScriptMgr.GetLuaString(L, 2);

        object[] o = obj.DoString(arg0);
        LuaScriptMgr.PushArray(L, o);
        return(1);
    }
Esempio n. 12
0
 void Start()
 {
     LuaScriptMgr lua = new LuaScriptMgr();
     lua.Start();
     lua.DoString(script);
     LuaFunction f = lua.GetLuaFunction("TestArray");
     //转换一下类型,避免可变参数拆成多个参数传递
     f.Call((object)objs);
     f.Release();
 }
Esempio n. 13
0
    void Awake()
    {
        lua = new LuaScriptMgr();
        lua.Start();
        lua.DoString(script);
        LuaFunction f = lua.GetLuaFunction("myFunc");

        f.Call();
        f.Release();
    }
Esempio n. 14
0
    // Use this for initialization
    void Start()
    {
        LuaScriptMgr mgr = new LuaScriptMgr();

        mgr.Start();
        mgr.DoString(script);

        LuaFunction f = mgr.GetLuaFunction("testDelegate");

        f.Call(gameObject);     //将自己对象传给lua
    }
    // Use this for initialization
    void Start()
    {
        LuaScriptMgr mgr = new LuaScriptMgr();

        mgr.Start();
        mgr.DoString(script);

        LuaFunction func = mgr.GetLuaFunction("TestClick");

        func.Call(button);
    }
Esempio n. 16
0
 // Use this for initialization
 void Start()
 {
     if (isUseLua)
     {
         mgr = new LuaScriptMgr();
         mgr.Start();
         LuaState l         = mgr.lua;
         string   readToEnd = ConfigFileReader.FilePath(Path.Combine(Application.streamingAssetsPath, "LuaFile/LuaManager.lua"));
         mgr.DoString(readToEnd);
     }
 }
Esempio n. 17
0
    IEnumerator DelayCloseLua()
    {
        yield return(new WaitForEndOfFrame());

        mgr.Destroy();
        mgr = new LuaScriptMgr();
        mgr.Start();
        LuaState l         = mgr.lua;
        string   readToEnd = ConfigFileReader.FilePath(Path.Combine(Application.streamingAssetsPath, "LuaFile/LuaManager.lua"));

        mgr.DoString(readToEnd);
    }
Esempio n. 18
0
    private void Start()
    {
        LuaScriptMgr luaScriptMgr = new LuaScriptMgr();

        luaScriptMgr.DoString(this.script);
        this.func = luaScriptMgr.GetLuaFunction("luaFunc");
        object[] array = this.func.Call(123456.0);
        MonoBehaviour.print(array[0]);
        int num = this.CallFunc();

        MonoBehaviour.print(num);
    }
Esempio n. 19
0
    private void Start()
    {
        LuaScriptMgr luaScriptMgr = new LuaScriptMgr();

        luaScriptMgr.Start();
        luaScriptMgr.DoString("\r\n        local func1 = function() print('测试委托1'); end\r\n        local func2 = function(gameObj) print('测试委托2:>'..gameObj.name); end        \r\n        \r\n        function testDelegate(go) \r\n            local ev = go:AddComponent(TestDelegateListener.GetClassType());\r\n        \r\n            ---直接赋值模式---\r\n            ev.onClick = func1;\r\n\r\n            ---C#的加减模式---\r\n            local delegate = DelegateFactory.TestLuaDelegate_VoidDelegate(func2);\r\n            ev.onEvClick = ev.onEvClick + delegate;\r\n            --ev.onEvClick = ev.onEvClick - delegate;\r\n        end\r\n    ");
        LuaFunction luaFunction = luaScriptMgr.GetLuaFunction("testDelegate");

        luaFunction.Call(new object[]
        {
            base.gameObject
        });
    }
Esempio n. 20
0
    private void Start()
    {
        LuaScriptMgr luaScriptMgr = new LuaScriptMgr();

        luaScriptMgr.Start();
        luaScriptMgr.DoString(this.script);
        LuaFunction luaFunction = luaScriptMgr.GetLuaFunction("TestClick");

        luaFunction.Call(new object[]
        {
            this.button
        });
    }
Esempio n. 21
0
    // Use this for initialization
    void Start()
    {
        LuaScriptMgr mgr = new LuaScriptMgr();

        mgr.Start();
        mgr.DoString(script1);

        button = transform.Find("Button").GetComponent <Button>();

        LuaFunction func = mgr.GetLuaFunction("TestClick");

        func.Call(button);
    }
Esempio n. 22
0
    //反射已经无法区分这些重载函数了
    void Start()
    {
        LuaScriptMgr mgr = new LuaScriptMgr();

        mgr.Start();
        TestOverrideWrap.Register(mgr.GetL());
        TestOverride_SpaceWrap.Register(mgr.GetL());
        mgr.DoString(script);

        TestOverride to   = new TestOverride();
        LuaFunction  func = mgr.GetLuaFunction("Test");

        func.Call(to);
    }
Esempio n. 23
0
    void Start()
    {
        LuaScriptMgr lua = new LuaScriptMgr();
        lua.Start();
        lua.DoString(script);
        LuaFunction f = lua.GetLuaFunction("TestArray");
        //转换一下类型,避免可变参数拆成多个参数传递
        object[] rts = f.Call((object)objs);
        f.Release();

        for (int i = 0; i < objs.Length; i++)
        {
            Debug.Log(rts[i].ToString());
        }
    }
Esempio n. 24
0
    void Start()
    {
        //Screen.SetResolution(800, 480, true);

        TextAsset asset = Resources.Load <TextAsset>("perf");

        Profiler.BeginSample("init");
        l = new LuaScriptMgr();
        l.Start();
        l.DoString(asset.ToString());
        Profiler.EndSample();
        l.GetLuaFunction("main").Call();

        Application.logMessageReceived += this.log;
    }
Esempio n. 25
0
 // Use this for initialization
 void Awake()
 {
     mgr = new LuaScriptMgr();
     luaCache = new Dictionary<string, LuaTable>();
     luaScript = FileHelper.ReadLuaScriptFile(Define.LuaScriptPathRoot + "/" + "main.lua");
     Debug.Log(luaScript);
     object[] ret = mgr.DoString(luaScript);
     LuaTable mainTable = ret[0] as LuaTable;
     awakeFun = mainTable.RawGetFunc("awake");
     startFun = mainTable.RawGetFunc("start");
     updateFun = mainTable.RawGetFunc("update");
     lateUpdateFun = mainTable.RawGetFunc("lateUpdate");
     LuaTable conf = mainTable.rawget("conf") as LuaTable;
     string[] confStr = conf.ToArray<string>();
     for (int i = 0; i < confStr.Length; i++)
     {
         Debug.Log(Define.LuaScriptPathRoot + "/" + confStr[i] + ".lua");
         luaScript = FileHelper.ReadLuaScriptFile(Define.LuaScriptPathRoot + "/" + confStr[i] + ".lua");
         LuaTable retTable = mgr.DoString(luaScript)[0] as LuaTable;
         luaCache.Add(confStr[i], retTable);
     }
         if (awakeFun != null)
             awakeFun.Call();
 }
	// Use this for initialization
	void Start () {
        LuaScriptMgr mgr = new LuaScriptMgr();
        
        mgr.DoString(script);

        // Get the function object
        func = mgr.GetLuaFunction("luaFunc");

        //有gc alloc
        object[] r = func.Call(123456);        
        print(r[0]);

        // no gc alloc
        int num = CallFunc();
        print(num);
	}
Esempio n. 27
0
    private void Start()
    {
        LuaScriptMgr luaScriptMgr = new LuaScriptMgr();

        luaScriptMgr.Start();
        TestOverrideWrap.Register(luaScriptMgr.GetL());
        TestOverride_SpaceWrap.Register(luaScriptMgr.GetL());
        luaScriptMgr.DoString(this.script);
        TestOverride testOverride = new TestOverride();
        LuaFunction  luaFunction  = luaScriptMgr.GetLuaFunction("Test");

        luaFunction.Call(new object[]
        {
            testOverride
        });
    }
Esempio n. 28
0
    private void Start()
    {
        LuaScriptMgr luaScriptMgr = new LuaScriptMgr();

        luaScriptMgr.Start();
        TestProtolWrap.Register(luaScriptMgr.GetL());
        luaScriptMgr.DoFile("3rd/pblua/person_pb.lua");
        luaScriptMgr.DoString(this.script);
        LuaFunction luaFunction = luaScriptMgr.GetLuaFunction("encoder");

        luaFunction.Call();
        luaFunction.Release();
        luaFunction = luaScriptMgr.GetLuaFunction("decoder");
        luaFunction.Call();
        luaFunction.Release();
    }
Esempio n. 29
0
    //实际应用如Socket.Send(LuaStringBuffer lsb)函数(功能发送lsb.buffer) , 在lua中调用Socket.Send(pb_data)
    //读取协议 Socket.PeekMsgPacket() {return MsgPacket}; lua 中,取协议字节流 MsgPacket.data
    void Start()
    {
        LuaScriptMgr mgr = new LuaScriptMgr();
        mgr.Start();
        TestProtolWrap.Register(mgr.GetL());
        mgr.DoFile("3rd/pblua/person_pb.lua");
        mgr.DoString(script);

        LuaFunction func = mgr.GetLuaFunction("encoder");
        func.Call();
        func.Release();

        func = mgr.GetLuaFunction("decoder");
        func.Call();
        func.Release();
    }
Esempio n. 30
0
 private void OnGUI()
 {
     if (GUI.Button(new Rect(20, 20, 200, 80), "Reflect"))
     {
         LuaState lua = new LuaState();
         lua.DoString(script);
         lua.Close();
     }
     if (GUI.Button(new Rect(20, 120, 200, 80), "Wrap"))
     {
         LuaScriptMgr lua = new LuaScriptMgr();
         lua.Start();
         lua.DoString(script2);
         lua.Destroy();
     }
 }
Esempio n. 31
0
    void Start()
    {
        LuaScriptMgr lua = new LuaScriptMgr();

        lua.Start();
        lua.DoString(script);
        LuaFunction f = lua.GetLuaFunction("TestArray");

        //转换一下类型,避免可变参数拆成多个参数传递
        object[] rts = f.Call((object)objs);
        f.Release();

        for (int i = 0; i < objs.Length; i++)
        {
            Debug.Log(rts[i].ToString());
        }
    }
Esempio n. 32
0
    private void Start()
    {
        LuaScriptMgr luaScriptMgr = new LuaScriptMgr();

        luaScriptMgr.Start();
        luaScriptMgr.DoString(this.script);
        LuaFunction luaFunction = luaScriptMgr.GetLuaFunction("TestArray");

        object[] array = luaFunction.Call(new object[]
        {
            this.objs
        });
        luaFunction.Release();
        for (int i = 0; i < this.objs.Length; i++)
        {
            Debug.Log(array[i].ToString());
        }
    }
Esempio n. 33
0
    //需要删除的转LuaFunction为委托,不需要删除的直接加或者等于即可
    void Start()
    {
        LuaScriptMgr mgr = new LuaScriptMgr();
        mgr.Start();
        mgr.DoString(script);
        TestEventListener listener = gameObject.AddComponent<TestEventListener>();         

        LuaFunction func = mgr.GetLuaFunction("AddDelegate");
        func.Call(listener);                
        listener.OnClick(gameObject);
        func.Release();

        Debug.Log("---------------------------------------------------------------------");        
        func = mgr.GetLuaFunction("RemoveDelegate");
        func.Call(listener);
        listener.OnClick(gameObject);
        func.Release();        
    }
Esempio n. 34
0
    // Use this for initialization
    void Start()
    {
        LuaScriptMgr mgr = new LuaScriptMgr();

        mgr.DoString(script);

        // Get the function object
        func = mgr.GetLuaFunction("luaFunc");

        //有gc alloc
        object[] r = func.Call(123456);
        print(r[0]);

        // no gc alloc
        int num = CallFunc();

        print(num);
    }
Esempio n. 35
0
    //实际应用如Socket.Send(LuaStringBuffer lsb)函数(功能发送lsb.buffer) , 在lua中调用Socket.Send(pb_data)
    //读取协议 Socket.PeekMsgPacket() {return MsgPacket}; lua 中,取协议字节流 MsgPacket.data
    void Start()
    {
        LuaScriptMgr mgr = new LuaScriptMgr();

        mgr.Start();
        TestProtolWrap.Register(mgr.GetL());
        mgr.DoFile("3rd/pblua/person_pb.lua");
        mgr.DoString(script);

        LuaFunction func = mgr.GetLuaFunction("encoder");

        func.Call();
        func.Release();

        func = mgr.GetLuaFunction("decoder");
        func.Call();
        func.Release();
    }
Esempio n. 36
0
    //需要删除的转LuaFunction为委托,不需要删除的直接加或者等于即可
    void Start()
    {
        LuaScriptMgr mgr = new LuaScriptMgr();
        mgr.Start();
        TestEventListenerWrap.Register(mgr.GetL());
        mgr.DoString(script);
        GameObject go = new GameObject("TestGo");
        TestEventListener listener = (TestEventListener)go.AddComponent(typeof(TestEventListener));         

        LuaFunction func = mgr.GetLuaFunction("AddDelegate");
        func.Call(listener);                
        listener.OnClick(go);
        func.Release();
        Debug.Log("---------------------------------------------------------------------");        
        func = mgr.GetLuaFunction("RemoveDelegate");
        func.Call(listener);
        listener.OnClick(go);
        func.Release();        
    }
Esempio n. 37
0
    // Use this for initialization
    void Start()
    {
        Screen.SetResolution(800, 480, true);

        TextAsset asset = Resources.Load <TextAsset>("perf");

        Profiler.BeginSample("init");
        l = new LuaScriptMgr();
        l.Start();
        l.DoString(asset.ToString());
        Profiler.EndSample();
        l.GetLuaFunction("main").Call();

#if UNITY_5
        Application.logMessageReceived += this.log;
#else
        Application.RegisterLogCallback(this.log);
#endif
    }
Esempio n. 38
0
    //需要删除的转LuaFunction为委托,不需要删除的直接加或者等于即可
    void Start()
    {
        LuaScriptMgr mgr = new LuaScriptMgr();

        mgr.Start();
        mgr.DoString(script);
        TestEventListener listener = gameObject.AddComponent <TestEventListener>();

        LuaFunction func = mgr.GetLuaFunction("AddDelegate");

        func.Call(listener);
        listener.OnClick(gameObject);
        func.Release();

        Debug.Log("---------------------------------------------------------------------");
        func = mgr.GetLuaFunction("RemoveDelegate");
        func.Call(listener);
        listener.OnClick(gameObject);
        func.Release();
    }
Esempio n. 39
0
    private bool LoadManetic(string sLuaFileName)
    {
        Util.ClearMemory();
        string       sLuaCode = File.ReadAllText(sLuaFileName);
        LuaScriptMgr mgr      = new LuaScriptMgr();

        mgr.DoString(sLuaCode);
        LuaFunction func = mgr.GetLuaFunction("GetMagneticByLatticeIndex");

        if (null == func)
        {
            ShowErrorMessage("GetMagneticByLatticeIndex function cannot been found.");
            mgr.Destroy();
            return(false);
        }

        for (int x = 0; x < m_iResolution; ++x)
        {
            for (int y = 0; y < m_iResolution; ++y)
            {
                object[] r = func.Call2(x, y);
                if (3 != r.Length ||
                    !(r[0] is double) ||
                    !(r[1] is double) ||
                    !(r[2] is double))
                {
                    ShowErrorMessage("GetMagneticByLatticeIndex should return 3 numbers.");
                    mgr.Destroy();
                    return(false);
                }

                _mags[y * m_iResolution + x] = new Vector3(
                    (float)(double)r[0],
                    (float)(double)r[1],
                    (float)(double)r[2]);
            }
        }
        mgr.Destroy();
        SetCurrentState(_mags);
        return(true);
    }
Esempio n. 40
0
    //需要删除的转LuaFunction为委托,不需要删除的直接加或者等于即可
    void Start()
    {
        LuaScriptMgr mgr = new LuaScriptMgr();

        mgr.Start();
        TestEventListenerWrap.Register(mgr.GetL());
        mgr.DoString(script);
        GameObject        go       = new GameObject("TestGo");
        TestEventListener listener = (TestEventListener)go.AddComponent(typeof(TestEventListener));

        LuaFunction func = mgr.GetLuaFunction("AddDelegate");

        func.Call(listener);
        listener.OnClick(go);
        func.Release();
        Debug.Log("---------------------------------------------------------------------");
        func = mgr.GetLuaFunction("RemoveDelegate");
        func.Call(listener);
        listener.OnClick(go);
        func.Release();
    }
Esempio n. 41
0
    public void Init()
    {
        System.DateTime time = System.DateTime.Now;
        _luaScriptMgr = new LuaScriptMgr();
        Debug.Log("【Time】LuaMgr>>>new LuaScriptMgr=>" + (System.DateTime.Now - time).TotalSeconds.ToString());

        time = System.DateTime.Now;
        _luaScriptMgr.Start();
        Debug.Log("【Time】LuaMgr>>>_luaScriptMgr.Start=>" + (System.DateTime.Now - time).TotalSeconds.ToString());

        string init = "require 'common/functions'\n" +
                      "require 'pbc/protobuf'\n" +
                      "parser = require 'pbc/parser'\n" +
                      "require 'Custom/Common/Common'\n";

        time = System.DateTime.Now;
        _luaScriptMgr.DoString(init);
        Debug.Log("【Time】LuaMgr>>>_luaScriptMgr.DoString=>" + (System.DateTime.Now - time).TotalSeconds.ToString());

        tblTime           = LuaScriptMgr.Instance.GetLuaTable("Time");
        funcSetFixedDelta = tblTime["SetFixedDelta"] as LuaFunction;
    }
Esempio n. 42
0
    private void Start()
    {
        LuaScriptMgr luaScriptMgr = new LuaScriptMgr();

        luaScriptMgr.Start();
        luaScriptMgr.DoString(this.script);
        TestEventListener testEventListener = base.gameObject.AddComponent <TestEventListener>();
        LuaFunction       luaFunction       = luaScriptMgr.GetLuaFunction("AddDelegate");

        luaFunction.Call(new object[]
        {
            testEventListener
        });
        testEventListener.OnClick(base.gameObject);
        luaFunction.Release();
        Debug.Log("---------------------------------------------------------------------");
        luaFunction = luaScriptMgr.GetLuaFunction("RemoveDelegate");
        luaFunction.Call(new object[]
        {
            testEventListener
        });
        testEventListener.OnClick(base.gameObject);
        luaFunction.Release();
    }
Esempio n. 43
0
    //反射已经无法区分这些重载函数了
    void Start()
    {
        LuaScriptMgr mgr = new LuaScriptMgr();
        mgr.Start();
        TestOverrideWrap.Register(mgr.GetL());
        TestOverride_SpaceWrap.Register(mgr.GetL());
        mgr.DoString(script);

        TestOverride to = new TestOverride();
        LuaFunction func = mgr.GetLuaFunction("Test");
        func.Call(to);   
    }
Esempio n. 44
0
	//非反射调用
	void Start () {
        LuaScriptMgr lua = new LuaScriptMgr();
        lua.Start();
        lua.DoString(script);
	}