static int _CreateToLuaInjectionTest(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 0)
            {
                ToLuaInjectionTest obj = new ToLuaInjectionTest();
                ToLua.PushObject(L, obj);
                return(1);
            }
            else if (count == 1)
            {
                bool arg0 = LuaDLL.luaL_checkboolean(L, 1);
                ToLuaInjectionTest obj = new ToLuaInjectionTest(arg0);
                ToLua.PushObject(L, obj);
                return(1);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to ctor method: ToLuaInjectionTest.New"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
 static int TestCoroutine(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 2);
         ToLuaInjectionTest obj           = (ToLuaInjectionTest)ToLua.CheckObject <ToLuaInjectionTest>(L, 1);
         float arg0                       = (float)LuaDLL.luaL_checknumber(L, 2);
         System.Collections.IEnumerator o = obj.TestCoroutine(arg0);
         ToLua.Push(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
 static int TestRef(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 2);
         ToLuaInjectionTest obj = (ToLuaInjectionTest)ToLua.CheckObject <ToLuaInjectionTest>(L, 1);
         int arg0 = (int)LuaDLL.luaL_checknumber(L, 2);
         int o    = obj.TestRef(ref arg0);
         LuaDLL.lua_pushinteger(L, o);
         LuaDLL.lua_pushinteger(L, arg0);
         return(2);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
    static int set_PropertyTest(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            ToLuaInjectionTest obj = (ToLuaInjectionTest)o;
            int arg0 = (int)LuaDLL.luaL_checknumber(L, 2);
            obj.PropertyTest = arg0;
            return(0);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o, "attempt to index PropertyTest on a nil value"));
        }
    }
    static int get_PropertyTest(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            ToLuaInjectionTest obj = (ToLuaInjectionTest)o;
            int ret = obj.PropertyTest;
            LuaDLL.lua_pushinteger(L, ret);
            return(1);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o, "attempt to index PropertyTest on a nil value"));
        }
    }
    static int TestOverload(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 3 && TypeChecker.CheckTypes <bool, int>(L, 2))
            {
                ToLuaInjectionTest obj = (ToLuaInjectionTest)ToLua.CheckObject <ToLuaInjectionTest>(L, 1);
                bool arg0 = LuaDLL.lua_toboolean(L, 2);
                int  arg1 = (int)LuaDLL.lua_tonumber(L, 3);
                obj.TestOverload(arg0, arg1);
                return(0);
            }
            else if (count == 3 && TypeChecker.CheckTypes <int, bool>(L, 2))
            {
                ToLuaInjectionTest obj = (ToLuaInjectionTest)ToLua.CheckObject <ToLuaInjectionTest>(L, 1);
                int  arg0 = (int)LuaDLL.lua_tonumber(L, 2);
                bool arg1 = LuaDLL.lua_toboolean(L, 3);
                obj.TestOverload(arg0, ref arg1);
                LuaDLL.lua_pushboolean(L, arg1);
                return(1);
            }
            else if (count == 3 && TypeChecker.CheckTypes <int, bool>(L, 2))
            {
                ToLuaInjectionTest obj = (ToLuaInjectionTest)ToLua.CheckObject <ToLuaInjectionTest>(L, 1);
                int  arg0 = (int)LuaDLL.lua_tonumber(L, 2);
                bool arg1 = LuaDLL.lua_toboolean(L, 3);
                obj.TestOverload(arg0, arg1);
                return(0);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to method: ToLuaInjectionTest.TestOverload"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
示例#7
0
    // Use this for initialization
    void Start()
    {
        InitGUI();
#if UNITY_5 || UNITY_2017_1_OR_NEWER
        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
            ///此处Require是示例专用,暖更新的lua代码都要放到LuaInjectionBus.lua中统一require
            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("TestOverload ref result:" + state);
            test.TestOverload(state, 1);
            int refResult = test.TestRef(ref counter);
            Debug.Log(string.Format("TestRef return result:{0}; ref result:{1}", refResult, 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_1_OR_NEWER
        Application.logMessageReceived -= ShowTips;
#else
        Application.RegisterLogCallback(null);
#endif
        luaState.Dispose();
        luaState = null;
    }

    Vector2 MousePoisition {
        get { return(new Vector2(-Input.mousePosition.x, Input.mousePosition.y)); }
    }