Пример #1
0
        public void StartLuaSvr(Action <bool> onComplete)
        {
            string    initModulePath  = GetModulePath(m_luaInitModuleName);
            TextAsset initModuleAsset = null;

            initModuleAsset = ResourceManager.Instance.LoadAsset <TextAsset>(initModulePath);

            if (initModuleAsset == null)
            {
                Debug.LogError("StartLuaSvr fail load initModuleAsset fail");
                onComplete(false);
            }

            // 构造lua state 环境
            m_luaSvr = new LuaSvr();

            // 设置lua模块加载器
            LuaSvr.mainState.loaderDelegate = LuaLoader;

            // 初始化lua环境
            m_luaSvr.init(null, () =>
            {
                // 加载初始化模块
                if (!string.IsNullOrEmpty(m_luaInitModuleName))
                {
                    m_luaSvr.start(m_luaInitModuleName);
                }
            });
            onComplete(true);
        }
Пример #2
0
 // Use this for initialization
 void Start()
 {
     l = new LuaSvr();
     l.init(null, () => {
         l.start("delegate");
     });
 }
Пример #3
0
 void StartLuaScript()
 {
     // Make sure that we got script file before start
     if (luaScript != null)
     {
         // Initializing
         svr = new LuaSvr();
         svr.init(null, () =>
         {
             object obj;
             // Reading lua scripts
             if (svr.luaState.doBuffer(luaScript.bytes, "Here can be any name but should unique", out obj))
             {
                 // Calling main function from lua script
                 LuaFunction func = (LuaFunction)svr.luaState["main"];
                 if (func != null)
                 {
                     self   = (LuaTable)func.call();
                     update = (LuaFunction)self["update"];
                 }
                 else
                 {
                     Debug.LogError("No main function");
                 }
             }
             else
             {
                 Debug.LogError("Can not read scripts");
             }
         });
     }
 }
Пример #4
0
        public void Close()
        {
            m_luaServer = null;
            if (m_luaUpdate != null)
            {
                m_luaUpdate.Dispose();
                m_luaUpdate = null;
            }

            if (m_luaUpdate != null)
            {
                m_luaLateUpdate.Dispose();
                m_luaLateUpdate = null;
            }

            if (m_FixedUpdate != null)
            {
                m_FixedUpdate.Dispose();
                m_FixedUpdate = null;
            }

            m_inited         = false;
            m_progress       = 0;
            LuaSvr.mainState = null;
        }
Пример #5
0
        public void StopSvr()
        {
            if (m_luaSvr == null)
            {
                return;
            }

            if (!m_launched)
            {
                SLua.Logger.LogError("lua虚拟机还没启动完成");
                return;
            }

            Application.logMessageReceived -= UnityLogCallback; //监听unitys的log

            m_luaTable = null;

            m_luaState.loaderDelegate = null;
            m_luaState.Dispose();

            m_luaUpdate      = null;
            m_luaLateUpdate  = null;
            m_luaNotify      = null;
            m_luaNotifyError = null;

            m_luaState = null;
            m_luaSvr   = null;
            m_launched = false;


            LuaEvtCenter.Enable = false;

            //errorDelegateLua = null; //因为是static,由外面自己维护
        }
Пример #6
0
    void Start()
    {
        lua  = new LuaSvr();
        self = (LuaTable)lua.start("LuaFiles/building_txt");
        //self = (LuaTable)lua.luaState.getObject("data");
        //object o = lua.luaState.getFunction("GetData").call();
        Debug.Log("table " + ((LuaTable)self[1])["name"]);


        LuaFunction dataFunction = ((LuaFunction)self["GetData"]);
        LuaTable    dataTable    = (LuaTable)dataFunction.call();
        LuaFunction callFunction = (LuaFunction)self["CallBack"];

        callFunction.call(222);
        //lua.luaState.getFunction("CallBack").call();
        lua.luaState.getFunction("Call").call(2);
        Debug.Log("table " + ((LuaTable)dataTable[1])["use_money"] + "   is Null " + (callFunction == null));


        LuaTable d = (LuaTable)((LuaFunction)self["GetData1"]).call();

        Debug.Log("---------------- : " + ((LuaTable)d[1])["use_money"]);
        LuaTable table2 = (LuaTable)lua.start("LuaFiles/building_txt1");

        test2 = (LuaFunction)self["test"];
        object o = test2.call(self, 9, 1);

        Debug.Log("add function :" + o);

        SetTransform = (LuaFunction)self["SetTransform"];
        SetTransform.call(self, tr);
        //tr.localPosition = new Vector3(2, 2, 2);
    }
