ToLua_System_Delegate.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. using System;
  2. using LuaInterface;
  3. public class ToLua_System_Delegate
  4. {
  5. public static string AdditionNameSpace = "System.Collections.Generic";
  6. [NoToLuaAttribute]
  7. public static string op_AdditionDefined =
  8. @" try
  9. {
  10. LuaTypes type = LuaDLL.lua_type(L, 1);
  11. switch (type)
  12. {
  13. case LuaTypes.LUA_TFUNCTION:
  14. Delegate arg0 = ToLua.ToObject(L, 2) as Delegate;
  15. LuaFunction func = ToLua.ToLuaFunction(L, 1);
  16. Type t = arg0.GetType();
  17. Delegate arg1 = DelegateFactory.CreateDelegate(t, func);
  18. Delegate arg2 = Delegate.Combine(arg0, arg1);
  19. ToLua.Push(L, arg2);
  20. return 1;
  21. case LuaTypes.LUA_TNIL:
  22. LuaDLL.lua_pushvalue(L, 2);
  23. return 1;
  24. case LuaTypes.LUA_TUSERDATA:
  25. Delegate a0 = ToLua.ToObject(L, 1) as Delegate;
  26. Delegate a1 = ToLua.CheckDelegate(a0.GetType(), L, 2);
  27. Delegate ret = Delegate.Combine(a0, a1);
  28. ToLua.Push(L, ret);
  29. return 1;
  30. default:
  31. LuaDLL.luaL_typerror(L, 1, ""Delegate"");
  32. return 0;
  33. }
  34. }
  35. catch (Exception e)
  36. {
  37. return LuaDLL.toluaL_exception(L, e);
  38. }";
  39. [NoToLuaAttribute]
  40. public static string op_SubtractionDefined =
  41. @" try
  42. {
  43. Delegate arg0 = (Delegate)ToLua.CheckObject<Delegate>(L, 1);
  44. LuaTypes type = LuaDLL.lua_type(L, 2);
  45. if (type == LuaTypes.LUA_TFUNCTION)
  46. {
  47. LuaState state = LuaState.Get(L);
  48. LuaFunction func = ToLua.ToLuaFunction(L, 2);
  49. Delegate[] ds = arg0.GetInvocationList();
  50. for (int i = 0; i < ds.Length; i++)
  51. {
  52. LuaDelegate ld = ds[i].Target as LuaDelegate;
  53. if (ld != null && ld.func == func && ld.self == null)
  54. {
  55. arg0 = Delegate.Remove(arg0, ds[i]);
  56. state.DelayDispose(ld.func);
  57. break;
  58. }
  59. }
  60. func.Dispose();
  61. ToLua.Push(L, arg0);
  62. return 1;
  63. }
  64. else
  65. {
  66. Delegate arg1 = (Delegate)ToLua.CheckObject<Delegate>(L, 2);
  67. arg0 = DelegateFactory.RemoveDelegate(arg0, arg1);
  68. ToLua.Push(L, arg0);
  69. return 1;
  70. }
  71. }
  72. catch (Exception e)
  73. {
  74. return LuaDLL.toluaL_exception(L, e);
  75. }";
  76. public static bool operator ==(ToLua_System_Delegate lhs, ToLua_System_Delegate rhs)
  77. {
  78. return false;
  79. }
  80. public static bool operator !=(ToLua_System_Delegate lhs, ToLua_System_Delegate rhs)
  81. {
  82. return false;
  83. }
  84. [UseDefinedAttribute]
  85. public static ToLua_System_Delegate operator +(ToLua_System_Delegate a, ToLua_System_Delegate b)
  86. {
  87. return null;
  88. }
  89. [UseDefinedAttribute]
  90. public static ToLua_System_Delegate operator -(ToLua_System_Delegate a, ToLua_System_Delegate b)
  91. {
  92. return null;
  93. }
  94. public override bool Equals(object other)
  95. {
  96. return false;
  97. }
  98. public override int GetHashCode()
  99. {
  100. return 0;
  101. }
  102. public static string DestroyDefined =
  103. @" Delegate arg0 = (Delegate)ToLua.CheckObject<Delegate>(L, 1);
  104. Delegate[] ds = arg0.GetInvocationList();
  105. for (int i = 0; i < ds.Length; i++)
  106. {
  107. LuaDelegate ld = ds[i].Target as LuaDelegate;
  108. if (ld != null)
  109. {
  110. ld.Dispose();
  111. }
  112. }
  113. return 0;";
  114. [UseDefinedAttribute]
  115. public static void Destroy(object obj)
  116. {
  117. }
  118. }