From c3c0c0e6d978c1212919f944793066c1a70a74fb Mon Sep 17 00:00:00 2001 From: jarjin <2338894521@qq.com> Date: Sat, 12 Mar 2016 11:05:18 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DLuaLoop=E5=8D=8F=E5=90=8C?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Scripts/Manager/LuaManager.cs | 27 ++++++++++++++++--- .../02_ScriptsFromFile/ScriptsFromFile.cs | 2 +- Assets/LuaFramework/ToLua/Source/LuaConst.cs | 4 +-- ReadMe.txt | 3 +++ 4 files changed, 30 insertions(+), 6 deletions(-) diff --git a/Assets/LuaFramework/Scripts/Manager/LuaManager.cs b/Assets/LuaFramework/Scripts/Manager/LuaManager.cs index 2020320..9610c0d 100644 --- a/Assets/LuaFramework/Scripts/Manager/LuaManager.cs +++ b/Assets/LuaFramework/Scripts/Manager/LuaManager.cs @@ -6,12 +6,15 @@ namespace LuaFramework { public class LuaManager : Manager { private LuaState lua; private LuaLoader loader; + private LuaLooper loop = null; // Use this for initialization void Awake() { loader = new LuaLoader(); lua = new LuaState(); - this.InitLuaLibrary(); + this.OpenLibs(); + lua.LuaSetTop(0); + LuaBinder.Bind(lua); LuaCoroutine.Register(lua, this); } @@ -20,13 +23,28 @@ public void InitStart() { InitLuaPath(); InitLuaBundle(); this.lua.Start(); //启动LUAVM + this.StartMain(); + this.StartLooper(); + } + + void StartLooper() { + loop = gameObject.AddComponent(); + loop.luaState = lua; + } + + void StartMain() { lua.DoFile("Main.lua"); + + LuaFunction main = lua.GetFunction("Main"); + main.Call(); + main.Dispose(); + main = null; } /// /// 初始化加载第三方库 /// - void InitLuaLibrary() { + void OpenLibs() { lua.OpenLibs(LuaDLL.luaopen_pb); lua.OpenLibs(LuaDLL.luaopen_sproto_core); lua.OpenLibs(LuaDLL.luaopen_protobuf_c); @@ -64,8 +82,8 @@ void InitLuaBundle() { loader.AddBundle("Lua/Lua_View.unity3d"); loader.AddBundle("Lua/Lua_Controller.unity3d"); loader.AddBundle("Lua/Lua_Misc.unity3d"); - loader.AddBundle("Lua/Lua_protobuf.unity3d"); + loader.AddBundle("Lua/Lua_protobuf.unity3d"); loader.AddBundle("Lua/Lua_3rd_cjson.unity3d"); loader.AddBundle("Lua/Lua_3rd_luabitop.unity3d"); loader.AddBundle("Lua/Lua_3rd_pbc.unity3d"); @@ -92,6 +110,9 @@ public void LuaGC() { } public void Close() { + loop.Destroy(); + loop = null; + lua.Dispose(); lua = null; loader = null; diff --git a/Assets/LuaFramework/ToLua/Examples/02_ScriptsFromFile/ScriptsFromFile.cs b/Assets/LuaFramework/ToLua/Examples/02_ScriptsFromFile/ScriptsFromFile.cs index f89b4ed..338d36f 100644 --- a/Assets/LuaFramework/ToLua/Examples/02_ScriptsFromFile/ScriptsFromFile.cs +++ b/Assets/LuaFramework/ToLua/Examples/02_ScriptsFromFile/ScriptsFromFile.cs @@ -19,7 +19,7 @@ void Start () #endif lua = new LuaState(); lua.Start(); - string fullPath = Application.dataPath + "/ToLua/Examples/02_ScriptsFromFile"; + string fullPath = Application.dataPath + "/LuaFramework/ToLua/Examples/02_ScriptsFromFile"; lua.AddSearchPath(fullPath); } diff --git a/Assets/LuaFramework/ToLua/Source/LuaConst.cs b/Assets/LuaFramework/ToLua/Source/LuaConst.cs index 84aabd7..31d994a 100644 --- a/Assets/LuaFramework/ToLua/Source/LuaConst.cs +++ b/Assets/LuaFramework/ToLua/Source/LuaConst.cs @@ -2,6 +2,6 @@ public static class LuaConst { - public static string luaDir = Application.dataPath + "/Lua"; - public static string toluaDir = Application.dataPath + "/ToLua/Lua"; + public static string luaDir = Application.dataPath + "/LuaFramework/Lua"; + public static string toluaDir = Application.dataPath + "/LuaFramework/ToLua/Lua"; } \ No newline at end of file diff --git a/ReadMe.txt b/ReadMe.txt index 6da0f98..7be7bf9 100644 --- a/ReadMe.txt +++ b/ReadMe.txt @@ -15,6 +15,9 @@ tolua#地址: https://github.com/topameng/tolua tolua#底层库 https://github.com/topameng/tolua_runtime 服务器框架: https://github.com/jarjin/ServerFramework +//-------------2016-03-12------------- +(1)修复LuaLoop协同功能。 + //-------------2016-03-06------------- (1)更新tolua #到1.03版本