Пример #7
0
    void Start()
    {
        Application.targetFrameRate = LGameConfig.DEFAULT_FRAME_RATE;

        if (_l == null)
        {
#if UNITY_5
            Application.logMessageReceived += this.log;
#else
            Application.RegisterLogCallback(this.log);
#endif
            if (LGameConfig.GetInstance().isDebug)
            {
                LuaState.loaderDelegate = loadFileWithSuffix;
            }
            else
            {
                LuaState.loaderDelegate = loadLuaWithAb;
            }
            _l = new LuaSvr();
            _l.init(tick, complete);
        }
        else
        {
            complete();
        }
    }
Пример #8
0
    // Use this for initialization
    private void Start()
    {
        l = new LuaSvr();
        l.Init(null, () =>
        {
            l.Start("valuetype");
        });

        using (LuaState newState = new LuaState())
        {
            LuaTable table = new LuaTable(newState);

            Vector2 v2  = new Vector2(1, 2);
            Vector3 v3  = new Vector3(1, 2, 3);
            Vector4 v4  = new Vector4(1, 2, 3, 4);
            Color   col = new Color(.1f, .2f, .3f);
            Foo     foo = new Foo();

            table["v2"]  = v2;
            table["v3"]  = v3;
            table["v4"]  = v4;
            table["col"] = col;
            table["foo"] = foo;

            Assert.IsTrue((Vector2)table["v2"] == v2);
            Assert.IsTrue((Vector3)table["v3"] == v3);
            Assert.IsTrue((Vector4)table["v4"] == v4);
            Assert.IsTrue((Color)table["col"] == col);
            Assert.IsTrue(table["foo"] == foo);
        }
    }
Пример #9
0
 void Start()
 {
     luaSvr = new LuaSvr();
     luaSvr.init(null, () => {
         luaSvr.start("useLua");
     }, LuaSvrFlag.LSF_DEBUG);
 }
Пример #10
0
    public void Init()
    {
        LuaState.loaderDelegate += LoaderDelegate;

        l = new LuaSvr();
        l.init(null, Complete, LuaSvrFlag.LSF_EXTLIB);
        DontDestroyOnLoad(this);
    }
Пример #11
0
 // Use this for initialization
 private void Start()
 {
     l = new LuaSvr();
     l.Init(null, () =>
     {
         l.Start("varobj");
     });
 }
Пример #12
0
 void Start()
 {
     svr = new LuaSvr();
     svr.init(null, () =>
     {
         self = (LuaTable)svr.start("skynet/main");
     }, LuaSvrFlag.LSF_EXTLIB);
 }
Пример #13
0
    //LuaFunction function;
    void Start()
    {
        luaSvr = LuaMgr.GetInstance().Init();
        //luaSvr.start("Test");
        //luaSvr.init(null, LuaCompleteFunc);

        LuaCompleteFunc();
    }
Пример #14
0
 // Use this for initialization
 void Start()
 {
     luaSvr = new LuaSvr();
     luaSvr.init(null, () =>
     {
         self = (LuaTable)luaSvr.start("startGame");
     });
 }
Пример #15
0
 // Use this for initialization
 void Start()
 {
     l = new LuaSvr();
     l.init(null, () =>
     {
         l.start("varobj");
     });
 }
Пример #16
0
 // Use this for initialization
 void Start()
 {
     l = new LuaSvr();
     l.init(null, () =>
     {
         l.start("LuaTest");
     });
 }
Пример #17
0
 // Use this for initialization
 void Start()
 {
     l = new LuaSvr();
     l.init(null, () =>
     {
         l.start("valuetype");
     });
 }
Пример #18
0
 // Use this for initialization
 public void Start()
 {
     l = new LuaSvr();
     l.Init(null, () =>
     {
         l.Start("delegate");
     });
 }
Пример #19
0
 void Awake()
 {
     _instance     = this;
     svr           = new LuaSvr();
     self          = (LuaTable)svr.start("LuaFiles/LuaCallCsAPI");
     self["event"] = DataEventSource.Instance;
     self["name"]  = "API";
 }
