Skip to content

Commit 70351bd

Browse files
committed
更新tolua#到1.0.6.238版
1 parent acb755f commit 70351bd

File tree

9 files changed

+94
-42
lines changed

9 files changed

+94
-42
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System;
2+
using LuaInterface;
3+
4+
public class UnityEngine_CoroutineWrap
5+
{
6+
public static void Register(LuaState L)
7+
{
8+
L.BeginClass(typeof(UnityEngine.Coroutine), null);
9+
L.RegFunction("__tostring", ToLua.op_ToString);
10+
L.EndClass();
11+
}
12+
}

Assets/LuaFramework/ToLua/BaseType/UnityEngine_CoroutineWrap.cs.meta

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/LuaFramework/ToLua/Core/LuaDLL.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ public string short_src
187187

188188
public class LuaDLL
189189
{
190-
public static string version = "1.0.6.233";
190+
public static string version = "1.0.6.237";
191191
public static int LUA_MULTRET = -1;
192192
public static string[] LuaTypeName = { "none", "nil", "boolean", "lightuserdata", "number", "string", "table", "function", "userdata", "thread" };
193193

Assets/LuaFramework/ToLua/Core/LuaState.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ void OpenBaseLibs()
151151

152152
BeginModule("UnityEngine");
153153
UnityEngine_ObjectWrap.Register(this);
154+
UnityEngine_CoroutineWrap.Register(this);
154155
EndModule(); //end UnityEngine
155156

156157
EndModule(); //end global
@@ -180,7 +181,7 @@ void InitLuaPath()
180181

181182
if (!Directory.Exists(LuaConst.toluaDir))
182183
{
183-
string msg = string.Format("toluaDir path not exists: {0}, configer it in LuaConst.cs", LuaConst.luaDir);
184+
string msg = string.Format("toluaDir path not exists: {0}, configer it in LuaConst.cs", LuaConst.toluaDir);
184185
throw new LuaException(msg);
185186
}
186187

Assets/LuaFramework/ToLua/Core/ToLua.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -300,15 +300,10 @@ static int IsNull(IntPtr L)
300300
{
301301
object o = ToLua.ToObject(L, -1);
302302

303-
if (o == null)
303+
if (o == null || o.Equals(null))
304304
{
305305
LuaDLL.lua_pushboolean(L, true);
306306
}
307-
else if (o is UnityEngine.Object)
308-
{
309-
UnityEngine.Object obj = (UnityEngine.Object)o;
310-
LuaDLL.lua_pushboolean(L, obj == null);
311-
}
312307
else
313308
{
314309
LuaDLL.lua_pushboolean(L, false);
@@ -526,7 +521,11 @@ static void GetToLuaInstanceID()
526521
{
527522
if (_instanceID == -1)
528523
{
529-
_instanceID = AssetDatabase.LoadAssetAtPath("Assets/LuaFramework/ToLua/Core/ToLua.cs", typeof(MonoScript)).GetInstanceID();
524+
int start = LuaConst.toluaDir.IndexOf("Assets");
525+
int end = LuaConst.toluaDir.LastIndexOf("/Lua");
526+
string dir = LuaConst.toluaDir.Substring(start, end - start);
527+
dir += "/Core/ToLua.cs";
528+
_instanceID = AssetDatabase.LoadAssetAtPath(dir, typeof(MonoScript)).GetInstanceID();//"Assets/ToLua/Core/ToLua.cs"
530529
}
531530
}
532531

Assets/LuaFramework/ToLua/Editor/ToLuaMenu.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,11 +1086,11 @@ public static void BuildNotJitBundles()
10861086
CopyLuaBytesFiles(LuaConst.luaDir, tempDir);
10871087
CopyLuaBytesFiles(LuaConst.toluaDir, tempDir);
10881088

1089-
AssetDatabase.SaveAssets();
1089+
AssetDatabase.Refresh();
10901090
List<string> dirs = new List<string>();
10911091
GetAllDirs(tempDir, dirs);
10921092

1093-
#if UNITY_5
1093+
#if UNITY_5
10941094
for (int i = 0; i < dirs.Count; i++)
10951095
{
10961096
string str = dirs[i].Remove(0, tempDir.Length);
@@ -1099,10 +1099,11 @@ public static void BuildNotJitBundles()
10991099

11001100
BuildLuaBundle(null, "Assets/temp/Lua");
11011101

1102-
AssetDatabase.SaveAssets();
1103-
string output = string.Format("{0}/{1}", Application.streamingAssetsPath, GetOS());
1102+
AssetDatabase.SaveAssets();
1103+
string output = string.Format("{0}/{1}", Application.streamingAssetsPath, GetOS());
11041104
BuildPipeline.BuildAssetBundles(output, BuildAssetBundleOptions.DeterministicAssetBundle, EditorUserBuildSettings.activeBuildTarget);
1105-
Directory.Delete(Application.dataPath + "/temp/", true);
1105+
1106+
//Directory.Delete(Application.dataPath + "/temp/", true);
11061107
#else
11071108
for (int i = 0; i < dirs.Count; i++)
11081109
{

Assets/LuaFramework/ToLua/Misc/LuaCoroutine.cs

Lines changed: 50 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2626

2727
public static class LuaCoroutine
2828
{
29-
static MonoBehaviour mb = null;
29+
static MonoBehaviour mb = null;
3030

3131
static string strCo =
3232
@"
33-
local _WaitForSeconds, _WaitForFixedUpdate, _WaitForEndOfFrame, _Yield = WaitForSeconds, WaitForFixedUpdate, WaitForEndOfFrame, Yield
33+
local _WaitForSeconds, _WaitForFixedUpdate, _WaitForEndOfFrame, _Yield, _StopCoroutine = WaitForSeconds, WaitForFixedUpdate, WaitForEndOfFrame, Yield, StopCoroutine
3434
local error = error
3535
local debug = debug
3636
local coroutine = coroutine
@@ -54,8 +54,7 @@ function WaitForSeconds(t)
5454
_resume(co)
5555
end
5656
57-
comap[co] = true
58-
_WaitForSeconds(t, resume)
57+
comap[co] = _WaitForSeconds(t, resume)
5958
return coroutine.yield()
6059
end
6160
@@ -65,8 +64,7 @@ function WaitForFixedUpdate()
6564
_resume(co)
6665
end
6766
68-
comap[co] = true
69-
_WaitForFixedUpdate(resume)
67+
comap[co] = _WaitForFixedUpdate(resume)
7068
return coroutine.yield()
7169
end
7270
@@ -76,8 +74,7 @@ function WaitForEndOfFrame()
7674
_resume(co)
7775
end
7876
79-
comap[co] = true
80-
_WaitForEndOfFrame(resume)
77+
comap[co] = _WaitForEndOfFrame(resume)
8178
return coroutine.yield()
8279
end
8380
@@ -87,8 +84,7 @@ function Yield(o)
8784
_resume(co)
8885
end
8986
90-
comap[co] = true
91-
_Yield(o, resume)
87+
comap[co] = _Yield(o, resume)
9288
return coroutine.yield()
9389
end
9490
@@ -99,21 +95,29 @@ function StartCoroutine(func)
9995
end
10096
10197
function StopCoroutine(co)
102-
comap[co] = false
98+
local _co = comap[co]
99+
100+
if _co == nil then
101+
return
102+
end
103+
104+
comap[co] = nil
105+
_StopCoroutine(_co)
103106
end
104107
";
105108

106109
public static void Register(LuaState state, MonoBehaviour behaviour)
107-
{
110+
{
108111
state.BeginModule(null);
109112
state.RegFunction("WaitForSeconds", WaitForSeconds);
110113
state.RegFunction("WaitForFixedUpdate", WaitForFixedUpdate);
111-
state.RegFunction("WaitForEndOfFrame", WaitForEndOfFrame);
112-
state.RegFunction("Yield", Yield);
113-
state.EndModule();
114+
state.RegFunction("WaitForEndOfFrame", WaitForEndOfFrame);
115+
state.RegFunction("Yield", Yield);
116+
state.RegFunction("StopCoroutine", StopCoroutine);
117+
state.EndModule();
114118

115119
state.LuaDoString(strCo);
116-
mb = behaviour;
120+
mb = behaviour;
117121
}
118122

119123
//另一种方式,非脚本回调方式(用脚本方式更好,可避免lua_yield异常出现在c#函数中)
@@ -148,8 +152,9 @@ static int WaitForSeconds(IntPtr L)
148152
{
149153
float sec = (float)LuaDLL.luaL_checknumber(L, 1);
150154
LuaFunction func = ToLua.ToLuaFunction(L, 2);
151-
mb.StartCoroutine(CoWaitForSeconds(sec, func));
152-
return 0;
155+
Coroutine co = mb.StartCoroutine(CoWaitForSeconds(sec, func));
156+
ToLua.PushObject(L, co);
157+
return 1;
153158
}
154159
catch (Exception e)
155160
{
@@ -169,8 +174,9 @@ static int WaitForFixedUpdate(IntPtr L)
169174
try
170175
{
171176
LuaFunction func = ToLua.ToLuaFunction(L, 1);
172-
mb.StartCoroutine(CoWaitForFixedUpdate(func));
173-
return 0;
177+
Coroutine co = mb.StartCoroutine(CoWaitForFixedUpdate(func));
178+
ToLua.PushObject(L, co);
179+
return 1;
174180
}
175181
catch (Exception e)
176182
{
@@ -179,7 +185,7 @@ static int WaitForFixedUpdate(IntPtr L)
179185
}
180186

181187
static IEnumerator CoWaitForFixedUpdate(LuaFunction func)
182-
{
188+
{
183189
yield return new WaitForFixedUpdate();
184190
func.Call();
185191
}
@@ -190,8 +196,9 @@ static int WaitForEndOfFrame(IntPtr L)
190196
try
191197
{
192198
LuaFunction func = ToLua.ToLuaFunction(L, 1);
193-
mb.StartCoroutine(CoWaitForEndOfFrame(func));
194-
return 0;
199+
Coroutine co = mb.StartCoroutine(CoWaitForEndOfFrame(func));
200+
ToLua.PushObject(L, co);
201+
return 1;
195202
}
196203
catch (Exception e)
197204
{
@@ -203,7 +210,7 @@ static IEnumerator CoWaitForEndOfFrame(LuaFunction func)
203210
{
204211
yield return new WaitForEndOfFrame();
205212
func.Call();
206-
}
213+
}
207214

208215
[MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
209216
static int Yield(IntPtr L)
@@ -212,8 +219,9 @@ static int Yield(IntPtr L)
212219
{
213220
object o = ToLua.ToVarObject(L, 1);
214221
LuaFunction func = ToLua.ToLuaFunction(L, 2);
215-
mb.StartCoroutine(CoYield(o, func));
216-
return 0;
222+
Coroutine co = mb.StartCoroutine(CoYield(o, func));
223+
ToLua.PushObject(L, co);
224+
return 1;
217225
}
218226
catch (Exception e)
219227
{
@@ -233,6 +241,21 @@ static IEnumerator CoYield(object o, LuaFunction func)
233241
}
234242

235243
func.Call();
236-
}
244+
}
245+
246+
[MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
247+
static int StopCoroutine(IntPtr L)
248+
{
249+
try
250+
{
251+
Coroutine co = (Coroutine)ToLua.CheckObject(L, 1, typeof(Coroutine));
252+
mb.StopCoroutine(co);
253+
return 0;
254+
}
255+
catch (Exception e)
256+
{
257+
return LuaDLL.toluaL_exception(L, e);
258+
}
259+
}
237260
}
238261

Assets/LuaFramework/ToLua/Reflection/LuaReflection.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ public LuaReflection()
3939
#endif
4040
LoadAssembly("mscorlib");
4141
LoadAssembly("UnityEngine");
42-
LoadAssembly("Assembly-CSharp");
42+
//注释避免放在插件目录无法加载,需要可从lua代码loadassembly
43+
//LoadAssembly("Assembly-CSharp");
4344
}
4445

4546
public static void OpenLibs(IntPtr L)

ReadMe.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ tolua#地址: https://github.com/topameng/tolua
1616
XlsxToLua: https://github.com/zhangqi-ulua/XlsxToLua
1717
UnityHello: https://github.com/woshihuo12/UnityHello
1818

19+
//-------------2016-08-20-------------
20+
(1)更新tolua#到1.0.6.238版
21+
1922
//-------------2016-08-13-------------
2023
(1)更新tolua#到1.0.6.233版
2124

0 commit comments

Comments
 (0)