Skip to content

Commit 9a68c8f

Browse files
committed
更新tolua#到1.0.6.253版
1 parent 217b1bc commit 9a68c8f

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

Assets/LuaFramework/ToLua/Editor/ToLuaExport.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3254,6 +3254,25 @@ public static Delegate CreateDelegate(Type t, LuaFunction func = null)
32543254
{
32553255
throw new LuaException(string.Format(""Delegate {0} not register"", LuaMisc.GetTypeName(t)));
32563256
}
3257+
3258+
if (func != null)
3259+
{
3260+
int luaFunctionRef = func.GetReference();
3261+
WeakReference luaDelegateWeakRef = null;
3262+
if (!luaDelegateDict.TryGetValue(luaFunctionRef, out luaDelegateWeakRef) || luaDelegateWeakRef == null || !luaDelegateWeakRef.IsAlive)
3263+
{
3264+
Delegate d = create(func, null, false);
3265+
luaDelegateWeakRef = new WeakReference(d.Target);
3266+
luaDelegateDict[luaFunctionRef] = luaDelegateWeakRef;
3267+
return d;
3268+
}
3269+
3270+
LuaDelegate luaDelegate = luaDelegateWeakRef.Target as LuaDelegate;
3271+
if (luaDelegate.self == null)
3272+
return Delegate.CreateDelegate(t, luaDelegate, ""Call"");
3273+
else
3274+
return Delegate.CreateDelegate(t, luaDelegate, ""CallWithSelf"");
3275+
}
32573276
32583277
return create(func, null, false);
32593278
}
@@ -3440,6 +3459,7 @@ public static void GenDelegates(DelegateType[] list)
34403459
sb.Append("{\r\n");
34413460
sb.Append("\tpublic delegate Delegate DelegateValue(LuaFunction func, LuaTable self, bool flag);\r\n");
34423461
sb.Append("\tpublic static Dictionary<Type, DelegateValue> dict = new Dictionary<Type, DelegateValue>();\r\n");
3462+
sb.Append("\tpublic static Dictionary<int, WeakReference> luaDelegateDict = new Dictionary<int, WeakReference>();\r\n");
34433463
sb.AppendLineEx();
34443464
sb.Append("\tstatic DelegateFactory()\r\n");
34453465
sb.Append("\t{\r\n");

Assets/LuaFramework/ToLua/Misc/LuaClient.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2525
using System.Collections;
2626
using System.IO;
2727
using System;
28+
29+
#if UNITY_5_4
2830
using UnityEngine.SceneManagement;
31+
#endif
2932

3033
public class LuaClient : MonoBehaviour
3134
{

Assets/LuaFramework/ToLua/Source/Generate/DelegateFactory.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ public static class DelegateFactory
77
{
88
public delegate Delegate DelegateValue(LuaFunction func, LuaTable self, bool flag);
99
public static Dictionary<Type, DelegateValue> dict = new Dictionary<Type, DelegateValue>();
10+
public static Dictionary<int, WeakReference> luaDelegateDict = new Dictionary<int, WeakReference>();
1011

1112
static DelegateFactory()
1213
{
@@ -28,6 +29,25 @@ public static Delegate CreateDelegate(Type t, LuaFunction func = null)
2829
{
2930
throw new LuaException(string.Format("Delegate {0} not register", LuaMisc.GetTypeName(t)));
3031
}
32+
33+
if (func != null)
34+
{
35+
int luaFunctionRef = func.GetReference();
36+
WeakReference luaDelegateWeakRef = null;
37+
if (!luaDelegateDict.TryGetValue(luaFunctionRef, out luaDelegateWeakRef) || luaDelegateWeakRef == null || !luaDelegateWeakRef.IsAlive)
38+
{
39+
Delegate d = create(func, null, false);
40+
luaDelegateWeakRef = new WeakReference(d.Target);
41+
luaDelegateDict[luaFunctionRef] = luaDelegateWeakRef;
42+
return d;
43+
}
44+
45+
LuaDelegate luaDelegate = luaDelegateWeakRef.Target as LuaDelegate;
46+
if (luaDelegate.self == null)
47+
return Delegate.CreateDelegate(t, luaDelegate, "Call");
48+
else
49+
return Delegate.CreateDelegate(t, luaDelegate, "CallWithSelf");
50+
}
3151

3252
return create(func, null, false);
3353
}

0 commit comments

Comments
 (0)