Пример #20
0
        private LuaModule()
        {
#if UNITY_EDITOR
            UnityEngine.Debug.Log("Consturct LuaModule...");
#endif
            _luaSvr = new LuaSvr();
            _luaSvr.init(progress => { }, () => { });
        }
Пример #21
0
 public void Start()
 {
     c = this;
     l = new LuaSvr();
     l.Init(null, () =>
     {
         l.Start("custom");
     });
 }
Пример #22
0
 void Start()
 {
     c = this;
     l = new LuaSvr();
     l.init(null, () =>
     {
         l.start("custom");
     });
 }
Пример #23
0
 void Start()
 {
     c = this;
     l = new LuaSvr();
     l.init(null, () =>
     {
         l.start("custom");
     });
 }
Пример #24
0
 void Start()
 {
     c = this;
     l = new LuaSvr();
     l.init(null, () =>
     {
         l.start("BindCSharp");
     });
 }
Пример #25
0
 void Start()
 {
     luaSvr = new LuaSvr();
     LuaSvr.mainState.loaderDelegate += LuaLoader;
     luaSvr.init(null, () =>
     {
         luaSvr.start("CreatePrefab.Lua");
     });
 }
Пример #26
0
 void Start()
 {
     svr = new LuaSvr();
     svr.init(null, () =>
     {
         self   = (LuaTable)svr.start("circle/circle");
         update = (LuaFunction)self["update"];
     });
 }
 // Use this for initialization
 void Start()
 {
     luaSvr = new LuaSvr();
     luaSvr.init(null, () =>
     {
         self = (LuaTable)luaSvr.start("main");
         //selfUpdate = (LuaFunction)self["update"];
     });
 }
Пример #28
0
 void Start()
 {
     luaSvr = new LuaSvr();
     LuaSvr.mainState.loaderDelegate += LuaLoader;
     luaSvr.init(null, () =>
     {
         luaSvr.start("MyPackage.Lua");
     });
 }
Пример #29
0
 public void ResetStatus()
 {
     svr = new LuaSvr();
     svr.init(null, () =>
     {
         CallScript("Main");
         save = LuaSvr.mainState.getFunction("save");
     });
 }
Пример #30
0
 void Start()
 {
     luaSvr = new LuaSvr();
     LuaSvr.mainState.loaderDelegate += LuaLoader;
     luaSvr.init(null, () =>
     {
         luaSvr.start("UseCSharpClass.Lua");
     });
 }
Пример #31
0
    private void Awake()
    {
        LuaSvr svr = new LuaSvr();

        svr.init(null, () =>
        {
            svr.start("06_RequireImport/06_RequireImport");
        });
    }
Пример #32
0
        public void TestLuaSvr()
        {
            var luaSvr = new LuaSvr();
            luaSvr.init((x) => { }, () => { });
            var code = @"
local testVar = 12345;
return testVar;
";
            object ret;
            luaSvr.luaState.doBuffer(Encoding.UTF8.GetBytes(code), "TestLua", out ret);
            Assert.AreEqual(ret, 12345);
        }
Пример #33
0
        public void CreateStructVector2()
        {
            var luaSvr = new LuaSvr();
            luaSvr.init(x => { }, () => { });

            var code = @"
            local v = Slua.CreateClass('SLua.Test.TestStruct+Vector2', 1, 2)
            return v
            ";
            var ret = luaSvr.luaState.doString(code);
            Assert.AreEqual(ret, new Vector2(1, 2f));
        }
Пример #34
0
        public void TestSLuaLib()
        {
            var luaSvr = new LuaSvr();
            luaSvr.init(x => { }, () => { });
            var code = @"
local TestSLua = Slua.GetClass('SLua.Test.TestSLua')
return TestSLua
";
            var ret = luaSvr.luaState.doString(code);
            Assert.AreEqual("SLua.LuaClassObject", ret.GetType().ToString());

            var clsField = ret.GetType().GetField("cls", BindingFlags.NonPublic | BindingFlags.Instance);
            var cls = clsField.GetValue(ret);
            Assert.AreEqual(typeof(TestSLua), cls);
        }
Пример #35
0
 public void Init()
 {
     luaSvr = new LuaSvr();
     luaSvr.init(x => { }, () => { });
 }