LuaClassWrapGCM.tpl.txt 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517
  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 XLua;
  11. using System.Collections.Generic;
  12. <%ForEachCsList(namespaces, function(namespace)%>using <%=namespace%>;<%end)%>
  13. <%
  14. require "TemplateCommon"
  15. local OpNameMap = {
  16. op_Addition = "__AddMeta",
  17. op_Subtraction = "__SubMeta",
  18. op_Multiply = "__MulMeta",
  19. op_Division = "__DivMeta",
  20. op_Equality = "__EqMeta",
  21. op_UnaryNegation = "__UnmMeta",
  22. op_LessThan = "__LTMeta",
  23. op_LessThanOrEqual = "__LEMeta",
  24. op_Modulus = "__ModMeta",
  25. op_BitwiseAnd = "__BandMeta",
  26. op_BitwiseOr = "__BorMeta",
  27. op_ExclusiveOr = "__BxorMeta",
  28. op_OnesComplement = "__BnotMeta",
  29. op_LeftShift = "__ShlMeta",
  30. op_RightShift = "__ShrMeta",
  31. }
  32. local OpCallNameMap = {
  33. op_Addition = "+",
  34. op_Subtraction = "-",
  35. op_Multiply = "*",
  36. op_Division = "/",
  37. op_Equality = "==",
  38. op_UnaryNegation = "-",
  39. op_LessThan = "<",
  40. op_LessThanOrEqual = "<=",
  41. op_Modulus = "%",
  42. op_BitwiseAnd = "&",
  43. op_BitwiseOr = "|",
  44. op_ExclusiveOr = "^",
  45. op_OnesComplement = "~",
  46. op_LeftShift = "<<",
  47. op_RightShift = ">>",
  48. }
  49. local obj_method_count = 0
  50. local obj_getter_count = 0
  51. local obj_setter_count = 0
  52. local meta_func_count = operators.Count
  53. local cls_field_count = 1
  54. local cls_getter_count = 0
  55. local cls_setter_count = 0
  56. ForEachCsList(methods, function(method)
  57. if method.IsStatic then
  58. cls_field_count = cls_field_count + 1
  59. else
  60. obj_method_count = obj_method_count + 1
  61. end
  62. end)
  63. ForEachCsList(events, function(event)
  64. if event.IsStatic then
  65. cls_field_count = cls_field_count + 1
  66. else
  67. obj_method_count = obj_method_count + 1
  68. end
  69. end)
  70. ForEachCsList(getters, function(getter)
  71. if getter.IsStatic then
  72. if getter.ReadOnly then
  73. cls_field_count = cls_field_count + 1
  74. else
  75. cls_getter_count = cls_getter_count + 1
  76. end
  77. else
  78. obj_getter_count = obj_getter_count + 1
  79. end
  80. end)
  81. ForEachCsList(setters, function(setter)
  82. if setter.IsStatic then
  83. cls_setter_count = cls_setter_count + 1
  84. else
  85. obj_setter_count = obj_setter_count + 1
  86. end
  87. end)
  88. ForEachCsList(lazymembers, function(lazymember)
  89. if lazymember.IsStatic == 'true' then
  90. if 'CLS_IDX' == lazymember.Index then
  91. cls_field_count = cls_field_count + 1
  92. elseif 'CLS_GETTER_IDX' == lazymember.Index then
  93. cls_getter_count = cls_getter_count + 1
  94. elseif 'CLS_SETTER_IDX' == lazymember.Index then
  95. cls_setter_count = cls_setter_count + 1
  96. end
  97. else
  98. if 'METHOD_IDX' == lazymember.Index then
  99. obj_method_count = obj_method_count + 1
  100. elseif 'GETTER_IDX' == lazymember.Index then
  101. obj_getter_count = obj_getter_count + 1
  102. elseif 'SETTER_IDX' == lazymember.Index then
  103. obj_setter_count = obj_setter_count + 1
  104. end
  105. end
  106. end)
  107. local v_type_name = CSVariableName(type)
  108. local generic_arg_list, type_constraints = GenericArgumentList(type)
  109. %>
  110. namespace XLua
  111. {
  112. public partial class ObjectTranslator
  113. {
  114. public void __Register<%=v_type_name%><%=generic_arg_list%>(RealStatePtr L) <%=type_constraints%>
  115. {
  116. System.Type type = typeof(<%=CsFullTypeName(type)%>);
  117. Utils.BeginObjectRegister(type, L, this, <%=meta_func_count%>, <%=obj_method_count%>, <%=obj_getter_count%>, <%=obj_setter_count%>);
  118. <%ForEachCsList(operators, function(operator)%>Utils.RegisterFunc(L, Utils.OBJ_META_IDX, "<%=(OpNameMap[operator.Name]):gsub('Meta', ''):lower()%>", <%=v_type_name%><%=OpNameMap[operator.Name]%><%=generic_arg_list%>);
  119. <%end)%>
  120. <%ForEachCsList(methods, function(method) if not method.IsStatic then %>Utils.RegisterFunc(L, Utils.METHOD_IDX, "<%=method.Name%>", <%=v_type_name%>_m_<%=method.Name%><%=generic_arg_list%>);
  121. <% end end)%>
  122. <%ForEachCsList(events, function(event) if not event.IsStatic then %>Utils.RegisterFunc(L, Utils.METHOD_IDX, "<%=event.Name%>", <%=v_type_name%>_e_<%=event.Name%><%=generic_arg_list%>);
  123. <% end end)%>
  124. <%ForEachCsList(getters, function(getter) if not getter.IsStatic then %>Utils.RegisterFunc(L, Utils.GETTER_IDX, "<%=getter.Name%>", <%=v_type_name%>_g_get_<%=getter.Name%><%=generic_arg_list%>);
  125. <%end end)%>
  126. <%ForEachCsList(setters, function(setter) if not setter.IsStatic then %>Utils.RegisterFunc(L, Utils.SETTER_IDX, "<%=setter.Name%>", <%=v_type_name%>_s_set_<%=setter.Name%><%=generic_arg_list%>);
  127. <%end end)%>
  128. <%ForEachCsList(lazymembers, function(lazymember) if lazymember.IsStatic == 'false' then %>Utils.RegisterLazyFunc(L, Utils.<%=lazymember.Index%>, "<%=lazymember.Name%>", type, <%=lazymember.MemberType%>, <%=lazymember.IsStatic%>);
  129. <%end end)%>
  130. Utils.EndObjectRegister(type, L, this, <% if type.IsArray or ((indexers.Count or 0) > 0) then %>__CSIndexer<%=v_type_name%><%=generic_arg_list%><%else%>null<%end%>, <%if type.IsArray or ((newindexers.Count or 0) > 0) then%>__NewIndexer<%=v_type_name%><%=generic_arg_list%><%else%>null<%end%>,
  131. null, null, null);
  132. Utils.BeginClassRegister(type, L, __CreateInstance<%=v_type_name%><%=generic_arg_list%>, <%=cls_field_count%>, <%=cls_getter_count%>, <%=cls_setter_count%>);
  133. <%ForEachCsList(methods, function(method) if method.IsStatic then %>Utils.RegisterFunc(L, Utils.CLS_IDX, "<%=method.Overloads[0].Name%>", <%=v_type_name%>_m_<%=method.Name%><%=generic_arg_list%>);
  134. <% end end)%>
  135. <%ForEachCsList(events, function(event) if event.IsStatic then %>Utils.RegisterFunc(L, Utils.CLS_IDX, "<%=event.Name%>", <%=v_type_name%>_e_<%=event.Name%><%=generic_arg_list%>);
  136. <% end end)%>
  137. <%ForEachCsList(getters, function(getter) if getter.IsStatic and getter.ReadOnly then %>Utils.RegisterObject(L, this, Utils.CLS_IDX, "<%=getter.Name%>", <%=CsFullTypeName(type).."."..getter.Name%>);
  138. <%end end)%>
  139. <%ForEachCsList(getters, function(getter) if getter.IsStatic and (not getter.ReadOnly) then %>Utils.RegisterFunc(L, Utils.CLS_GETTER_IDX, "<%=getter.Name%>", <%=v_type_name%>_g_get_<%=getter.Name%><%=generic_arg_list%>);
  140. <%end end)%>
  141. <%ForEachCsList(setters, function(setter) if setter.IsStatic then %>Utils.RegisterFunc(L, Utils.CLS_SETTER_IDX, "<%=setter.Name%>", <%=v_type_name%>_s_set_<%=setter.Name%><%=generic_arg_list%>);
  142. <%end end)%>
  143. <%ForEachCsList(lazymembers, function(lazymember) if lazymember.IsStatic == 'true' then %>Utils.RegisterLazyFunc(L, Utils.<%=lazymember.Index%>, "<%=lazymember.Name%>", type, <%=lazymember.MemberType%>, <%=lazymember.IsStatic%>);
  144. <%end end)%>
  145. Utils.EndClassRegister(type, L, this);
  146. }
  147. int __CreateInstance<%=v_type_name%><%=generic_arg_list%>(RealStatePtr L, int gen_param_count) <%=type_constraints%>
  148. {
  149. <%
  150. if constructors.Count == 0 and (not type.IsValueType) then
  151. %>return LuaAPI.luaL_error(L, "<%=CsFullTypeName(type)%> does not have a constructor!");<%
  152. else %>
  153. ObjectTranslator translator = this;
  154. <%
  155. local hasZeroParamsCtor = false
  156. ForEachCsList(constructors, function(constructor, ci)
  157. local parameters = constructor:GetParameters()
  158. if parameters.Length == 0 then
  159. hasZeroParamsCtor = true
  160. end
  161. local def_count = constructor_def_vals[ci]
  162. local param_count = parameters.Length
  163. local in_num = CalcCsList(parameters, function(p) return not (p.IsOut and p.ParameterType.IsByRef) end)
  164. local out_num = CalcCsList(parameters, function(p) return p.IsOut or p.ParameterType.IsByRef end)
  165. local real_param_count = param_count - def_count
  166. local has_v_params = param_count > 0 and IsParams(parameters[param_count - 1])
  167. local in_pos = 0
  168. %>if(gen_param_count <%=has_v_params and ">=" or "=="%> <%=in_num + 1 - def_count - (has_v_params and 1 or 0)%><%ForEachCsList(parameters, function(parameter, pi)
  169. if pi >= real_param_count then return end
  170. local parameterType = parameter.ParameterType
  171. if has_v_params and pi == param_count - 1 then parameterType = parameterType:GetElementType() end
  172. if not (parameter.IsOut and parameter.ParameterType.IsByRef) then in_pos = in_pos + 1
  173. %> && <%=GetCheckStatement(parameterType, in_pos+1, has_v_params and pi == param_count - 1)%><%
  174. end
  175. end)%>)
  176. {
  177. <%ForEachCsList(parameters, function(parameter, pi)
  178. if pi >= real_param_count then return end
  179. %><%=GetCasterStatement(parameter.ParameterType, pi+2, LocalName(parameter.Name), true, has_v_params and pi == param_count - 1)%>;
  180. <%end)%>
  181. var gen_ret = new <%=CsFullTypeName(type)%>(<%ForEachCsList(parameters, function(parameter, pi) if pi >= real_param_count then return end; if pi ~=0 then %><%=', '%><% end ;if parameter.IsOut and parameter.ParameterType.IsByRef then %>out <% elseif parameter.ParameterType.IsByRef and not parameter.IsIn then %>ref <% end %><%=LocalName(parameter.Name)%><% end)%>);
  182. <%=GetPushStatement(type, "gen_ret")%>;
  183. <%local in_pos = 0
  184. ForEachCsList(parameters, function(parameter, pi)
  185. if pi >= real_param_count then return end
  186. if not (parameter.IsOut and parameter.ParameterType.IsByRef) then
  187. in_pos = in_pos + 1
  188. end
  189. if parameter.ParameterType.IsByRef then
  190. %><%=GetPushStatement(parameter.ParameterType:GetElementType(), LocalName(parameter.Name))%>;
  191. <%if not parameter.IsOut and parameter.ParameterType.IsByRef and NeedUpdate(parameter.ParameterType) then
  192. %><%=GetUpdateStatement(parameter.ParameterType:GetElementType(), in_pos+1, LocalName(parameter.Name))%>;
  193. <%end%>
  194. <%
  195. end
  196. end)
  197. %>
  198. return <%=out_num + 1%>;
  199. }
  200. <%end)
  201. if (not hasZeroParamsCtor) and type.IsValueType then
  202. %>
  203. if (gen_param_count == 1)
  204. {
  205. <%=GetPushStatement(type, "default(" .. CsFullTypeName(type).. ")")%>;
  206. return 1;
  207. }
  208. <%end%>
  209. return LuaAPI.luaL_error(L, "invalid arguments to <%=CsFullTypeName(type)%> constructor!");
  210. <% end %>
  211. }
  212. <% if type.IsArray or ((indexers.Count or 0) > 0) then %>
  213. int __CSIndexer<%=v_type_name%><%=generic_arg_list%>(RealStatePtr L, int gen_param_count) <%=type_constraints%>
  214. {
  215. <%if type.IsArray then %>
  216. ObjectTranslator translator = this;
  217. if (<%=GetCheckStatement(type, 1)%> && LuaAPI.lua_isnumber(L, 2))
  218. {
  219. int index = (int)LuaAPI.lua_tonumber(L, 2);
  220. <%=GetSelfStatement(type)%>;
  221. LuaAPI.lua_pushboolean(L, true);
  222. <%=GetPushStatement(type:GetElementType(), "gen_to_be_invoked[index]")%>;
  223. return 2;
  224. }
  225. <%elseif indexers.Count > 0 then
  226. %>ObjectTranslator translator = this;
  227. <%
  228. ForEachCsList(indexers, function(indexer)
  229. local paramter = indexer:GetParameters()[0]
  230. %>
  231. if (<%=GetCheckStatement(type, 1)%> && <%=GetCheckStatement(paramter.ParameterType, 2)%>)
  232. {
  233. <%=GetSelfStatement(type)%>;
  234. <%=GetCasterStatement(paramter.ParameterType, 2, "index", true)%>;
  235. LuaAPI.lua_pushboolean(L, true);
  236. <%=GetPushStatement(indexer.ReturnType, "gen_to_be_invoked[index]")%>;
  237. return 2;
  238. }
  239. <%end)
  240. end%>
  241. LuaAPI.lua_pushboolean(L, false);
  242. return 1;
  243. }
  244. <% end %>
  245. <%if type.IsArray or ((newindexers.Count or 0) > 0) then%>
  246. int __NewIndexer<%=v_type_name%><%=generic_arg_list%>(RealStatePtr L, int gen_param_count) <%=type_constraints%>
  247. {
  248. <%if type.IsArray or newindexers.Count > 0 then %>ObjectTranslator translator = this;<%end%>
  249. <%if type.IsArray then
  250. local elementType = type:GetElementType()
  251. %>
  252. if (<%=GetCheckStatement(type, 1)%> && LuaAPI.lua_isnumber(L, 2) && <%=GetCheckStatement(elementType, 3)%>)
  253. {
  254. int index = (int)LuaAPI.lua_tonumber(L, 2);
  255. <%=GetSelfStatement(type)%>;
  256. <%=GetCasterStatement(elementType, 3, "gen_to_be_invoked[index]")%>;
  257. LuaAPI.lua_pushboolean(L, true);
  258. return 1;
  259. }
  260. <%elseif newindexers.Count > 0 then%>
  261. <%ForEachCsList(newindexers, function(newindexer)
  262. local keyType = newindexer:GetParameters()[0].ParameterType
  263. local valueType = newindexer:GetParameters()[1].ParameterType
  264. %>
  265. if (<%=GetCheckStatement(type, 1)%> && <%=GetCheckStatement(keyType, 2)%> && <%=GetCheckStatement(valueType, 3)%>)
  266. {
  267. <%=GetSelfStatement(type)%>;
  268. <%=GetCasterStatement(keyType, 2, "key", true)%>;
  269. <%if IsStruct(valueType) then%><%=GetCasterStatement(valueType, 3, "gen_value", true)%>;
  270. gen_to_be_invoked[key] = gen_value;<%else
  271. %><%=GetCasterStatement(valueType, 3, "gen_to_be_invoked[key]")%>;<%end%>
  272. LuaAPI.lua_pushboolean(L, true);
  273. return 1;
  274. }
  275. <%end)
  276. end%>
  277. LuaAPI.lua_pushboolean(L, false);
  278. return 1;
  279. }
  280. <% end %>
  281. <%ForEachCsList(operators, function(operator) %>
  282. int <%=v_type_name%><%=OpNameMap[operator.Name]%><%=generic_arg_list%>(RealStatePtr L, int gen_param_count) <%=type_constraints%>
  283. {
  284. ObjectTranslator translator = this;
  285. <% if operator.Name ~= "op_UnaryNegation" and operator.Name ~= "op_OnesComplement" then
  286. ForEachCsList(operator.Overloads, function(overload)
  287. local left_param = overload:GetParameters()[0]
  288. local right_param = overload:GetParameters()[1]
  289. %>
  290. if (<%=GetCheckStatement(left_param.ParameterType, 1)%> && <%=GetCheckStatement(right_param.ParameterType, 2)%>)
  291. {
  292. <%=GetCasterStatement(left_param.ParameterType, 1, "leftside", true)%>;
  293. <%=GetCasterStatement(right_param.ParameterType, 2, "rightside", true)%>;
  294. <%=GetPushStatement(overload.ReturnType, "leftside " .. OpCallNameMap[operator.Name] .. " rightside")%>;
  295. return 1;
  296. }
  297. <%end)%>
  298. return LuaAPI.luaL_error(L, "invalid arguments to right hand of <%=OpCallNameMap[operator.Name]%> operator, need <%=CsFullTypeName(type)%>!");
  299. <%else%>
  300. <%=GetCasterStatement(type, 1, "rightside", true)%>;
  301. <%=GetPushStatement(operator.Overloads[0].ReturnType, OpCallNameMap[operator.Name] .. " rightside")%>;
  302. return 1;
  303. <%end%>
  304. }
  305. <%end)%>
  306. <%ForEachCsList(methods, function(method)%>
  307. int <%=v_type_name%>_m_<%=method.Name%><%=generic_arg_list%>(RealStatePtr L, int gen_param_count) <%=type_constraints%>
  308. {
  309. <%
  310. local need_obj = not method.IsStatic
  311. if MethodCallNeedTranslator(method) then
  312. %>
  313. ObjectTranslator translator = this;
  314. <%end%>
  315. <%if need_obj then%>
  316. <%=GetSelfStatement(type)%>;
  317. <%end%>
  318. <%ForEachCsList(method.Overloads, function(overload, oi)
  319. local parameters = MethodParameters(overload)
  320. local in_num = CalcCsList(parameters, function(p) return not (p.IsOut and p.ParameterType.IsByRef) end)
  321. local param_offset = method.IsStatic and 0 or 1
  322. local out_num = CalcCsList(parameters, function(p) return p.IsOut or p.ParameterType.IsByRef end)
  323. local in_pos = 0
  324. local has_return = (overload.ReturnType.FullName ~= "System.Void")
  325. local def_count = method.DefaultValues[oi]
  326. local param_count = parameters.Length
  327. local real_param_count = param_count - def_count
  328. local has_v_params = param_count > 0 and IsParams(parameters[param_count - 1])
  329. if method.Overloads.Count > 1 then
  330. %>if(gen_param_count <%=has_v_params and ">=" or "=="%> <%=in_num+param_offset-def_count - (has_v_params and 1 or 0)%><%
  331. ForEachCsList(parameters, function(parameter, pi)
  332. if pi >= real_param_count then return end
  333. local parameterType = parameter.ParameterType
  334. if has_v_params and pi == param_count - 1 then parameterType = parameterType:GetElementType() end
  335. if not (parameter.IsOut and parameter.ParameterType.IsByRef) then in_pos = in_pos + 1;
  336. %>&& <%=GetCheckStatement(parameterType , in_pos+param_offset, has_v_params and pi == param_count - 1)%><%
  337. end
  338. end)%>) <%end%>
  339. {
  340. <%if overload.Name == "get_Item" and overload.IsSpecialName then
  341. local keyType = overload:GetParameters()[0].ParameterType%>
  342. <%=GetCasterStatement(keyType, 2, "key", true)%>;
  343. <%=GetPushStatement(overload.ReturnType, "gen_to_be_invoked[key]")%>;
  344. <%elseif overload.Name == "set_Item" and overload.IsSpecialName then
  345. local keyType = overload:GetParameters()[0].ParameterType
  346. local valueType = overload:GetParameters()[1].ParameterType%>
  347. <%=GetCasterStatement(keyType, 2, "key", true)%>;
  348. <%=GetCasterStatement(valueType, 3, "gen_to_be_invoked[key]")%>;
  349. <% else
  350. in_pos = 0;
  351. ForEachCsList(parameters, function(parameter, pi)
  352. if pi >= real_param_count then return end
  353. %><%if not (parameter.IsOut and parameter.ParameterType.IsByRef) then
  354. in_pos = in_pos + 1
  355. %><%=GetCasterStatement(parameter.ParameterType, in_pos+param_offset, LocalName(parameter.Name), true, has_v_params and pi == param_count - 1)%><%
  356. else%><%=CsFullTypeName(parameter.ParameterType)%> <%=LocalName(parameter.Name)%><%end%>;
  357. <%end)%>
  358. <%
  359. if has_return then
  360. %>var gen_ret = <%
  361. end
  362. %><%if method.IsStatic then
  363. %><%=CsFullTypeName(type).."."..UnK(overload.Name)%><%
  364. else
  365. %>gen_to_be_invoked.<%=UnK(overload.Name)%><%
  366. end%>( <%ForEachCsList(parameters, function(parameter, pi)
  367. if pi >= real_param_count then return end
  368. if pi ~= 0 then %>, <% end; if parameter.IsOut and parameter.ParameterType.IsByRef then %>out <% elseif parameter.ParameterType.IsByRef and not parameter.IsIn then %>ref <% end %><%=LocalName(parameter.Name)%><% end) %> );
  369. <%
  370. if has_return then
  371. %><%=GetPushStatement(overload.ReturnType, "gen_ret")%>;
  372. <%
  373. end
  374. local in_pos = 0
  375. ForEachCsList(parameters, function(parameter, pi)
  376. if pi >= real_param_count then return end
  377. if not (parameter.IsOut and parameter.ParameterType.IsByRef) then
  378. in_pos = in_pos + 1
  379. end
  380. if parameter.ParameterType.IsByRef then
  381. %><%=GetPushStatement(parameter.ParameterType:GetElementType(), LocalName(parameter.Name))%>;
  382. <%if not parameter.IsOut and parameter.ParameterType.IsByRef and NeedUpdate(parameter.ParameterType) then
  383. %><%=GetUpdateStatement(parameter.ParameterType:GetElementType(), in_pos+param_offset, LocalName(parameter.Name))%>;
  384. <%end%>
  385. <%
  386. end
  387. end)
  388. end
  389. %>
  390. <%if NeedUpdate(type) and not method.IsStatic then%>
  391. <%=GetUpdateStatement(type, 1, "gen_to_be_invoked")%>;
  392. <%end%>
  393. return <%=out_num+(has_return and 1 or 0)%>;
  394. }
  395. <% end)%>
  396. <%if method.Overloads.Count > 1 then%>
  397. return LuaAPI.luaL_error(L, "invalid arguments to <%=CsFullTypeName(type)%>.<%=method.Overloads[0].Name%>!");
  398. <%end%>
  399. }
  400. <% end)%>
  401. <%ForEachCsList(getters, function(getter)
  402. if getter.IsStatic and getter.ReadOnly then return end --readonly static
  403. %>
  404. int <%=v_type_name%>_g_get_<%=getter.Name%><%=generic_arg_list%>(RealStatePtr L, int gen_param_count) <%=type_constraints%>
  405. {
  406. <%if AccessorNeedTranslator(getter) then %>ObjectTranslator translator = this;<%end%>
  407. <%if not getter.IsStatic then%>
  408. <%=GetSelfStatement(type)%>;
  409. <%=GetPushStatement(getter.Type, "gen_to_be_invoked."..UnK(getter.Name))%>;<% else %> <%=GetPushStatement(getter.Type, CsFullTypeName(type).."."..UnK(getter.Name))%>;<% end%>
  410. return 1;
  411. }
  412. <%end)%>
  413. <%ForEachCsList(setters, function(setter)
  414. local is_struct = IsStruct(setter.Type)
  415. %>
  416. int <%=v_type_name%>_s_set_<%=setter.Name%><%=generic_arg_list%>(RealStatePtr L, int gen_param_count) <%=type_constraints%>
  417. {
  418. <%if AccessorNeedTranslator(setter) then %>ObjectTranslator translator = this;<%end%>
  419. <%if not setter.IsStatic then %>
  420. <%=GetSelfStatement(type)%>;
  421. <%if is_struct then %><%=GetCasterStatement(setter.Type, 2, "gen_value", true)%>;
  422. gen_to_be_invoked.<%=UnK(setter.Name)%> = gen_value;<% else
  423. %><%=GetCasterStatement(setter.Type, 2, "gen_to_be_invoked." .. UnK(setter.Name))%>;<%end
  424. else
  425. if is_struct then %><%=GetCasterStatement(setter.Type, 1, "gen_value", true)%>;
  426. <%=CsFullTypeName(type)%>.<%=UnK(setter.Name)%> = gen_value;<%else
  427. %><%=GetCasterStatement(setter.Type, 1, CsFullTypeName(type) .."." .. UnK(setter.Name))%>;<%end
  428. end%>
  429. <%if NeedUpdate(type) and not setter.IsStatic then%>
  430. <%=GetUpdateStatement(type, 1, "gen_to_be_invoked")%>;
  431. <%end%>
  432. return 0;
  433. }
  434. <%end)%>
  435. <%ForEachCsList(events, function(event) if not event.IsStatic then %>
  436. int <%=v_type_name%>_e_<%=event.Name%><%=generic_arg_list%>(RealStatePtr L, int gen_param_count) <%=type_constraints%>
  437. {
  438. ObjectTranslator translator = this;
  439. <%=GetSelfStatement(type)%>;
  440. <%=GetCasterStatement(event.Type, 3, "gen_delegate", true)%>;
  441. if (gen_delegate == null) {
  442. return LuaAPI.luaL_error(L, "#3 need <%=CsFullTypeName(event.Type)%>!");
  443. }
  444. if (gen_param_count == 3)
  445. {
  446. <%if event.CanAdd then%>
  447. if (LuaAPI.xlua_is_eq_str(L, 2, "+")) {
  448. gen_to_be_invoked.<%=UnK(event.Name)%> += gen_delegate;
  449. return 0;
  450. }
  451. <%end%>
  452. <%if event.CanRemove then%>
  453. if (LuaAPI.xlua_is_eq_str(L, 2, "-")) {
  454. gen_to_be_invoked.<%=UnK(event.Name)%> -= gen_delegate;
  455. return 0;
  456. }
  457. <%end%>
  458. }
  459. LuaAPI.luaL_error(L, "invalid arguments to <%=CsFullTypeName(type)%>.<%=event.Name%>!");
  460. return 0;
  461. }
  462. <%end end)%>
  463. <%ForEachCsList(events, function(event) if event.IsStatic then %>
  464. int <%=v_type_name%>_e_<%=event.Name%><%=generic_arg_list%>(RealStatePtr L, int gen_param_count) <%=type_constraints%>
  465. {
  466. ObjectTranslator translator = this;
  467. <%=GetCasterStatement(event.Type, 2, "gen_delegate", true)%>;
  468. if (gen_delegate == null) {
  469. return LuaAPI.luaL_error(L, "#2 need <%=CsFullTypeName(event.Type)%>!");
  470. }
  471. <%if event.CanAdd then%>
  472. if (gen_param_count == 2 && LuaAPI.xlua_is_eq_str(L, 1, "+")) {
  473. <%=CsFullTypeName(type)%>.<%=UnK(event.Name)%> += gen_delegate;
  474. return 0;
  475. }
  476. <%end%>
  477. <%if event.CanRemove then%>
  478. if (gen_param_count == 2 && LuaAPI.xlua_is_eq_str(L, 1, "-")) {
  479. <%=CsFullTypeName(type)%>.<%=UnK(event.Name)%> -= gen_delegate;
  480. return 0;
  481. }
  482. <%end%>
  483. return LuaAPI.luaL_error(L, "invalid arguments to <%=CsFullTypeName(type)%>.<%=event.Name%>!");
  484. }
  485. <%end end)%>
  486. }
  487. }