예제 #1
0
 private void Bind()
 {
     LuaBinder.Bind(m_LuaState);
     LuaCoroutine.Register(m_LuaState, this);
 }
예제 #2
0
파일: MainGame.cs 프로젝트: ukyohpq/tolua
 protected virtual void Bind()
 {
     LuaBinder.Bind(luaState);
     DelegateFactory.Init();
     LuaCoroutine.Register(luaState, this);
 }
예제 #3
0
파일: LuaClient.cs 프로젝트: jilianji/Demo
 protected virtual void Bind()
 {
     LuaBinder.Bind(luaState);
     LuaCoroutine.Register(luaState, this);
 }
예제 #4
0
    // Use this for initialization
    void Start()
    {
        InitGUI();
#if UNITY_5 || UNITY_2017
        Application.logMessageReceived += ShowTips;
#else
        Application.RegisterLogCallback(ShowTips);
#endif
        new LuaResLoader();
        luaState = new LuaState();
        luaState.Start();
        LuaBinder.Bind(luaState);
        //For InjectByModule
        //////////////////////////////////////////////////////
        luaState.BeginModule(null);
        BaseTestWrap.Register(luaState);
        ToLuaInjectionTestWrap.Register(luaState);
        luaState.EndModule();
        //////////////////////////////////////////////////////

#if ENABLE_LUA_INJECTION
#if UNITY_EDITOR
        if (UnityEditor.EditorPrefs.GetInt(Application.dataPath + "InjectStatus") == 1)
        {
#else
        if (true)
        {
#endif
            luaState.Require("ToLuaInjectionTestInjector");
            int  counter            = 0;
            bool state              = true;
            ToLuaInjectionTest test = new ToLuaInjectionTest(true);
            test = new ToLuaInjectionTest();
            StartCoroutine(test.TestCoroutine(0.3f));
            test.TestOverload(1, state);
            test.TestOverload(1, ref state);
            Debug.Log("ref Test Result :" + state);
            test.TestOverload(state, 1);
            Debug.Log("ref Test Return Value :" + test.TestRef(ref counter));
            Debug.Log("ref Test Result :" + counter);
            Debug.Log("Property Get Test:" + test.PropertyTest);
            test.PropertyTest = 2;
            Debug.Log("Property Set Test:" + test.PropertyTest);

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();
            for (int i = 0; i < 10000000; ++i)
            {
                test.NoInject(true, 1);
            }
            sw.Stop();
            long noInjectMethodCostTime = sw.ElapsedMilliseconds;
            sw.Reset();
            sw.Start();
            for (int i = 0; i < 10000000; ++i)
            {
                test.Inject(true, 1);
            }
            sw.Stop();
            Debug.Log("time cost ratio:" + (double)sw.ElapsedMilliseconds / noInjectMethodCostTime);
        }
        else
#endif
        {
            Debug.LogError("查看是否开启了宏ENABLE_LUA_INJECTION并执行了菜单命令——\"Lua=>Inject All\"");
        }
    }

    void InitGUI()
    {
        m_windowRect.x      = 0;
        m_windowRect.y      = 0;
        m_windowRect.width  = Screen.width;
        m_windowRect.height = Screen.height;

        m_logFontSize = (int)(m_fontSize * Screen.width * Screen.height / (1280 * 720));
        m_normalColor = Color.white;
        m_fontStyle   = new GUIStyle();
        m_fontStyle.normal.textColor = m_normalColor;
        m_fontStyle.fontSize         = m_logFontSize;

        //设置窗口颜色
        m_windowStyle = new GUIStyle();
        Texture2D windowTexture = new Texture2D(1, 1);

        windowTexture.SetPixel(0, 0, Color.black);
        windowTexture.Apply();
        m_windowStyle.normal.background = windowTexture;

        scaleThreshold = Screen.width / 1100.0f;
    }

    void OnApplicationQuit()
    {
#if UNITY_5 || UNITY_2017
        Application.logMessageReceived -= ShowTips;
#else
        Application.RegisterLogCallback(null);
#endif
        luaState.Dispose();
        luaState = null;
    }

    Vector2 MousePoisition {
        get { return(new Vector2(-Input.mousePosition.x, Input.mousePosition.y)); }
    }
예제 #5
0
        public void Initialize(Action OnInitalOver)
        {
            string[] fileNameArr = new string[lhConfigData.luaLoaderConfig.luaFiles.Count];
            string[] pathArr     = new string[lhConfigData.luaLoaderConfig.luaFiles.Count];
            for (int i = 0; i < lhConfigData.luaLoaderConfig.luaFiles.Count; i++)
            {
                fileNameArr[i] = lhConfigData.luaLoaderConfig.luaFiles[i].name;
                pathArr[i]     = lhConfigData.luaLoaderConfig.luaFiles[i].path;
            }
            lhResources.Load(pathArr,
                             (i, s, o) =>
            {
                if (o == null)
                {
                    lhDebug.LogError("LaoHan: load is null  ->" + s);
                }
                byte[] bytes = (o as TextAsset).bytes;
                m_luaDic.Add(fileNameArr[i], bytes);
            },
                             () => {
                luaState = new LuaState();
                luaState.OpenLibs(LuaDLL.luaopen_pb);
                luaState.OpenLibs(LuaDLL.luaopen_struct);
                luaState.OpenLibs(LuaDLL.luaopen_lpeg);
#if UNITY_STANDALONE_OSX || UNITY_EDITOR_OSX
                luaState.OpenLibs(LuaDLL.luaopen_bit);
#endif
                if (m_openLuaSocket)
                {
                    luaState.OpenLibs(LuaDLL.luaopen_socket_core);
                    luaState.OpenLibs(LuaDLL.luaopen_luasocket_scripts);
                }
                //-------------------cjson
                luaState.LuaGetField(LuaIndexes.LUA_REGISTRYINDEX, "_LOADED");
                luaState.OpenLibs(LuaDLL.luaopen_cjson);
                luaState.LuaSetField(-2, "cjson");

                luaState.OpenLibs(LuaDLL.luaopen_cjson_safe);
                luaState.LuaSetField(-2, "cjson.safe");
                //---------------

                luaState.LuaSetTop(0);

                LuaBinder.Bind(luaState);

                luaState.Start();
                if (!string.IsNullOrEmpty(lhConfigData.luaLoaderConfig.entry.startFileName))
                {
                    luaState.DoFile(lhConfigData.luaLoaderConfig.entry.startFileName);
                }
                if (!string.IsNullOrEmpty(lhConfigData.luaLoaderConfig.entry.startFunction))
                {
                    LuaFunction main = luaState.GetFunction(lhConfigData.luaLoaderConfig.entry.startFunction);
                    main.Call();
                    main.Dispose();
                    main = null;
                }
                OnInitalOver();
            }
                             );
        }
예제 #6
0
 // Use this for initialization
 void Awake()
 {
     loader = new LuaLoader();
     lua    = new LuaState();
     LuaBinder.Bind(lua);
 }
예제 #7
0
    void Bind()
    {
        IntPtr L = lua.L;

        LuaBinder.Bind(L);
    }