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)); } }
// 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)); } }