LuaRegister.tpl.txt 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. #if USE_UNI_LUA
  2. using LuaAPI = UniLua.Lua;
  3. using RealStatePtr = UniLua.ILuaState;
  4. using LuaCSFunction = UniLua.CSharpFunctionDelegate;
  5. #else
  6. using LuaAPI = XLua.LuaDLL.Lua;
  7. using RealStatePtr = System.IntPtr;
  8. using LuaCSFunction = XLua.LuaDLL.lua_CSFunction;
  9. #endif
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Reflection;
  13. <%
  14. require "TemplateCommon"
  15. %>
  16. namespace XLua.CSObjectWrap
  17. {
  18. public class XLua_Gen_Initer_Register__
  19. {
  20. <%
  21. local split_method_perfix = 'wrapInit'
  22. local split_method_count = 0
  23. local wrap_in_split_method = 0
  24. local max_wrap_in_split_method = 50
  25. %>
  26. <%ForEachCsList(wraps, function(wrap)%>
  27. <%if wrap_in_split_method == 0 then%>static void <%=split_method_perfix%><%=split_method_count%>(LuaEnv luaenv, ObjectTranslator translator)
  28. {
  29. <%end%>
  30. translator.DelayWrapLoader(typeof(<%=CsFullTypeName(wrap)%>), <%=CSVariableName(wrap)%>Wrap.__Register);
  31. <%if wrap_in_split_method == max_wrap_in_split_method then
  32. wrap_in_split_method = 0
  33. split_method_count = split_method_count + 1
  34. %>
  35. }
  36. <%else
  37. wrap_in_split_method = wrap_in_split_method + 1
  38. end
  39. end)%>
  40. <% if generic_wraps then
  41. for generic_def, instances in pairs(generic_wraps) do
  42. for _, args in ipairs(instances) do
  43. local generic_arg_list = "<"
  44. ForEachCsList(args, function(generic_arg, gai)
  45. if gai ~= 0 then generic_arg_list = generic_arg_list .. ", " end
  46. generic_arg_list = generic_arg_list .. CsFullTypeName(generic_arg)
  47. end)
  48. generic_arg_list = generic_arg_list .. ">"
  49. %>
  50. <%if wrap_in_split_method == 0 then%>static void <%=split_method_perfix%><%=split_method_count%>(LuaEnv luaenv, ObjectTranslator translator)
  51. {
  52. <%end%>
  53. translator.DelayWrapLoader(typeof(<%=generic_def.Name:gsub("`%d+", "") .. generic_arg_list%>), <%=CSVariableName(generic_def)%>Wrap<%=generic_arg_list%>.__Register);
  54. <%if wrap_in_split_method == max_wrap_in_split_method then
  55. wrap_in_split_method = 0
  56. split_method_count = split_method_count + 1
  57. %>
  58. }
  59. <%else
  60. wrap_in_split_method = wrap_in_split_method + 1
  61. end
  62. end
  63. end
  64. end%>
  65. <%if wrap_in_split_method ~= 0 then
  66. split_method_count = split_method_count + 1
  67. %>}<%end%>
  68. static void Init(LuaEnv luaenv, ObjectTranslator translator)
  69. {
  70. <%for i = 1, split_method_count do%>
  71. <%=split_method_perfix%><%=(i - 1)%>(luaenv, translator);
  72. <%end%>
  73. <%ForEachCsList(itf_bridges, function(itf_bridge)%>
  74. translator.AddInterfaceBridgeCreator(typeof(<%=CsFullTypeName(itf_bridge)%>), <%=CSVariableName(itf_bridge)%>Bridge.__Create);
  75. <%end)%>
  76. }
  77. static XLua_Gen_Initer_Register__()
  78. {
  79. XLua.LuaEnv.AddIniter(Init);
  80. }
  81. }
  82. }
  83. namespace XLua
  84. {
  85. public partial class ObjectTranslator
  86. {
  87. static XLua.CSObjectWrap.XLua_Gen_Initer_Register__ s_gen_reg_dumb_obj = new XLua.CSObjectWrap.XLua_Gen_Initer_Register__();
  88. static XLua.CSObjectWrap.XLua_Gen_Initer_Register__ gen_reg_dumb_obj {get{return s_gen_reg_dumb_obj;}}
  89. }
  90. internal partial class InternalGlobals
  91. {
  92. <%
  93. local type_to_methods = {}
  94. local seq_tbl = {}
  95. ForEachCsList(extension_methods, function(extension_method, idx)
  96. local parameters = extension_method:GetParameters()
  97. local type = parameters[0].ParameterType
  98. if not type_to_methods[type] then
  99. type_to_methods[type] = {type = type}
  100. table.insert(seq_tbl, type_to_methods[type])
  101. end
  102. table.insert(type_to_methods[type], {method = extension_method, index = idx})
  103. %>
  104. delegate <%=CsFullTypeName(extension_method.ReturnType)%> __GEN_DELEGATE<%=idx%>(<%ForEachCsList(parameters, function(parameter, pi)
  105. %><%if pi ~= 0 then%>, <%end%><%if parameter.IsOut then %>out <% elseif parameter.ParameterType.IsByRef then %>ref <% end %> <%=CsFullTypeName(parameter.ParameterType)%> <%=parameter.Name%><%
  106. end)%>);
  107. <%end)%>
  108. static InternalGlobals()
  109. {
  110. extensionMethodMap = new Dictionary<Type, IEnumerable<MethodInfo>>()
  111. {
  112. <%for _, methods_info in ipairs(seq_tbl) do%>
  113. {typeof(<%=CsFullTypeName(methods_info.type)%>), new List<MethodInfo>(){
  114. <% for _, method_info in ipairs(methods_info) do%>
  115. new __GEN_DELEGATE<%=method_info.index%>(<%=CsFullTypeName(method_info.method.DeclaringType)%>.<%=method_info.method.Name%>)
  116. #if UNITY_WSA && !UNITY_EDITOR
  117. .GetMethodInfo(),
  118. #else
  119. .Method,
  120. #endif
  121. <% end%>
  122. }},
  123. <%end%>
  124. };
  125. genTryArrayGetPtr = StaticLuaCallbacks.__tryArrayGet;
  126. genTryArraySetPtr = StaticLuaCallbacks.__tryArraySet;
  127. }
  128. }
  129. }