更新Xlua 到最新版本

This commit is contained in:
2024-09-04 02:07:48 +08:00
parent dba48de5cf
commit 5b79a2d4bb
227 changed files with 5594 additions and 878 deletions
Assets
Plugins
XLua.meta
XLua
CHANGELOG.txtCHANGELOG.txt.meta
Doc
Editor.meta
Editor
Gen.meta
Gen
DelegatesGensBridge.csDelegatesGensBridge.cs.metaEnumWrap.csEnumWrap.cs.metaIMarketingActRetDelBridge.cs.metaLuaMainWrap.cs.metaLuaUIBehaviourWrap.cs.metaPackUnpack.cs.metaSdkControlWrap.csSdkControlWrap.cs.metaSystem_Collections_Generic_List_1_System_Int32_Wrap.cs.metaSystem_Collections_HashtableWrap.cs.metaSystem_Collections_IEnumerableBridge.cs.metaSystem_Collections_IEnumeratorBridge.cs.metaSystem_ObjectWrap.cs.metaTableManagerLuaWrap.cs.metaTutorial_BaseClassWrap.csTutorial_BaseClassWrap.cs.metaTutorial_CSCallLua_ItfDBridge.csTutorial_CSCallLua_ItfDBridge.cs.metaTutorial_DerivedClassExtensionsWrap.csTutorial_DerivedClassExtensionsWrap.cs.metaTutorial_DerivedClassWrap.csTutorial_DerivedClassWrap.cs.metaTutorial_ICalcWrap.csTutorial_ICalcWrap.cs.metaUnityEngine_AnimationClipWrap.cs.metaUnityEngine_AnimationCurveWrap.cs.metaUnityEngine_BehaviourWrap.cs.metaUnityEngine_BoundsWrap.cs.metaUnityEngine_ColorWrap.cs.metaUnityEngine_ComponentWrap.cs.metaUnityEngine_DebugWrap.cs.metaUnityEngine_GameObjectWrap.cs.metaUnityEngine_KeyframeWrap.cs.metaUnityEngine_LightWrap.cs.metaUnityEngine_MathfWrap.cs.metaUnityEngine_MonoBehaviourWrap.cs.metaUnityEngine_ObjectWrap.cs.metaUnityEngine_ParticleSystemWrap.cs.metaUnityEngine_QuaternionWrap.cs.metaUnityEngine_Ray2DWrap.cs.metaUnityEngine_RayWrap.cs.metaUnityEngine_RendererWrap.cs.metaUnityEngine_ResourcesWrap.cs.metaUnityEngine_SkinnedMeshRendererWrap.cs.metaUnityEngine_TextAssetWrap.cs.metaUnityEngine_TimeWrap.cs.metaUnityEngine_TransformWrap.cs.metaUnityEngine_Vector2Wrap.cs.metaUnityEngine_Vector3Wrap.cs.metaUnityEngine_Vector4Wrap.cs.metaUnityEngine_WWWWrap.cs.metaWrapPusher.csWrapPusher.cs.metaXLuaGenAutoRegister.csXLuaGenAutoRegister.cs.metalink.xmllink.xml.meta
Resources
Src.meta
Src
CodeEmit.csCodeEmit.cs.metaCopyByValue.csCopyByValue.cs.metaDelegateBridge.csDelegateBridge.cs.metaEditor.meta
Editor
GenAttributes.csGenAttributes.cs.metaGenericDelegateBridge.csGenericDelegateBridge.cs.metaInternalGlobals.csInternalGlobals.cs.metaLuaBase.csLuaBase.cs.metaLuaDLL.csLuaDLL.cs.metaLuaEnv.csLuaEnv.cs.metaLuaException.csLuaException.cs.metaLuaFunction.csLuaFunction.cs.metaLuaTable.csLuaTable.cs.metaMethodWarpsCache.csMethodWarpsCache.cs.metaObjectCasters.csObjectCasters.cs.metaObjectPool.csObjectPool.cs.metaObjectTranslator.csObjectTranslator.cs.metaObjectTranslatorPool.csObjectTranslatorPool.cs.metaRawObject.csRawObject.cs.metaSignatureLoader.csSignatureLoader.cs.metaStaticLuaCallbacks.csStaticLuaCallbacks.cs.metaTemplateEngine.meta
TemplateEngine
TypeExtensions.csTypeExtensions.cs.metaUtils.csUtils.cs.meta
Tutorial.meta
Tutorial

@ -0,0 +1,589 @@
#if USE_UNI_LUA
using LuaAPI = UniLua.Lua;
using RealStatePtr = UniLua.ILuaState;
using LuaCSFunction = UniLua.CSharpFunctionDelegate;
#else
using LuaAPI = XLua.LuaDLL.Lua;
using RealStatePtr = System.IntPtr;
using LuaCSFunction = XLua.LuaDLL.lua_CSFunction;
#endif
using XLua;
using System.Collections.Generic;
<%ForEachCsList(namespaces, function(namespace)%>using <%=namespace%>;<%end)%>
<%
require "TemplateCommon"
local OpNameMap = {
op_Addition = "__AddMeta",
op_Subtraction = "__SubMeta",
op_Multiply = "__MulMeta",
op_Division = "__DivMeta",
op_Equality = "__EqMeta",
op_UnaryNegation = "__UnmMeta",
op_LessThan = "__LTMeta",
op_LessThanOrEqual = "__LEMeta",
op_Modulus = "__ModMeta",
op_BitwiseAnd = "__BandMeta",
op_BitwiseOr = "__BorMeta",
op_ExclusiveOr = "__BxorMeta",
op_OnesComplement = "__BnotMeta",
op_LeftShift = "__ShlMeta",
op_RightShift = "__ShrMeta",
}
local OpCallNameMap = {
op_Addition = "+",
op_Subtraction = "-",
op_Multiply = "*",
op_Division = "/",
op_Equality = "==",
op_UnaryNegation = "-",
op_LessThan = "<",
op_LessThanOrEqual = "<=",
op_Modulus = "%",
op_BitwiseAnd = "&",
op_BitwiseOr = "|",
op_ExclusiveOr = "^",
op_OnesComplement = "~",
op_LeftShift = "<<",
op_RightShift = ">>",
}
local obj_method_count = 0
local obj_getter_count = 0
local obj_setter_count = 0
local meta_func_count = operators.Count
local cls_field_count = 1
local cls_getter_count = 0
local cls_setter_count = 0
ForEachCsList(methods, function(method)
if method.IsStatic then
cls_field_count = cls_field_count + 1
else
obj_method_count = obj_method_count + 1
end
end)
ForEachCsList(events, function(event)
if event.IsStatic then
cls_field_count = cls_field_count + 1
else
obj_method_count = obj_method_count + 1
end
end)
ForEachCsList(getters, function(getter)
if getter.IsStatic then
if getter.ReadOnly then
cls_field_count = cls_field_count + 1
else
cls_getter_count = cls_getter_count + 1
end
else
obj_getter_count = obj_getter_count + 1
end
end)
ForEachCsList(setters, function(setter)
if setter.IsStatic then
cls_setter_count = cls_setter_count + 1
else
obj_setter_count = obj_setter_count + 1
end
end)
ForEachCsList(lazymembers, function(lazymember)
if lazymember.IsStatic == 'true' then
if 'CLS_IDX' == lazymember.Index then
cls_field_count = cls_field_count + 1
elseif 'CLS_GETTER_IDX' == lazymember.Index then
cls_getter_count = cls_getter_count + 1
elseif 'CLS_SETTER_IDX' == lazymember.Index then
cls_setter_count = cls_setter_count + 1
end
else
if 'METHOD_IDX' == lazymember.Index then
obj_method_count = obj_method_count + 1
elseif 'GETTER_IDX' == lazymember.Index then
obj_getter_count = obj_getter_count + 1
elseif 'SETTER_IDX' == lazymember.Index then
obj_setter_count = obj_setter_count + 1
end
end
end)
local generic_arg_list, type_constraints = GenericArgumentList(type)
%>
namespace XLua.CSObjectWrap
{
using Utils = XLua.Utils;
public class <%=CSVariableName(type)%>Wrap<%=generic_arg_list%> <%=type_constraints%>
{
public static void __Register(RealStatePtr L)
{
ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);
System.Type type = typeof(<%=CsFullTypeName(type)%>);
Utils.BeginObjectRegister(type, L, translator, <%=meta_func_count%>, <%=obj_method_count%>, <%=obj_getter_count%>, <%=obj_setter_count%>);
<%ForEachCsList(operators, function(operator)%>Utils.RegisterFunc(L, Utils.OBJ_META_IDX, "<%=(OpNameMap[operator.Name]):gsub('Meta', ''):lower()%>", <%=OpNameMap[operator.Name]%>);
<%end)%>
<%ForEachCsList(methods, function(method) if not method.IsStatic then %>Utils.RegisterFunc(L, Utils.METHOD_IDX, "<%=method.Name%>", _m_<%=method.Name%>);
<% end end)%>
<%ForEachCsList(events, function(event) if not event.IsStatic then %>Utils.RegisterFunc(L, Utils.METHOD_IDX, "<%=event.Name%>", _e_<%=event.Name%>);
<% end end)%>
<%ForEachCsList(getters, function(getter) if not getter.IsStatic then %>Utils.RegisterFunc(L, Utils.GETTER_IDX, "<%=getter.Name%>", _g_get_<%=getter.Name%>);
<%end end)%>
<%ForEachCsList(setters, function(setter) if not setter.IsStatic then %>Utils.RegisterFunc(L, Utils.SETTER_IDX, "<%=setter.Name%>", _s_set_<%=setter.Name%>);
<%end end)%>
<%ForEachCsList(lazymembers, function(lazymember) if lazymember.IsStatic == 'false' then %>Utils.RegisterLazyFunc(L, Utils.<%=lazymember.Index%>, "<%=lazymember.Name%>", type, <%=lazymember.MemberType%>, <%=lazymember.IsStatic%>);
<%end end)%>
Utils.EndObjectRegister(type, L, translator, <% if type.IsArray or ((indexers.Count or 0) > 0) then %>__CSIndexer<%else%>null<%end%>, <%if type.IsArray or ((newindexers.Count or 0) > 0) then%>__NewIndexer<%else%>null<%end%>,
null, null, null);
Utils.BeginClassRegister(type, L, __CreateInstance, <%=cls_field_count%>, <%=cls_getter_count%>, <%=cls_setter_count%>);
<%ForEachCsList(methods, function(method) if method.IsStatic then %>Utils.RegisterFunc(L, Utils.CLS_IDX, "<%=method.Overloads[0].Name%>", _m_<%=method.Name%>);
<% end end)%>
<%ForEachCsList(events, function(event) if event.IsStatic then %>Utils.RegisterFunc(L, Utils.CLS_IDX, "<%=event.Name%>", _e_<%=event.Name%>);
<% end end)%>
<%ForEachCsList(getters, function(getter) if getter.IsStatic and getter.ReadOnly then %>Utils.RegisterObject(L, translator, Utils.CLS_IDX, "<%=getter.Name%>", <%=CsFullTypeName(type).."."..getter.Name%>);
<%end end)%>
<%ForEachCsList(getters, function(getter) if getter.IsStatic and (not getter.ReadOnly) then %>Utils.RegisterFunc(L, Utils.CLS_GETTER_IDX, "<%=getter.Name%>", _g_get_<%=getter.Name%>);
<%end end)%>
<%ForEachCsList(setters, function(setter) if setter.IsStatic then %>Utils.RegisterFunc(L, Utils.CLS_SETTER_IDX, "<%=setter.Name%>", _s_set_<%=setter.Name%>);
<%end end)%>
<%ForEachCsList(lazymembers, function(lazymember) if lazymember.IsStatic == 'true' then %>Utils.RegisterLazyFunc(L, Utils.<%=lazymember.Index%>, "<%=lazymember.Name%>", type, <%=lazymember.MemberType%>, <%=lazymember.IsStatic%>);
<%end end)%>
Utils.EndClassRegister(type, L, translator);
}
[MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
static int __CreateInstance(RealStatePtr L)
{
<%
if constructors.Count == 0 and (not type.IsValueType) then
%>return LuaAPI.luaL_error(L, "<%=CsFullTypeName(type)%> does not have a constructor!");<%
else %>
try {
ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);
<%
local hasZeroParamsCtor = false
ForEachCsList(constructors, function(constructor, ci)
local parameters = constructor:GetParameters()
if parameters.Length == 0 then
hasZeroParamsCtor = true
end
local def_count = constructor_def_vals[ci]
local param_count = parameters.Length
local in_num = CalcCsList(parameters, function(p) return not (p.IsOut and p.ParameterType.IsByRef) end)
local out_num = CalcCsList(parameters, function(p) return p.IsOut or p.ParameterType.IsByRef end)
local real_param_count = param_count - def_count
local has_v_params = param_count > 0 and IsParams(parameters[param_count - 1])
local in_pos = 0
%>if(LuaAPI.lua_gettop(L) <%=has_v_params and ">=" or "=="%> <%=in_num + 1 - def_count - (has_v_params and 1 or 0)%><%ForEachCsList(parameters, function(parameter, pi)
if pi >= real_param_count then return end
local parameterType = parameter.ParameterType
if has_v_params and pi == param_count - 1 then parameterType = parameterType:GetElementType() end
if not (parameter.IsOut and parameter.ParameterType.IsByRef) then in_pos = in_pos + 1
%> && <%=GetCheckStatement(parameterType, in_pos+1, has_v_params and pi == param_count - 1)%><%
end
end)%>)
{
<%ForEachCsList(parameters, function(parameter, pi)
if pi >= real_param_count then return end
%><%=GetCasterStatement(parameter.ParameterType, pi+2, LocalName(parameter.Name), true, has_v_params and pi == param_count - 1)%>;
<%end)%>
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)%>);
<%=GetPushStatement(type, "gen_ret")%>;
<%local in_pos = 0
ForEachCsList(parameters, function(parameter, pi)
if pi >= real_param_count then return end
if not (parameter.IsOut and parameter.ParameterType.IsByRef) then
in_pos = in_pos + 1
end
if parameter.ParameterType.IsByRef then
%><%=GetPushStatement(parameter.ParameterType:GetElementType(), LocalName(parameter.Name))%>;
<%if not parameter.IsOut and parameter.ParameterType.IsByRef and NeedUpdate(parameter.ParameterType) then
%><%=GetUpdateStatement(parameter.ParameterType:GetElementType(), in_pos+1, LocalName(parameter.Name))%>;
<%end%>
<%
end
end)
%>
return <%=out_num + 1%>;
}
<%end)
if (not hasZeroParamsCtor) and type.IsValueType then
%>
if (LuaAPI.lua_gettop(L) == 1)
{
<%=GetPushStatement(type, "default(" .. CsFullTypeName(type).. ")")%>;
return 1;
}
<%end%>
}
catch(System.Exception gen_e) {
return LuaAPI.luaL_error(L, "c# exception:" + gen_e);
}
return LuaAPI.luaL_error(L, "invalid arguments to <%=CsFullTypeName(type)%> constructor!");
<% end %>
}
<% if type.IsArray or ((indexers.Count or 0) > 0) then %>
[MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
public static int __CSIndexer(RealStatePtr L)
{
<%if type.IsArray then %>
try {
ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);
if (<%=GetCheckStatement(type, 1)%> && LuaAPI.lua_isnumber(L, 2))
{
int index = (int)LuaAPI.lua_tonumber(L, 2);
<%=GetSelfStatement(type)%>;
LuaAPI.lua_pushboolean(L, true);
<%=GetPushStatement(type:GetElementType(), "gen_to_be_invoked[index]")%>;
return 2;
}
}
catch(System.Exception gen_e) {
return LuaAPI.luaL_error(L, "c# exception:" + gen_e);
}
<%elseif indexers.Count > 0 then
%>try {
ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);
<%
ForEachCsList(indexers, function(indexer)
local paramter = indexer:GetParameters()[0]
%>
if (<%=GetCheckStatement(type, 1)%> && <%=GetCheckStatement(paramter.ParameterType, 2)%>)
{
<%=GetSelfStatement(type)%>;
<%=GetCasterStatement(paramter.ParameterType, 2, "index", true)%>;
LuaAPI.lua_pushboolean(L, true);
<%=GetPushStatement(indexer.ReturnType, "gen_to_be_invoked[index]")%>;
return 2;
}
<%end)%>
}
catch(System.Exception gen_e) {
return LuaAPI.luaL_error(L, "c# exception:" + gen_e);
}
<%end%>
LuaAPI.lua_pushboolean(L, false);
return 1;
}
<% end %>
<%if type.IsArray or ((newindexers.Count or 0) > 0) then%>
[MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
public static int __NewIndexer(RealStatePtr L)
{
<%if type.IsArray or newindexers.Count > 0 then %>ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);<%end%>
<%if type.IsArray then
local elementType = type:GetElementType()
%>
try {
if (<%=GetCheckStatement(type, 1)%> && LuaAPI.lua_isnumber(L, 2) && <%=GetCheckStatement(elementType, 3)%>)
{
int index = (int)LuaAPI.lua_tonumber(L, 2);
<%=GetSelfStatement(type)%>;
<%=GetCasterStatement(elementType, 3, "gen_to_be_invoked[index]")%>;
LuaAPI.lua_pushboolean(L, true);
return 1;
}
}
catch(System.Exception gen_e) {
return LuaAPI.luaL_error(L, "c# exception:" + gen_e);
}
<%elseif newindexers.Count > 0 then%>
try {
<%ForEachCsList(newindexers, function(newindexer)
local keyType = newindexer:GetParameters()[0].ParameterType
local valueType = newindexer:GetParameters()[1].ParameterType
%>
if (<%=GetCheckStatement(type, 1)%> && <%=GetCheckStatement(keyType, 2)%> && <%=GetCheckStatement(valueType, 3)%>)
{
<%=GetSelfStatement(type)%>;
<%=GetCasterStatement(keyType, 2, "key", true)%>;
<%if IsStruct(valueType) then%><%=GetCasterStatement(valueType, 3, "gen_value", true)%>;
gen_to_be_invoked[key] = gen_value;<%else
%><%=GetCasterStatement(valueType, 3, "gen_to_be_invoked[key]")%>;<%end%>
LuaAPI.lua_pushboolean(L, true);
return 1;
}
<%end)%>
}
catch(System.Exception gen_e) {
return LuaAPI.luaL_error(L, "c# exception:" + gen_e);
}
<%end%>
LuaAPI.lua_pushboolean(L, false);
return 1;
}
<% end %>
<%ForEachCsList(operators, function(operator) %>
[MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
static int <%=OpNameMap[operator.Name]%>(RealStatePtr L)
{
<% if operator.Name ~= "op_UnaryNegation" and operator.Name ~= "op_OnesComplement" then %>
try {
ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);
<%ForEachCsList(operator.Overloads, function(overload)
local left_param = overload:GetParameters()[0]
local right_param = overload:GetParameters()[1]
%>
if (<%=GetCheckStatement(left_param.ParameterType, 1)%> && <%=GetCheckStatement(right_param.ParameterType, 2)%>)
{
<%=GetCasterStatement(left_param.ParameterType, 1, "leftside", true)%>;
<%=GetCasterStatement(right_param.ParameterType, 2, "rightside", true)%>;
<%=GetPushStatement(overload.ReturnType, "leftside " .. OpCallNameMap[operator.Name] .. " rightside")%>;
return 1;
}
<%end)%>
}
catch(System.Exception gen_e) {
return LuaAPI.luaL_error(L, "c# exception:" + gen_e);
}
return LuaAPI.luaL_error(L, "invalid arguments to right hand of <%=OpCallNameMap[operator.Name]%> operator, need <%=CsFullTypeName(type)%>!");
<%else%>
ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);
try {
<%=GetCasterStatement(type, 1, "rightside", true)%>;
<%=GetPushStatement(operator.Overloads[0].ReturnType, OpCallNameMap[operator.Name] .. " rightside")%>;
} catch(System.Exception gen_e) {
return LuaAPI.luaL_error(L, "c# exception:" + gen_e);
}
return 1;
<%end%>
}
<%end)%>
<%ForEachCsList(methods, function(method)%>
[MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
static int _m_<%=method.Name%>(RealStatePtr L)
{
try {
<%
local need_obj = not method.IsStatic
if MethodCallNeedTranslator(method) then
%>
ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);
<%end%>
<%if need_obj then%>
<%=GetSelfStatement(type)%>;
<%end%>
<%if method.Overloads.Count > 1 then%>
int gen_param_count = LuaAPI.lua_gettop(L);
<%end%>
<%ForEachCsList(method.Overloads, function(overload, oi)
local parameters = MethodParameters(overload)
local in_num = CalcCsList(parameters, function(p) return not (p.IsOut and p.ParameterType.IsByRef) end)
local param_offset = method.IsStatic and 0 or 1
local out_num = CalcCsList(parameters, function(p) return p.IsOut or p.ParameterType.IsByRef end)
local in_pos = 0
local has_return = (overload.ReturnType.FullName ~= "System.Void")
local def_count = method.DefaultValues[oi]
local param_count = parameters.Length
local real_param_count = param_count - def_count
local has_v_params = param_count > 0 and IsParams(parameters[param_count - 1])
if method.Overloads.Count > 1 then
%>if(gen_param_count <%=has_v_params and ">=" or "=="%> <%=in_num+param_offset-def_count - (has_v_params and 1 or 0)%><%
ForEachCsList(parameters, function(parameter, pi)
if pi >= real_param_count then return end
local parameterType = parameter.ParameterType
if has_v_params and pi == param_count - 1 then parameterType = parameterType:GetElementType() end
if not (parameter.IsOut and parameter.ParameterType.IsByRef) then in_pos = in_pos + 1;
%>&& <%=GetCheckStatement(parameterType , in_pos+param_offset, has_v_params and pi == param_count - 1)%><%
end
end)%>) <%end%>
{
<%if overload.Name == "get_Item" and overload.IsSpecialName then
local keyType = overload:GetParameters()[0].ParameterType%>
<%=GetCasterStatement(keyType, 2, "key", true)%>;
<%=GetPushStatement(overload.ReturnType, "gen_to_be_invoked[key]")%>;
<%elseif overload.Name == "set_Item" and overload.IsSpecialName then
local keyType = overload:GetParameters()[0].ParameterType
local valueType = overload:GetParameters()[1].ParameterType%>
<%=GetCasterStatement(keyType, 2, "key", true)%>;
<%=GetCasterStatement(valueType, 3, "gen_value", true)%>;
gen_to_be_invoked[key] = gen_value;
<% else
in_pos = 0;
ForEachCsList(parameters, function(parameter, pi)
if pi >= real_param_count then return end
%><%if not (parameter.IsOut and parameter.ParameterType.IsByRef) then
in_pos = in_pos + 1
%><%=GetCasterStatement(parameter.ParameterType, in_pos+param_offset, LocalName(parameter.Name), true, has_v_params and pi == param_count - 1)%><%
else%><%=CsFullTypeName(parameter.ParameterType)%> <%=LocalName(parameter.Name)%><%end%>;
<%end)%>
<%
if has_return then
%> var gen_ret = <%
end
%><%if method.IsStatic then
%><%=CsFullTypeName(type).."."..UnK(overload.Name)%><%
else
%>gen_to_be_invoked.<%=UnK(overload.Name)%><%
end%>( <%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) %> );
<%
if has_return then
%> <%=GetPushStatement(overload.ReturnType, "gen_ret")%>;
<%
end
local in_pos = 0
ForEachCsList(parameters, function(parameter, pi)
if pi >= real_param_count then return end
if not (parameter.IsOut and parameter.ParameterType.IsByRef) then
in_pos = in_pos + 1
end
if parameter.ParameterType.IsByRef then
%><%=GetPushStatement(parameter.ParameterType:GetElementType(), LocalName(parameter.Name))%>;
<%if not parameter.IsOut and parameter.ParameterType.IsByRef and NeedUpdate(parameter.ParameterType) then
%><%=GetUpdateStatement(parameter.ParameterType:GetElementType(), in_pos+param_offset, LocalName(parameter.Name))%>;
<%end%>
<%
end
end)
end
%>
<%if NeedUpdate(type) and not method.IsStatic then%>
<%=GetUpdateStatement(type, 1, "gen_to_be_invoked")%>;
<%end%>
return <%=out_num+(has_return and 1 or 0)%>;
}
<% end)%>
} catch(System.Exception gen_e) {
return LuaAPI.luaL_error(L, "c# exception:" + gen_e);
}
<%if method.Overloads.Count > 1 then%>
return LuaAPI.luaL_error(L, "invalid arguments to <%=CsFullTypeName(type)%>.<%=method.Overloads[0].Name%>!");
<%end%>
}
<% end)%>
<%ForEachCsList(getters, function(getter)
if getter.IsStatic and getter.ReadOnly then return end --readonly static
%>
[MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
static int _g_get_<%=getter.Name%>(RealStatePtr L)
{
try {
<%if AccessorNeedTranslator(getter) then %> ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);<%end%>
<%if not getter.IsStatic then%>
<%=GetSelfStatement(type)%>;
<%=GetPushStatement(getter.Type, "gen_to_be_invoked."..UnK(getter.Name))%>;<% else %> <%=GetPushStatement(getter.Type, CsFullTypeName(type).."."..UnK(getter.Name))%>;<% end%>
} catch(System.Exception gen_e) {
return LuaAPI.luaL_error(L, "c# exception:" + gen_e);
}
return 1;
}
<%end)%>
<%ForEachCsList(setters, function(setter)
local is_struct = IsStruct(setter.Type)
%>
[MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
static int _s_set_<%=setter.Name%>(RealStatePtr L)
{
try {
<%if AccessorNeedTranslator(setter) then %>ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);<%end%>
<%if not setter.IsStatic then %>
<%=GetSelfStatement(type)%>;
<%if is_struct then %><%=GetCasterStatement(setter.Type, 2, "gen_value", true)%>;
gen_to_be_invoked.<%=UnK(setter.Name)%> = gen_value;<% else
%><%=GetCasterStatement(setter.Type, 2, "gen_to_be_invoked." .. UnK(setter.Name))%>;<%end
else
if is_struct then %><%=GetCasterStatement(setter.Type, 1, "gen_value", true)%>;
<%=CsFullTypeName(type)%>.<%=UnK(setter.Name)%> = gen_value;<%else
%> <%=GetCasterStatement(setter.Type, 1, CsFullTypeName(type) .."." .. UnK(setter.Name))%>;<%end
end%>
<%if NeedUpdate(type) and not setter.IsStatic then%>
<%=GetUpdateStatement(type, 1, "gen_to_be_invoked")%>;
<%end%>
} catch(System.Exception gen_e) {
return LuaAPI.luaL_error(L, "c# exception:" + gen_e);
}
return 0;
}
<%end)%>
<%ForEachCsList(events, function(event) if not event.IsStatic then %>
[MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
static int _e_<%=event.Name%>(RealStatePtr L)
{
try {
ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);
int gen_param_count = LuaAPI.lua_gettop(L);
<%=GetSelfStatement(type)%>;
<%=GetCasterStatement(event.Type, 3, "gen_delegate", true)%>;
if (gen_delegate == null) {
return LuaAPI.luaL_error(L, "#3 need <%=CsFullTypeName(event.Type)%>!");
}
if (gen_param_count == 3)
{
<%if event.CanAdd then%>
if (LuaAPI.xlua_is_eq_str(L, 2, "+")) {
gen_to_be_invoked.<%=UnK(event.Name)%> += gen_delegate;
return 0;
}
<%end%>
<%if event.CanRemove then%>
if (LuaAPI.xlua_is_eq_str(L, 2, "-")) {
gen_to_be_invoked.<%=UnK(event.Name)%> -= gen_delegate;
return 0;
}
<%end%>
}
} catch(System.Exception gen_e) {
return LuaAPI.luaL_error(L, "c# exception:" + gen_e);
}
LuaAPI.luaL_error(L, "invalid arguments to <%=CsFullTypeName(type)%>.<%=event.Name%>!");
return 0;
}
<%end end)%>
<%ForEachCsList(events, function(event) if event.IsStatic then %>
[MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
static int _e_<%=event.Name%>(RealStatePtr L)
{
try {
ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);
int gen_param_count = LuaAPI.lua_gettop(L);
<%=GetCasterStatement(event.Type, 2, "gen_delegate", true)%>;
if (gen_delegate == null) {
return LuaAPI.luaL_error(L, "#2 need <%=CsFullTypeName(event.Type)%>!");
}
<%if event.CanAdd then%>
if (gen_param_count == 2 && LuaAPI.xlua_is_eq_str(L, 1, "+")) {
<%=CsFullTypeName(type)%>.<%=UnK(event.Name)%> += gen_delegate;
return 0;
}
<%end%>
<%if event.CanRemove then%>
if (gen_param_count == 2 && LuaAPI.xlua_is_eq_str(L, 1, "-")) {
<%=CsFullTypeName(type)%>.<%=UnK(event.Name)%> -= gen_delegate;
return 0;
}
<%end%>
} catch(System.Exception gen_e) {
return LuaAPI.luaL_error(L, "c# exception:" + gen_e);
}
return LuaAPI.luaL_error(L, "invalid arguments to <%=CsFullTypeName(type)%>.<%=event.Name%>!");
}
<%end end)%>
}
}

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 8503038eabbabe44dac0f5f749d4411a
timeCreated: 1481620508
licenseType: Pro
TextScriptImporter:
userData:
assetBundleName:
assetBundleVariant:

@ -0,0 +1,517 @@
#if USE_UNI_LUA
using LuaAPI = UniLua.Lua;
using RealStatePtr = UniLua.ILuaState;
using LuaCSFunction = UniLua.CSharpFunctionDelegate;
#else
using LuaAPI = XLua.LuaDLL.Lua;
using RealStatePtr = System.IntPtr;
using LuaCSFunction = XLua.LuaDLL.lua_CSFunction;
#endif
using XLua;
using System.Collections.Generic;
<%ForEachCsList(namespaces, function(namespace)%>using <%=namespace%>;<%end)%>
<%
require "TemplateCommon"
local OpNameMap = {
op_Addition = "__AddMeta",
op_Subtraction = "__SubMeta",
op_Multiply = "__MulMeta",
op_Division = "__DivMeta",
op_Equality = "__EqMeta",
op_UnaryNegation = "__UnmMeta",
op_LessThan = "__LTMeta",
op_LessThanOrEqual = "__LEMeta",
op_Modulus = "__ModMeta",
op_BitwiseAnd = "__BandMeta",
op_BitwiseOr = "__BorMeta",
op_ExclusiveOr = "__BxorMeta",
op_OnesComplement = "__BnotMeta",
op_LeftShift = "__ShlMeta",
op_RightShift = "__ShrMeta",
}
local OpCallNameMap = {
op_Addition = "+",
op_Subtraction = "-",
op_Multiply = "*",
op_Division = "/",
op_Equality = "==",
op_UnaryNegation = "-",
op_LessThan = "<",
op_LessThanOrEqual = "<=",
op_Modulus = "%",
op_BitwiseAnd = "&",
op_BitwiseOr = "|",
op_ExclusiveOr = "^",
op_OnesComplement = "~",
op_LeftShift = "<<",
op_RightShift = ">>",
}
local obj_method_count = 0
local obj_getter_count = 0
local obj_setter_count = 0
local meta_func_count = operators.Count
local cls_field_count = 1
local cls_getter_count = 0
local cls_setter_count = 0
ForEachCsList(methods, function(method)
if method.IsStatic then
cls_field_count = cls_field_count + 1
else
obj_method_count = obj_method_count + 1
end
end)
ForEachCsList(events, function(event)
if event.IsStatic then
cls_field_count = cls_field_count + 1
else
obj_method_count = obj_method_count + 1
end
end)
ForEachCsList(getters, function(getter)
if getter.IsStatic then
if getter.ReadOnly then
cls_field_count = cls_field_count + 1
else
cls_getter_count = cls_getter_count + 1
end
else
obj_getter_count = obj_getter_count + 1
end
end)
ForEachCsList(setters, function(setter)
if setter.IsStatic then
cls_setter_count = cls_setter_count + 1
else
obj_setter_count = obj_setter_count + 1
end
end)
ForEachCsList(lazymembers, function(lazymember)
if lazymember.IsStatic == 'true' then
if 'CLS_IDX' == lazymember.Index then
cls_field_count = cls_field_count + 1
elseif 'CLS_GETTER_IDX' == lazymember.Index then
cls_getter_count = cls_getter_count + 1
elseif 'CLS_SETTER_IDX' == lazymember.Index then
cls_setter_count = cls_setter_count + 1
end
else
if 'METHOD_IDX' == lazymember.Index then
obj_method_count = obj_method_count + 1
elseif 'GETTER_IDX' == lazymember.Index then
obj_getter_count = obj_getter_count + 1
elseif 'SETTER_IDX' == lazymember.Index then
obj_setter_count = obj_setter_count + 1
end
end
end)
local v_type_name = CSVariableName(type)
local generic_arg_list, type_constraints = GenericArgumentList(type)
%>
namespace XLua
{
public partial class ObjectTranslator
{
public void __Register<%=v_type_name%><%=generic_arg_list%>(RealStatePtr L) <%=type_constraints%>
{
System.Type type = typeof(<%=CsFullTypeName(type)%>);
Utils.BeginObjectRegister(type, L, this, <%=meta_func_count%>, <%=obj_method_count%>, <%=obj_getter_count%>, <%=obj_setter_count%>);
<%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%>);
<%end)%>
<%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%>);
<% end end)%>
<%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%>);
<% end end)%>
<%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%>);
<%end end)%>
<%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%>);
<%end end)%>
<%ForEachCsList(lazymembers, function(lazymember) if lazymember.IsStatic == 'false' then %>Utils.RegisterLazyFunc(L, Utils.<%=lazymember.Index%>, "<%=lazymember.Name%>", type, <%=lazymember.MemberType%>, <%=lazymember.IsStatic%>);
<%end end)%>
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%>,
null, null, null);
Utils.BeginClassRegister(type, L, __CreateInstance<%=v_type_name%><%=generic_arg_list%>, <%=cls_field_count%>, <%=cls_getter_count%>, <%=cls_setter_count%>);
<%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%>);
<% end end)%>
<%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%>);
<% end end)%>
<%ForEachCsList(getters, function(getter) if getter.IsStatic and getter.ReadOnly then %>Utils.RegisterObject(L, this, Utils.CLS_IDX, "<%=getter.Name%>", <%=CsFullTypeName(type).."."..getter.Name%>);
<%end end)%>
<%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%>);
<%end end)%>
<%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%>);
<%end end)%>
<%ForEachCsList(lazymembers, function(lazymember) if lazymember.IsStatic == 'true' then %>Utils.RegisterLazyFunc(L, Utils.<%=lazymember.Index%>, "<%=lazymember.Name%>", type, <%=lazymember.MemberType%>, <%=lazymember.IsStatic%>);
<%end end)%>
Utils.EndClassRegister(type, L, this);
}
int __CreateInstance<%=v_type_name%><%=generic_arg_list%>(RealStatePtr L, int gen_param_count) <%=type_constraints%>
{
<%
if constructors.Count == 0 and (not type.IsValueType) then
%>return LuaAPI.luaL_error(L, "<%=CsFullTypeName(type)%> does not have a constructor!");<%
else %>
ObjectTranslator translator = this;
<%
local hasZeroParamsCtor = false
ForEachCsList(constructors, function(constructor, ci)
local parameters = constructor:GetParameters()
if parameters.Length == 0 then
hasZeroParamsCtor = true
end
local def_count = constructor_def_vals[ci]
local param_count = parameters.Length
local in_num = CalcCsList(parameters, function(p) return not (p.IsOut and p.ParameterType.IsByRef) end)
local out_num = CalcCsList(parameters, function(p) return p.IsOut or p.ParameterType.IsByRef end)
local real_param_count = param_count - def_count
local has_v_params = param_count > 0 and IsParams(parameters[param_count - 1])
local in_pos = 0
%>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)
if pi >= real_param_count then return end
local parameterType = parameter.ParameterType
if has_v_params and pi == param_count - 1 then parameterType = parameterType:GetElementType() end
if not (parameter.IsOut and parameter.ParameterType.IsByRef) then in_pos = in_pos + 1
%> && <%=GetCheckStatement(parameterType, in_pos+1, has_v_params and pi == param_count - 1)%><%
end
end)%>)
{
<%ForEachCsList(parameters, function(parameter, pi)
if pi >= real_param_count then return end
%><%=GetCasterStatement(parameter.ParameterType, pi+2, LocalName(parameter.Name), true, has_v_params and pi == param_count - 1)%>;
<%end)%>
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)%>);
<%=GetPushStatement(type, "gen_ret")%>;
<%local in_pos = 0
ForEachCsList(parameters, function(parameter, pi)
if pi >= real_param_count then return end
if not (parameter.IsOut and parameter.ParameterType.IsByRef) then
in_pos = in_pos + 1
end
if parameter.ParameterType.IsByRef then
%><%=GetPushStatement(parameter.ParameterType:GetElementType(), LocalName(parameter.Name))%>;
<%if not parameter.IsOut and parameter.ParameterType.IsByRef and NeedUpdate(parameter.ParameterType) then
%><%=GetUpdateStatement(parameter.ParameterType:GetElementType(), in_pos+1, LocalName(parameter.Name))%>;
<%end%>
<%
end
end)
%>
return <%=out_num + 1%>;
}
<%end)
if (not hasZeroParamsCtor) and type.IsValueType then
%>
if (gen_param_count == 1)
{
<%=GetPushStatement(type, "default(" .. CsFullTypeName(type).. ")")%>;
return 1;
}
<%end%>
return LuaAPI.luaL_error(L, "invalid arguments to <%=CsFullTypeName(type)%> constructor!");
<% end %>
}
<% if type.IsArray or ((indexers.Count or 0) > 0) then %>
int __CSIndexer<%=v_type_name%><%=generic_arg_list%>(RealStatePtr L, int gen_param_count) <%=type_constraints%>
{
<%if type.IsArray then %>
ObjectTranslator translator = this;
if (<%=GetCheckStatement(type, 1)%> && LuaAPI.lua_isnumber(L, 2))
{
int index = (int)LuaAPI.lua_tonumber(L, 2);
<%=GetSelfStatement(type)%>;
LuaAPI.lua_pushboolean(L, true);
<%=GetPushStatement(type:GetElementType(), "gen_to_be_invoked[index]")%>;
return 2;
}
<%elseif indexers.Count > 0 then
%>ObjectTranslator translator = this;
<%
ForEachCsList(indexers, function(indexer)
local paramter = indexer:GetParameters()[0]
%>
if (<%=GetCheckStatement(type, 1)%> && <%=GetCheckStatement(paramter.ParameterType, 2)%>)
{
<%=GetSelfStatement(type)%>;
<%=GetCasterStatement(paramter.ParameterType, 2, "index", true)%>;
LuaAPI.lua_pushboolean(L, true);
<%=GetPushStatement(indexer.ReturnType, "gen_to_be_invoked[index]")%>;
return 2;
}
<%end)
end%>
LuaAPI.lua_pushboolean(L, false);
return 1;
}
<% end %>
<%if type.IsArray or ((newindexers.Count or 0) > 0) then%>
int __NewIndexer<%=v_type_name%><%=generic_arg_list%>(RealStatePtr L, int gen_param_count) <%=type_constraints%>
{
<%if type.IsArray or newindexers.Count > 0 then %>ObjectTranslator translator = this;<%end%>
<%if type.IsArray then
local elementType = type:GetElementType()
%>
if (<%=GetCheckStatement(type, 1)%> && LuaAPI.lua_isnumber(L, 2) && <%=GetCheckStatement(elementType, 3)%>)
{
int index = (int)LuaAPI.lua_tonumber(L, 2);
<%=GetSelfStatement(type)%>;
<%=GetCasterStatement(elementType, 3, "gen_to_be_invoked[index]")%>;
LuaAPI.lua_pushboolean(L, true);
return 1;
}
<%elseif newindexers.Count > 0 then%>
<%ForEachCsList(newindexers, function(newindexer)
local keyType = newindexer:GetParameters()[0].ParameterType
local valueType = newindexer:GetParameters()[1].ParameterType
%>
if (<%=GetCheckStatement(type, 1)%> && <%=GetCheckStatement(keyType, 2)%> && <%=GetCheckStatement(valueType, 3)%>)
{
<%=GetSelfStatement(type)%>;
<%=GetCasterStatement(keyType, 2, "key", true)%>;
<%if IsStruct(valueType) then%><%=GetCasterStatement(valueType, 3, "gen_value", true)%>;
gen_to_be_invoked[key] = gen_value;<%else
%><%=GetCasterStatement(valueType, 3, "gen_to_be_invoked[key]")%>;<%end%>
LuaAPI.lua_pushboolean(L, true);
return 1;
}
<%end)
end%>
LuaAPI.lua_pushboolean(L, false);
return 1;
}
<% end %>
<%ForEachCsList(operators, function(operator) %>
int <%=v_type_name%><%=OpNameMap[operator.Name]%><%=generic_arg_list%>(RealStatePtr L, int gen_param_count) <%=type_constraints%>
{
ObjectTranslator translator = this;
<% if operator.Name ~= "op_UnaryNegation" and operator.Name ~= "op_OnesComplement" then
ForEachCsList(operator.Overloads, function(overload)
local left_param = overload:GetParameters()[0]
local right_param = overload:GetParameters()[1]
%>
if (<%=GetCheckStatement(left_param.ParameterType, 1)%> && <%=GetCheckStatement(right_param.ParameterType, 2)%>)
{
<%=GetCasterStatement(left_param.ParameterType, 1, "leftside", true)%>;
<%=GetCasterStatement(right_param.ParameterType, 2, "rightside", true)%>;
<%=GetPushStatement(overload.ReturnType, "leftside " .. OpCallNameMap[operator.Name] .. " rightside")%>;
return 1;
}
<%end)%>
return LuaAPI.luaL_error(L, "invalid arguments to right hand of <%=OpCallNameMap[operator.Name]%> operator, need <%=CsFullTypeName(type)%>!");
<%else%>
<%=GetCasterStatement(type, 1, "rightside", true)%>;
<%=GetPushStatement(operator.Overloads[0].ReturnType, OpCallNameMap[operator.Name] .. " rightside")%>;
return 1;
<%end%>
}
<%end)%>
<%ForEachCsList(methods, function(method)%>
int <%=v_type_name%>_m_<%=method.Name%><%=generic_arg_list%>(RealStatePtr L, int gen_param_count) <%=type_constraints%>
{
<%
local need_obj = not method.IsStatic
if MethodCallNeedTranslator(method) then
%>
ObjectTranslator translator = this;
<%end%>
<%if need_obj then%>
<%=GetSelfStatement(type)%>;
<%end%>
<%ForEachCsList(method.Overloads, function(overload, oi)
local parameters = MethodParameters(overload)
local in_num = CalcCsList(parameters, function(p) return not (p.IsOut and p.ParameterType.IsByRef) end)
local param_offset = method.IsStatic and 0 or 1
local out_num = CalcCsList(parameters, function(p) return p.IsOut or p.ParameterType.IsByRef end)
local in_pos = 0
local has_return = (overload.ReturnType.FullName ~= "System.Void")
local def_count = method.DefaultValues[oi]
local param_count = parameters.Length
local real_param_count = param_count - def_count
local has_v_params = param_count > 0 and IsParams(parameters[param_count - 1])
if method.Overloads.Count > 1 then
%>if(gen_param_count <%=has_v_params and ">=" or "=="%> <%=in_num+param_offset-def_count - (has_v_params and 1 or 0)%><%
ForEachCsList(parameters, function(parameter, pi)
if pi >= real_param_count then return end
local parameterType = parameter.ParameterType
if has_v_params and pi == param_count - 1 then parameterType = parameterType:GetElementType() end
if not (parameter.IsOut and parameter.ParameterType.IsByRef) then in_pos = in_pos + 1;
%>&& <%=GetCheckStatement(parameterType , in_pos+param_offset, has_v_params and pi == param_count - 1)%><%
end
end)%>) <%end%>
{
<%if overload.Name == "get_Item" and overload.IsSpecialName then
local keyType = overload:GetParameters()[0].ParameterType%>
<%=GetCasterStatement(keyType, 2, "key", true)%>;
<%=GetPushStatement(overload.ReturnType, "gen_to_be_invoked[key]")%>;
<%elseif overload.Name == "set_Item" and overload.IsSpecialName then
local keyType = overload:GetParameters()[0].ParameterType
local valueType = overload:GetParameters()[1].ParameterType%>
<%=GetCasterStatement(keyType, 2, "key", true)%>;
<%=GetCasterStatement(valueType, 3, "gen_to_be_invoked[key]")%>;
<% else
in_pos = 0;
ForEachCsList(parameters, function(parameter, pi)
if pi >= real_param_count then return end
%><%if not (parameter.IsOut and parameter.ParameterType.IsByRef) then
in_pos = in_pos + 1
%><%=GetCasterStatement(parameter.ParameterType, in_pos+param_offset, LocalName(parameter.Name), true, has_v_params and pi == param_count - 1)%><%
else%><%=CsFullTypeName(parameter.ParameterType)%> <%=LocalName(parameter.Name)%><%end%>;
<%end)%>
<%
if has_return then
%>var gen_ret = <%
end
%><%if method.IsStatic then
%><%=CsFullTypeName(type).."."..UnK(overload.Name)%><%
else
%>gen_to_be_invoked.<%=UnK(overload.Name)%><%
end%>( <%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) %> );
<%
if has_return then
%><%=GetPushStatement(overload.ReturnType, "gen_ret")%>;
<%
end
local in_pos = 0
ForEachCsList(parameters, function(parameter, pi)
if pi >= real_param_count then return end
if not (parameter.IsOut and parameter.ParameterType.IsByRef) then
in_pos = in_pos + 1
end
if parameter.ParameterType.IsByRef then
%><%=GetPushStatement(parameter.ParameterType:GetElementType(), LocalName(parameter.Name))%>;
<%if not parameter.IsOut and parameter.ParameterType.IsByRef and NeedUpdate(parameter.ParameterType) then
%><%=GetUpdateStatement(parameter.ParameterType:GetElementType(), in_pos+param_offset, LocalName(parameter.Name))%>;
<%end%>
<%
end
end)
end
%>
<%if NeedUpdate(type) and not method.IsStatic then%>
<%=GetUpdateStatement(type, 1, "gen_to_be_invoked")%>;
<%end%>
return <%=out_num+(has_return and 1 or 0)%>;
}
<% end)%>
<%if method.Overloads.Count > 1 then%>
return LuaAPI.luaL_error(L, "invalid arguments to <%=CsFullTypeName(type)%>.<%=method.Overloads[0].Name%>!");
<%end%>
}
<% end)%>
<%ForEachCsList(getters, function(getter)
if getter.IsStatic and getter.ReadOnly then return end --readonly static
%>
int <%=v_type_name%>_g_get_<%=getter.Name%><%=generic_arg_list%>(RealStatePtr L, int gen_param_count) <%=type_constraints%>
{
<%if AccessorNeedTranslator(getter) then %>ObjectTranslator translator = this;<%end%>
<%if not getter.IsStatic then%>
<%=GetSelfStatement(type)%>;
<%=GetPushStatement(getter.Type, "gen_to_be_invoked."..UnK(getter.Name))%>;<% else %> <%=GetPushStatement(getter.Type, CsFullTypeName(type).."."..UnK(getter.Name))%>;<% end%>
return 1;
}
<%end)%>
<%ForEachCsList(setters, function(setter)
local is_struct = IsStruct(setter.Type)
%>
int <%=v_type_name%>_s_set_<%=setter.Name%><%=generic_arg_list%>(RealStatePtr L, int gen_param_count) <%=type_constraints%>
{
<%if AccessorNeedTranslator(setter) then %>ObjectTranslator translator = this;<%end%>
<%if not setter.IsStatic then %>
<%=GetSelfStatement(type)%>;
<%if is_struct then %><%=GetCasterStatement(setter.Type, 2, "gen_value", true)%>;
gen_to_be_invoked.<%=UnK(setter.Name)%> = gen_value;<% else
%><%=GetCasterStatement(setter.Type, 2, "gen_to_be_invoked." .. UnK(setter.Name))%>;<%end
else
if is_struct then %><%=GetCasterStatement(setter.Type, 1, "gen_value", true)%>;
<%=CsFullTypeName(type)%>.<%=UnK(setter.Name)%> = gen_value;<%else
%><%=GetCasterStatement(setter.Type, 1, CsFullTypeName(type) .."." .. UnK(setter.Name))%>;<%end
end%>
<%if NeedUpdate(type) and not setter.IsStatic then%>
<%=GetUpdateStatement(type, 1, "gen_to_be_invoked")%>;
<%end%>
return 0;
}
<%end)%>
<%ForEachCsList(events, function(event) if not event.IsStatic then %>
int <%=v_type_name%>_e_<%=event.Name%><%=generic_arg_list%>(RealStatePtr L, int gen_param_count) <%=type_constraints%>
{
ObjectTranslator translator = this;
<%=GetSelfStatement(type)%>;
<%=GetCasterStatement(event.Type, 3, "gen_delegate", true)%>;
if (gen_delegate == null) {
return LuaAPI.luaL_error(L, "#3 need <%=CsFullTypeName(event.Type)%>!");
}
if (gen_param_count == 3)
{
<%if event.CanAdd then%>
if (LuaAPI.xlua_is_eq_str(L, 2, "+")) {
gen_to_be_invoked.<%=UnK(event.Name)%> += gen_delegate;
return 0;
}
<%end%>
<%if event.CanRemove then%>
if (LuaAPI.xlua_is_eq_str(L, 2, "-")) {
gen_to_be_invoked.<%=UnK(event.Name)%> -= gen_delegate;
return 0;
}
<%end%>
}
LuaAPI.luaL_error(L, "invalid arguments to <%=CsFullTypeName(type)%>.<%=event.Name%>!");
return 0;
}
<%end end)%>
<%ForEachCsList(events, function(event) if event.IsStatic then %>
int <%=v_type_name%>_e_<%=event.Name%><%=generic_arg_list%>(RealStatePtr L, int gen_param_count) <%=type_constraints%>
{
ObjectTranslator translator = this;
<%=GetCasterStatement(event.Type, 2, "gen_delegate", true)%>;
if (gen_delegate == null) {
return LuaAPI.luaL_error(L, "#2 need <%=CsFullTypeName(event.Type)%>!");
}
<%if event.CanAdd then%>
if (gen_param_count == 2 && LuaAPI.xlua_is_eq_str(L, 1, "+")) {
<%=CsFullTypeName(type)%>.<%=UnK(event.Name)%> += gen_delegate;
return 0;
}
<%end%>
<%if event.CanRemove then%>
if (gen_param_count == 2 && LuaAPI.xlua_is_eq_str(L, 1, "-")) {
<%=CsFullTypeName(type)%>.<%=UnK(event.Name)%> -= gen_delegate;
return 0;
}
<%end%>
return LuaAPI.luaL_error(L, "invalid arguments to <%=CsFullTypeName(type)%>.<%=event.Name%>!");
}
<%end end)%>
}
}

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 2bd79d95fd859724283926ad8fa4df30
timeCreated: 1501232428
licenseType: Pro
TextScriptImporter:
userData:
assetBundleName:
assetBundleVariant:

@ -0,0 +1,104 @@
#if USE_UNI_LUA
using LuaAPI = UniLua.Lua;
using RealStatePtr = UniLua.ILuaState;
using LuaCSFunction = UniLua.CSharpFunctionDelegate;
#else
using LuaAPI = XLua.LuaDLL.Lua;
using RealStatePtr = System.IntPtr;
using LuaCSFunction = XLua.LuaDLL.lua_CSFunction;
#endif
using System;
<%
require "TemplateCommon"
%>
namespace XLua
{
public partial class DelegateBridge : DelegateBridgeBase
{
<%
ForEachCsList(delegates_groups, function(delegates_group, group_idx)
local delegate = delegates_group.Key
local parameters = delegate:GetParameters()
local in_num = CalcCsList(parameters, function(p) return not (p.IsOut and p.ParameterType.IsByRef) end)
local out_num = CalcCsList(parameters, function(p) return p.IsOut or p.ParameterType.IsByRef end)
local in_pos = 0
local has_return = (delegate.ReturnType.FullName ~= "System.Void")
local return_type_name = has_return and CsFullTypeName(delegate.ReturnType) or "void"
local out_idx = has_return and 2 or 1
if has_return then out_num = out_num + 1 end
%>
public <%=return_type_name%> __Gen_Delegate_Imp<%=group_idx%>(<%ForEachCsList(parameters, function(parameter, pi)
if pi ~= 0 then
%>, <%
end
if parameter.IsOut and parameter.ParameterType.IsByRef then
%>out <%
elseif parameter.ParameterType.IsByRef then
%>ref <%
end
%><%=CsFullTypeName(parameter.ParameterType)%> p<%=pi%><%
end) %>)
{
#if THREAD_SAFE || HOTFIX_ENABLE
lock (luaEnv.luaEnvLock)
{
#endif
RealStatePtr L = luaEnv.rawL;
int errFunc = LuaAPI.pcall_prepare(L, errorFuncRef, luaReference);
<%if CallNeedTranslator(delegate, "") then %>ObjectTranslator translator = luaEnv.translator;<%end%>
<%
local param_count = parameters.Length
local has_v_params = param_count > 0 and parameters[param_count - 1].IsParamArray
ForEachCsList(parameters, function(parameter, pi)
if not (parameter.IsOut and parameter.ParameterType.IsByRef) then
%><%=GetPushStatement(parameter.ParameterType, 'p' .. pi, has_v_params and pi == param_count - 1)%>;
<%
end
end) %>
PCall(L, <%=has_v_params and ((in_num - 1) .. " + (p".. (param_count - 1) .. " == null ? 0 : p" .. (param_count - 1) .. ".Length)" ) or in_num%>, <%=out_num%>, errFunc);
<%ForEachCsList(parameters, function(parameter, pi)
if parameter.IsOut or parameter.ParameterType.IsByRef then
%><%=GetCasterStatement(parameter.ParameterType, "errFunc" .. (" + "..out_idx), 'p' .. pi)%>;
<%
out_idx = out_idx + 1
end
end) %>
<%if has_return then %><%=GetCasterStatement(delegate.ReturnType, "errFunc + 1", "__gen_ret", true)%>;<% end%>
LuaAPI.lua_settop(L, errFunc - 1);
<%if has_return then %>return __gen_ret;<% end%>
#if THREAD_SAFE || HOTFIX_ENABLE
}
#endif
}
<%end)%>
static DelegateBridge()
{
Gen_Flag = true;
}
public override Delegate GetDelegateByType(Type type)
{
<%
ForEachCsList(delegates_groups, function(delegates_group, group_idx)
ForEachCsList(delegates_group.Value, function(delegate)
if delegate.DeclaringType then
local delegate_type_name = CsFullTypeName(delegate.DeclaringType)
%>
if (type == typeof(<%=delegate_type_name%>))
{
return new <%=delegate_type_name%>(__Gen_Delegate_Imp<%=group_idx%>);
}
<%
end
end)
end)
%>
return null;
}
}
}

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 3d992756e2469044484be75f78e4e556
timeCreated: 1481620508
licenseType: Pro
TextScriptImporter:
userData:
assetBundleName:
assetBundleVariant:

@ -0,0 +1,128 @@
#if USE_UNI_LUA
using LuaAPI = UniLua.Lua;
using RealStatePtr = UniLua.ILuaState;
using LuaCSFunction = UniLua.CSharpFunctionDelegate;
#else
using LuaAPI = XLua.LuaDLL.Lua;
using RealStatePtr = System.IntPtr;
using LuaCSFunction = XLua.LuaDLL.lua_CSFunction;
#endif
using XLua;
using System.Collections.Generic;
<%
require "TemplateCommon"
local parameters = delegate:GetParameters()
local in_num = CalcCsList(parameters, function(p) return not (p.IsOut and p.ParameterType.IsByRef) end)
local out_num = CalcCsList(parameters, function(p) return p.IsOut or p.ParameterType.IsByRef end)
local in_pos = 0
local has_return = (delegate.ReturnType.Name ~= "Void")
%>
namespace XLua.CSObjectWrap
{
using Utils = XLua.Utils;
public class <%=CSVariableName(type)%>Wrap
{
public static void __Register(RealStatePtr L)
{
ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);
Utils.BeginObjectRegister(typeof(<%=CsFullTypeName(type)%>), L, translator, 0, 0, 0, 0);
Utils.EndObjectRegister(typeof(<%=CsFullTypeName(type)%>), L, translator, null, null, null, null, null);
Utils.BeginClassRegister(typeof(<%=CsFullTypeName(type)%>), L, null, 1, 0, 0);
Utils.EndClassRegister(typeof(<%=CsFullTypeName(type)%>), L, translator);
}
static Dictionary<string, LuaCSFunction> __MetaFucntions_Dic = new Dictionary<string, LuaCSFunction>(){
{"__call", __CallMeta},
{"__add", __AddMeta},
{"__sub", __SubMeta},
};
[MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
static int __CallMeta(RealStatePtr L)
{
ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);
try {
if(LuaAPI.lua_gettop(L) == <%=in_num+1%> && <%=GetCheckStatement(type, 1)%><%
ForEachCsList(parameters, function(parameter)
if not (parameter.IsOut and parameter.ParameterType.IsByRef) then in_pos = in_pos + 1;
%>&& <%=GetCheckStatement(parameter.ParameterType, in_pos+1)%><%
end
end)%>)
{
<%
in_pos = 0;
ForEachCsList(parameters, function(parameter)
%><%
if not (parameter.IsOut and parameter.ParameterType.IsByRef) then
in_pos = in_pos + 1
%><%=GetCasterStatement(parameter.ParameterType, in_pos+1, parameter.Name, true)%><%
else%><%=CsFullTypeName(parameter.ParameterType)%> <%=parameter.Name%><%end%>;
<%end)%>
<%=GetSelfStatement(type)%>;
<%
if has_return then
%> var __cl_gen_ret = <%
end
%> __cl_gen_to_be_invoked( <%ForEachCsList(parameters, function(parameter, pi) if pi ~= 0 then %>, <% end; if parameter.IsOut then %>out <% elseif parameter.ParameterType.IsByRef then %>ref <% end %><%=parameter.Name%><% end) %> );
<%
if has_return then
%> <%=GetPushStatement(delegate.ReturnType, "__cl_gen_ret")%>;
<%
end
local in_pos = 0
ForEachCsList(parameters, function(parameter)
if not (parameter.IsOut and parameter.ParameterType.IsByRef) then
in_pos = in_pos + 1
end
if parameter.IsOut or parameter.ParameterType.IsByRef then
%><%=GetPushStatement(parameter.ParameterType:GetElementType(), parameter.Name)%>;
<%if not parameter.IsOut and parameter.ParameterType.IsByRef and NeedUpdate(parameter.ParameterType) then
%><%=GetUpdateStatement(parameter.ParameterType:GetElementType(), in_pos+param_offset, parameter.Name)%>;
<%end%>
<%
end
end)
%>
return <%=out_num+(has_return and 1 or 0)%>;
}
} catch(System.Exception __gen_e) {
return LuaAPI.luaL_error(L, "c# exception:" + __gen_e);
}
return LuaAPI.luaL_error(L, "invalid arguments to Delegate <%=CsFullTypeName(type)%>!");
}
[MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
static int __AddMeta(RealStatePtr L)
{
ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);
try {
<%=GetCasterStatement(type, 1, "leftside", true)%>;
<%=GetCasterStatement(type, 2, "rightside", true)%>;
<%=GetPushStatement(type, "leftside + rightside")%>;
return 1;
} catch(System.Exception __gen_e) {
return LuaAPI.luaL_error(L, "c# exception:" + __gen_e);
}
}
[MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
static int __SubMeta(RealStatePtr L)
{
ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);
try {
<%=GetCasterStatement(type, 1, "leftside", true)%>;
<%=GetCasterStatement(type, 2, "rightside", true)%>;
<%=GetPushStatement(type, "leftside - rightside")%>;
return 1;
} catch(System.Exception __gen_e) {
return LuaAPI.luaL_error(L, "c# exception:" + __gen_e);
}
}
}
}

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 33b33e1cd617f794b8c801a32f3b2539
timeCreated: 1481620508
licenseType: Pro
TextScriptImporter:
userData:
assetBundleName:
assetBundleVariant:

@ -0,0 +1,102 @@
#if USE_UNI_LUA
using LuaAPI = UniLua.Lua;
using RealStatePtr = UniLua.ILuaState;
using LuaCSFunction = UniLua.CSharpFunctionDelegate;
#else
using LuaAPI = XLua.LuaDLL.Lua;
using RealStatePtr = System.IntPtr;
using LuaCSFunction = XLua.LuaDLL.lua_CSFunction;
#endif
using XLua;
using System.Collections.Generic;
<%
require "TemplateCommon"
local enum_or_op = debug.getmetatable(CS.System.Reflection.BindingFlags.Public).__bor
%>
namespace XLua.CSObjectWrap
{
using Utils = XLua.Utils;
<%ForEachCsList(types, function(type)
local fields = type2fields and type2fields[type] or type:GetFields(enum_or_op(CS.System.Reflection.BindingFlags.Public, CS.System.Reflection.BindingFlags.Static))
local fields_to_gen = {}
ForEachCsList(fields, function(field)
if field.Name ~= "value__" and not IsObsolute(field) then
table.insert(fields_to_gen, field)
end
end)
%>
public class <%=CSVariableName(type)%>Wrap
{
public static void __Register(RealStatePtr L)
{
ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);
Utils.BeginObjectRegister(typeof(<%=CsFullTypeName(type)%>), L, translator, 0, 0, 0, 0);
Utils.EndObjectRegister(typeof(<%=CsFullTypeName(type)%>), L, translator, null, null, null, null, null);
Utils.BeginClassRegister(typeof(<%=CsFullTypeName(type)%>), L, null, <%=fields.Length + 1%>, 0, 0);
<%if #fields_to_gen <= 20 then%>
<% ForEachCsList(fields, function(field)
if field.Name == "value__" or IsObsolute(field) then return end
%>
Utils.RegisterObject(L, translator, Utils.CLS_IDX, "<%=field.Name%>", <%=CsFullTypeName(type)%>.<%=UnK(field.Name)%>);
<%end)%>
<%else%>
Utils.RegisterEnumType(L, typeof(<%=CsFullTypeName(type)%>));
<%end%>
Utils.RegisterFunc(L, Utils.CLS_IDX, "__CastFrom", __CastFrom);
Utils.EndClassRegister(typeof(<%=CsFullTypeName(type)%>), L, translator);
}
[MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
static int __CastFrom(RealStatePtr L)
{
ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);
LuaTypes lua_type = LuaAPI.lua_type(L, 1);
if (lua_type == LuaTypes.LUA_TNUMBER)
{
translator.Push<%=CSVariableName(type)%>(L, (<%=CsFullTypeName(type)%>)LuaAPI.xlua_tointeger(L, 1));
}
<%if #fields_to_gen > 0 then%>
else if(lua_type == LuaTypes.LUA_TSTRING)
{
<%if #fields_to_gen <= 20 then%>
<%
local is_first = true
ForEachCsList(fields, function(field, i)
if field.Name == "value__" or IsObsolute(field) then return end
%><%=(is_first and "" or "else ")%>if (LuaAPI.xlua_is_eq_str(L, 1, "<%=field.Name%>"))
{
translator.Push<%=CSVariableName(type)%>(L, <%=CsFullTypeName(type)%>.<%=UnK(field.Name)%>);
}
<%
is_first = false
end)
%>else
{
return LuaAPI.luaL_error(L, "invalid string for <%=CsFullTypeName(type)%>!");
}
<%else%>
try
{
translator.TranslateToEnumToTop(L, typeof(<%=CsFullTypeName(type)%>), 1);
}
catch (System.Exception e)
{
return LuaAPI.luaL_error(L, "cast to " + typeof(<%=CsFullTypeName(type)%>) + " exception:" + e);
}
<%end%>
}
<%end%>
else
{
return LuaAPI.luaL_error(L, "invalid lua type for <%=CsFullTypeName(type)%>! Expect number or string, got + " + lua_type);
}
return 1;
}
}
<%end)%>
}

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: ae16c73aad9a21a44aef65decb7e4928
timeCreated: 1481620508
licenseType: Pro
TextScriptImporter:
userData:
assetBundleName:
assetBundleVariant:

@ -0,0 +1,99 @@
#if USE_UNI_LUA
using LuaAPI = UniLua.Lua;
using RealStatePtr = UniLua.ILuaState;
using LuaCSFunction = UniLua.CSharpFunctionDelegate;
#else
using LuaAPI = XLua.LuaDLL.Lua;
using RealStatePtr = System.IntPtr;
using LuaCSFunction = XLua.LuaDLL.lua_CSFunction;
#endif
using XLua;
using System.Collections.Generic;
<%
require "TemplateCommon"
local enum_or_op = debug.getmetatable(CS.System.Reflection.BindingFlags.Public).__bor
%>
namespace XLua
{
public partial class ObjectTranslator
{
<%ForEachCsList(types, function(type)
local fields = type2fields and type2fields[type] or type:GetFields(enum_or_op(CS.System.Reflection.BindingFlags.Public, CS.System.Reflection.BindingFlags.Static))
local fields_to_gen = {}
ForEachCsList(fields, function(field)
if field.Name ~= "value__" and not IsObsolute(field) then
table.insert(fields_to_gen, field)
end
end)
local v_type_name = CSVariableName(type)
%>
public void __Register<%=v_type_name%>(RealStatePtr L)
{
Utils.BeginObjectRegister(typeof(<%=CsFullTypeName(type)%>), L, this, 0, 0, 0, 0);
Utils.EndObjectRegister(typeof(<%=CsFullTypeName(type)%>), L, this, null, null, null, null, null);
Utils.BeginClassRegister(typeof(<%=CsFullTypeName(type)%>), L, null, <%=fields.Length + 1%>, 0, 0);
<%if #fields_to_gen <= 20 then%>
<% ForEachCsList(fields, function(field)
if field.Name == "value__" or IsObsolute(field) then return end
%>
Utils.RegisterObject(L, this, Utils.CLS_IDX, "<%=field.Name%>", <%=CsFullTypeName(type)%>.<%=UnK(field.Name)%>);
<%end)%>
<%else%>
Utils.RegisterEnumType(L, typeof(<%=CsFullTypeName(type)%>));
<%end%>
Utils.RegisterFunc(L, Utils.CLS_IDX, "__CastFrom", __CastFrom<%=v_type_name%>);
Utils.EndClassRegister(typeof(<%=CsFullTypeName(type)%>), L, this);
}
int __CastFrom<%=v_type_name%>(RealStatePtr L, int __gen_top)
{
LuaTypes lua_type = LuaAPI.lua_type(L, 1);
if (lua_type == LuaTypes.LUA_TNUMBER)
{
Push<%=v_type_name%>(L, (<%=CsFullTypeName(type)%>)LuaAPI.xlua_tointeger(L, 1));
}
<%if #fields_to_gen > 0 then%>
else if(lua_type == LuaTypes.LUA_TSTRING)
{
<%if #fields_to_gen <= 20 then%>
<%
local is_first = true
ForEachCsList(fields, function(field, i)
if field.Name == "value__" or IsObsolute(field) then return end
%><%=(is_first and "" or "else ")%>if (LuaAPI.xlua_is_eq_str(L, 1, "<%=field.Name%>"))
{
Push<%=v_type_name%>(L, <%=CsFullTypeName(type)%>.<%=UnK(field.Name)%>);
}
<%
is_first = false
end)
%>else
{
return LuaAPI.luaL_error(L, "invalid string for <%=CsFullTypeName(type)%>!");
}
<%else%>
try
{
TranslateToEnumToTop(L, typeof(<%=CsFullTypeName(type)%>), 1);
}
catch (System.Exception e)
{
return LuaAPI.luaL_error(L, "cast to " + typeof(<%=CsFullTypeName(type)%>) + " exception:" + e);
}
<%end%>
}
<%end%>
else
{
return LuaAPI.luaL_error(L, "invalid lua type for <%=CsFullTypeName(type)%>! Expect number or string, got + " + lua_type);
}
return 1;
}
<%end)%>
}
}

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: ea84a5ee7abf8e347a810eb7848add46
timeCreated: 1501232428
licenseType: Pro
TextScriptImporter:
userData:
assetBundleName:
assetBundleVariant:

@ -0,0 +1,385 @@
#if USE_UNI_LUA
using LuaAPI = UniLua.Lua;
using RealStatePtr = UniLua.ILuaState;
using LuaCSFunction = UniLua.CSharpFunctionDelegate;
#else
using LuaAPI = XLua.LuaDLL.Lua;
using RealStatePtr = System.IntPtr;
using LuaCSFunction = XLua.LuaDLL.lua_CSFunction;
#endif
using XLua;
using System;
<%
require "TemplateCommon"
%>
namespace XLua.CSObjectWrap
{
public class <%=CSVariableName(type)%>Bridge : LuaBase, <%=CsFullTypeName(type)%>
{
public static LuaBase __Create(int reference, LuaEnv luaenv)
{
return new <%=CSVariableName(type)%>Bridge(reference, luaenv);
}
public <%=CSVariableName(type)%>Bridge(int reference, LuaEnv luaenv) : base(reference, luaenv)
{
}
<%
ForEachCsList(methods, function(method)
local parameters = method:GetParameters()
local in_num = CalcCsList(parameters, function(p) return not (p.IsOut and p.ParameterType.IsByRef) end)
local out_num = CalcCsList(parameters, function(p) return p.IsOut or p.ParameterType.IsByRef end)
local in_pos = 0
local has_return = (method.ReturnType.FullName ~= "System.Void")
local return_type_name = has_return and CsFullTypeName(method.ReturnType) or "void"
local out_idx = has_return and 2 or 1
if has_return then out_num = out_num + 1 end
%>
<%=return_type_name%> <%=CsFullTypeName(method.DeclaringType)%>.<%=method.Name%>(<%ForEachCsList(parameters, function(parameter, pi)
if pi ~= 0 then
%>, <%
end
if parameter.IsOut and parameter.ParameterType.IsByRef then
%>out <%
elseif parameter.ParameterType.IsByRef then
%>ref <%
end
%><%=CsFullTypeName(parameter.ParameterType)%> <%=parameter.Name%><%
end) %>)
{
#if THREAD_SAFE || HOTFIX_ENABLE
lock (luaEnv.luaEnvLock)
{
#endif
RealStatePtr L = luaEnv.L;
int err_func = LuaAPI.load_error_func(L, luaEnv.errorFuncRef);
<%if CallNeedTranslator(method, "") then %>ObjectTranslator translator = luaEnv.translator;<%end%>
LuaAPI.lua_getref(L, luaReference);
LuaAPI.xlua_pushasciistring(L, "<%=method.Name%>");
if (0 != LuaAPI.xlua_pgettable(L, -2))
{
luaEnv.ThrowExceptionFromError(err_func - 1);
}
if(!LuaAPI.lua_isfunction(L, -1))
{
LuaAPI.xlua_pushasciistring(L, "no such function <%=method.Name%>");
luaEnv.ThrowExceptionFromError(err_func - 1);
}
LuaAPI.lua_pushvalue(L, -2);
LuaAPI.lua_remove(L, -3);
<%
local param_count = parameters.Length
local has_v_params = param_count > 0 and IsParams(parameters[param_count - 1])
ForEachCsList(parameters, function(parameter, pi)
if not (parameter.IsOut and parameter.ParameterType.IsByRef) then
%><%=GetPushStatement(parameter.ParameterType, parameter.Name, has_v_params and pi == param_count - 1)%>;
<%
end
end) %>
int __gen_error = LuaAPI.lua_pcall(L, <%=has_v_params and ((in_num) .. " + (".. parameters[param_count - 1].Name .. " == null ? 0 : " .. parameters[param_count - 1].Name .. ".Length)" ) or (in_num + 1)%>, <%=out_num%>, err_func);
if (__gen_error != 0)
luaEnv.ThrowExceptionFromError(err_func - 1);
<%ForEachCsList(parameters, function(parameter)
if parameter.IsOut or parameter.ParameterType.IsByRef then
%><%=GetCasterStatement(parameter.ParameterType, "err_func" .. (" + "..out_idx), parameter.Name)%>;
<%
out_idx = out_idx + 1
end
end) %>
<%if has_return then %><%=GetCasterStatement(method.ReturnType, "err_func + 1", "__gen_ret", true)%>;<% end%>
LuaAPI.lua_settop(L, err_func - 1);
<%if has_return then %>return __gen_ret;<% end%>
#if THREAD_SAFE || HOTFIX_ENABLE
}
#endif
}
<%end)%>
<%
ForEachCsList(propertys, function(property)
%>
<%=CsFullTypeName(property.PropertyType)%> <%=CsFullTypeName(property.DeclaringType)%>.<%=property.Name%>
{
<%if property.CanRead then%>
get
{
#if THREAD_SAFE || HOTFIX_ENABLE
lock (luaEnv.luaEnvLock)
{
#endif
RealStatePtr L = luaEnv.L;
int oldTop = LuaAPI.lua_gettop(L);
<%if not JustLuaType(property.PropertyType) then %>ObjectTranslator translator = luaEnv.translator;<%end%>
LuaAPI.lua_getref(L, luaReference);
LuaAPI.xlua_pushasciistring(L, "<%=property.Name%>");
if (0 != LuaAPI.xlua_pgettable(L, -2))
{
luaEnv.ThrowExceptionFromError(oldTop);
}
<%=GetCasterStatement(property.PropertyType, "-1", "__gen_ret", true)%>;
LuaAPI.lua_pop(L, 2);
return __gen_ret;
#if THREAD_SAFE || HOTFIX_ENABLE
}
#endif
}
<%end%>
<%if property.CanWrite then%>
set
{
#if THREAD_SAFE || HOTFIX_ENABLE
lock (luaEnv.luaEnvLock)
{
#endif
RealStatePtr L = luaEnv.L;
int oldTop = LuaAPI.lua_gettop(L);
<%if not JustLuaType(property.PropertyType) then %>ObjectTranslator translator = luaEnv.translator;<%end%>
LuaAPI.lua_getref(L, luaReference);
LuaAPI.xlua_pushasciistring(L, "<%=property.Name%>");
<%=GetPushStatement(property.PropertyType, "value")%>;
if (0 != LuaAPI.xlua_psettable(L, -3))
{
luaEnv.ThrowExceptionFromError(oldTop);
}
LuaAPI.lua_pop(L, 1);
#if THREAD_SAFE || HOTFIX_ENABLE
}
#endif
}
<%end%>
}
<%end)%>
<%ForEachCsList(events, function(event) %>
event <%=CsFullTypeName(event.EventHandlerType)%> <%=CsFullTypeName(event.DeclaringType)%>.<%=event.Name%>
{<%local parameters = event:GetAddMethod():GetParameters()%>
add
{
#if THREAD_SAFE || HOTFIX_ENABLE
lock (luaEnv.luaEnvLock)
{
#endif
RealStatePtr L = luaEnv.L;
int err_func = LuaAPI.load_error_func(L, luaEnv.errorFuncRef);
<%if CallNeedTranslator(event:GetAddMethod(), "") then %>ObjectTranslator translator = luaEnv.translator;<%end%>
LuaAPI.lua_getref(L, luaReference);
LuaAPI.xlua_pushasciistring(L, "add_<%=event.Name%>");
if (0 != LuaAPI.xlua_pgettable(L, -2))
{
luaEnv.ThrowExceptionFromError(err_func - 1);
}
if(!LuaAPI.lua_isfunction(L, -1))
{
LuaAPI.xlua_pushasciistring(L, "no such function add_<%=event.Name%>");
luaEnv.ThrowExceptionFromError(err_func - 1);
}
LuaAPI.lua_pushvalue(L, -2);
LuaAPI.lua_remove(L, -3);
<%
local param_count = parameters.Length
local has_v_params = param_count > 0 and IsParams(parameters[param_count - 1])
ForEachCsList(parameters, function(parameter, pi)
if not (parameter.IsOut and parameter.ParameterType.IsByRef) then
%><%=GetPushStatement(parameter.ParameterType, parameter.Name, has_v_params and pi == param_count - 1)%>;
<%
end
end) %>
int __gen_error = LuaAPI.lua_pcall(L, 2, 0, err_func);
if (__gen_error != 0)
luaEnv.ThrowExceptionFromError(err_func - 1);
LuaAPI.lua_settop(L, err_func - 1);
#if THREAD_SAFE || HOTFIX_ENABLE
}
#endif
}
remove
{
#if THREAD_SAFE || HOTFIX_ENABLE
lock (luaEnv.luaEnvLock)
{
#endif
RealStatePtr L = luaEnv.L;
int err_func = LuaAPI.load_error_func(L, luaEnv.errorFuncRef);
<%if CallNeedTranslator(event:GetRemoveMethod(), "") then %>ObjectTranslator translator = luaEnv.translator;<%end%>
LuaAPI.lua_getref(L, luaReference);
LuaAPI.xlua_pushasciistring(L, "remove_<%=event.Name%>");
if (0 != LuaAPI.xlua_pgettable(L, -2))
{
luaEnv.ThrowExceptionFromError(err_func - 1);
}
if(!LuaAPI.lua_isfunction(L, -1))
{
LuaAPI.xlua_pushasciistring(L, "no such function remove_<%=event.Name%>");
luaEnv.ThrowExceptionFromError(err_func - 1);
}
LuaAPI.lua_pushvalue(L, -2);
LuaAPI.lua_remove(L, -3);
<%
local param_count = parameters.Length
local has_v_params = param_count > 0 and IsParams(parameters[param_count - 1])
ForEachCsList(parameters, function(parameter, pi)
if not (parameter.IsOut and parameter.ParameterType.IsByRef) then
%><%=GetPushStatement(parameter.ParameterType, parameter.Name, has_v_params and pi == param_count - 1)%>;
<%
end
end) %>
int __gen_error = LuaAPI.lua_pcall(L, 2, 0, err_func);
if (__gen_error != 0)
luaEnv.ThrowExceptionFromError(err_func - 1);
LuaAPI.lua_settop(L, err_func - 1);
#if THREAD_SAFE || HOTFIX_ENABLE
}
#endif
}
}
<%end)%>
<%ForEachCsList(indexers, function(indexer)
local ptype = (indexer:GetGetMethod() or indexer:GetSetMethod()):GetParameters()[0].ParameterType
local pname = (indexer:GetGetMethod() or indexer:GetSetMethod()):GetParameters()[0].Name
%>
<%=CsFullTypeName(indexer.PropertyType)%> <%=CsFullTypeName(indexer.DeclaringType)%>.this[<%=CsFullTypeName(ptype)%> <%=pname%>]
{<%if indexer:GetGetMethod() then
local method = indexer:GetGetMethod()
local parameters = method:GetParameters()
local in_num = CalcCsList(parameters, function(p) return not (p.IsOut and p.ParameterType.IsByRef) end)
local out_num = CalcCsList(parameters, function(p) return p.IsOut or p.ParameterType.IsByRef end)
local in_pos = 0
local has_return = (method.ReturnType.FullName ~= "System.Void")
local return_type_name = has_return and CsFullTypeName(method.ReturnType) or "void"
local out_idx = has_return and 2 or 1
if has_return then out_num = out_num + 1 end
%>
get
{
#if THREAD_SAFE || HOTFIX_ENABLE
lock (luaEnv.luaEnvLock)
{
#endif
RealStatePtr L = luaEnv.L;
int err_func = LuaAPI.load_error_func(L, luaEnv.errorFuncRef);
<%if CallNeedTranslator(method, "") then %>ObjectTranslator translator = luaEnv.translator;<%end%>
LuaAPI.lua_getref(L, luaReference);
LuaAPI.xlua_pushasciistring(L, "<%=method.Name%>");
if (0 != LuaAPI.xlua_pgettable(L, -2))
{
luaEnv.ThrowExceptionFromError(err_func - 1);
}
if(!LuaAPI.lua_isfunction(L, -1))
{
LuaAPI.xlua_pushasciistring(L, "no such function <%=method.Name%>");
luaEnv.ThrowExceptionFromError(err_func - 1);
}
LuaAPI.lua_pushvalue(L, -2);
LuaAPI.lua_remove(L, -3);
<%
local param_count = parameters.Length
local has_v_params = param_count > 0 and IsParams(parameters[param_count - 1])
ForEachCsList(parameters, function(parameter, pi)
if not (parameter.IsOut and parameter.ParameterType.IsByRef) then
%><%=GetPushStatement(parameter.ParameterType, parameter.Name, has_v_params and pi == param_count - 1)%>;
<%
end
end) %>
int __gen_error = LuaAPI.lua_pcall(L, <%=has_v_params and ((in_num) .. " + " .. parameters[param_count - 1].Name .. ".Length" ) or (in_num + 1)%>, <%=out_num%>, err_func);
if (__gen_error != 0)
luaEnv.ThrowExceptionFromError(err_func - 1);
<%ForEachCsList(parameters, function(parameter)
if parameter.IsOut or parameter.ParameterType.IsByRef then
%><%=GetCasterStatement(parameter.ParameterType, "err_func" .. (" + "..out_idx), parameter.Name)%>;
<%
out_idx = out_idx + 1
end
end) %>
<%if has_return then %><%=GetCasterStatement(method.ReturnType, "err_func + 1", "__gen_ret", true)%>;<% end%>
LuaAPI.lua_settop(L, err_func - 1);
<%if has_return then %>return __gen_ret;<% end%>
#if THREAD_SAFE || HOTFIX_ENABLE
}
#endif
}
<%end%>
<%if indexer:GetSetMethod() then
local method = indexer:GetSetMethod()
local parameters = method:GetParameters()
local in_num = CalcCsList(parameters, function(p) return not (p.IsOut and p.ParameterType.IsByRef) end)
local out_num = CalcCsList(parameters, function(p) return p.IsOut or p.ParameterType.IsByRef end)
local in_pos = 0
local has_return = (method.ReturnType.FullName ~= "System.Void")
local return_type_name = has_return and CsFullTypeName(method.ReturnType) or "void"
local out_idx = has_return and 2 or 1
if has_return then out_num = out_num + 1 end
%>
set
{
#if THREAD_SAFE || HOTFIX_ENABLE
lock (luaEnv.luaEnvLock)
{
#endif
RealStatePtr L = luaEnv.L;
int err_func = LuaAPI.load_error_func(L, luaEnv.errorFuncRef);
<%if CallNeedTranslator(method, "") then %>ObjectTranslator translator = luaEnv.translator;<%end%>
LuaAPI.lua_getref(L, luaReference);
LuaAPI.xlua_pushasciistring(L, "<%=method.Name%>");
if (0 != LuaAPI.xlua_pgettable(L, -2))
{
luaEnv.ThrowExceptionFromError(err_func - 1);
}
if(!LuaAPI.lua_isfunction(L, -1))
{
LuaAPI.xlua_pushasciistring(L, "no such function <%=method.Name%>");
luaEnv.ThrowExceptionFromError(err_func - 1);
}
LuaAPI.lua_pushvalue(L, -2);
LuaAPI.lua_remove(L, -3);
<%
local param_count = parameters.Length
local has_v_params = param_count > 0 and IsParams(parameters[param_count - 1])
ForEachCsList(parameters, function(parameter, pi)
if not (parameter.IsOut and parameter.ParameterType.IsByRef) then
%><%=GetPushStatement(parameter.ParameterType, parameter.Name, has_v_params and pi == param_count - 1)%>;
<%
end
end) %>
int __gen_error = LuaAPI.lua_pcall(L, <%=has_v_params and ((in_num) .. " + " .. parameters[param_count - 1].Name .. ".Length" ) or (in_num + 1)%>, <%=out_num%>, err_func);
if (__gen_error != 0)
luaEnv.ThrowExceptionFromError(err_func - 1);
<%ForEachCsList(parameters, function(parameter)
if parameter.IsOut or parameter.ParameterType.IsByRef then
%><%=GetCasterStatement(parameter.ParameterType, "err_func" .. (" + "..out_idx), parameter.Name)%>;
<%
out_idx = out_idx + 1
end
end) %>
<%if has_return then %><%=GetCasterStatement(method.ReturnType, "err_func + 1", "__gen_ret", true)%>;<% end%>
LuaAPI.lua_settop(L, err_func - 1);
<%if has_return then %>return __gen_ret;<% end%>
#if THREAD_SAFE || HOTFIX_ENABLE
}
#endif
}
<%end%>
}
<%end)%>
}
}

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 7165d08e91378494dadeb10e5338accb
timeCreated: 1481620508
licenseType: Pro
TextScriptImporter:
userData:
assetBundleName:
assetBundleVariant:

@ -0,0 +1,140 @@
#if USE_UNI_LUA
using LuaAPI = UniLua.Lua;
using RealStatePtr = UniLua.ILuaState;
using LuaCSFunction = UniLua.CSharpFunctionDelegate;
#else
using LuaAPI = XLua.LuaDLL.Lua;
using RealStatePtr = System.IntPtr;
using LuaCSFunction = XLua.LuaDLL.lua_CSFunction;
#endif
using System;
using System.Collections.Generic;
using System.Reflection;
<%
require "TemplateCommon"
%>
namespace XLua.CSObjectWrap
{
public class XLua_Gen_Initer_Register__
{
<%
local split_method_perfix = 'wrapInit'
local split_method_count = 0
local wrap_in_split_method = 0
local max_wrap_in_split_method = 50
%>
<%ForEachCsList(wraps, function(wrap)%>
<%if wrap_in_split_method == 0 then%>static void <%=split_method_perfix%><%=split_method_count%>(LuaEnv luaenv, ObjectTranslator translator)
{
<%end%>
translator.DelayWrapLoader(typeof(<%=CsFullTypeName(wrap)%>), <%=CSVariableName(wrap)%>Wrap.__Register);
<%if wrap_in_split_method == max_wrap_in_split_method then
wrap_in_split_method = 0
split_method_count = split_method_count + 1
%>
}
<%else
wrap_in_split_method = wrap_in_split_method + 1
end
end)%>
<% if generic_wraps then
for generic_def, instances in pairs(generic_wraps) do
for _, args in ipairs(instances) do
local generic_arg_list = "<"
ForEachCsList(args, function(generic_arg, gai)
if gai ~= 0 then generic_arg_list = generic_arg_list .. ", " end
generic_arg_list = generic_arg_list .. CsFullTypeName(generic_arg)
end)
generic_arg_list = generic_arg_list .. ">"
%>
<%if wrap_in_split_method == 0 then%>static void <%=split_method_perfix%><%=split_method_count%>(LuaEnv luaenv, ObjectTranslator translator)
{
<%end%>
translator.DelayWrapLoader(typeof(<%=generic_def.Name:gsub("`%d+", "") .. generic_arg_list%>), <%=CSVariableName(generic_def)%>Wrap<%=generic_arg_list%>.__Register);
<%if wrap_in_split_method == max_wrap_in_split_method then
wrap_in_split_method = 0
split_method_count = split_method_count + 1
%>
}
<%else
wrap_in_split_method = wrap_in_split_method + 1
end
end
end
end%>
<%if wrap_in_split_method ~= 0 then
split_method_count = split_method_count + 1
%>}<%end%>
static void Init(LuaEnv luaenv, ObjectTranslator translator)
{
<%for i = 1, split_method_count do%>
<%=split_method_perfix%><%=(i - 1)%>(luaenv, translator);
<%end%>
<%ForEachCsList(itf_bridges, function(itf_bridge)%>
translator.AddInterfaceBridgeCreator(typeof(<%=CsFullTypeName(itf_bridge)%>), <%=CSVariableName(itf_bridge)%>Bridge.__Create);
<%end)%>
}
static XLua_Gen_Initer_Register__()
{
XLua.LuaEnv.AddIniter(Init);
}
}
}
namespace XLua
{
public partial class ObjectTranslator
{
static XLua.CSObjectWrap.XLua_Gen_Initer_Register__ s_gen_reg_dumb_obj = new XLua.CSObjectWrap.XLua_Gen_Initer_Register__();
static XLua.CSObjectWrap.XLua_Gen_Initer_Register__ gen_reg_dumb_obj {get{return s_gen_reg_dumb_obj;}}
}
internal partial class InternalGlobals
{
<%
local type_to_methods = {}
local seq_tbl = {}
ForEachCsList(extension_methods, function(extension_method, idx)
local parameters = extension_method:GetParameters()
local type = parameters[0].ParameterType
if not type_to_methods[type] then
type_to_methods[type] = {type = type}
table.insert(seq_tbl, type_to_methods[type])
end
table.insert(type_to_methods[type], {method = extension_method, index = idx})
%>
delegate <%=CsFullTypeName(extension_method.ReturnType)%> __GEN_DELEGATE<%=idx%>(<%ForEachCsList(parameters, function(parameter, pi)
%><%if pi ~= 0 then%>, <%end%><%if parameter.IsOut then %>out <% elseif parameter.ParameterType.IsByRef then %>ref <% end %> <%=CsFullTypeName(parameter.ParameterType)%> <%=parameter.Name%><%
end)%>);
<%end)%>
static InternalGlobals()
{
extensionMethodMap = new Dictionary<Type, IEnumerable<MethodInfo>>()
{
<%for _, methods_info in ipairs(seq_tbl) do%>
{typeof(<%=CsFullTypeName(methods_info.type)%>), new List<MethodInfo>(){
<% for _, method_info in ipairs(methods_info) do%>
new __GEN_DELEGATE<%=method_info.index%>(<%=CsFullTypeName(method_info.method.DeclaringType)%>.<%=method_info.method.Name%>)
#if UNITY_WSA && !UNITY_EDITOR
.GetMethodInfo(),
#else
.Method,
#endif
<% end%>
}},
<%end%>
};
genTryArrayGetPtr = StaticLuaCallbacks.__tryArrayGet;
genTryArraySetPtr = StaticLuaCallbacks.__tryArraySet;
}
}
}

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: e416b82ec9fe340458f97cf1e3468ef7
timeCreated: 1481620508
licenseType: Pro
TextScriptImporter:
userData:
assetBundleName:
assetBundleVariant:

@ -0,0 +1,140 @@
#if USE_UNI_LUA
using LuaAPI = UniLua.Lua;
using RealStatePtr = UniLua.ILuaState;
using LuaCSFunction = UniLua.CSharpFunctionDelegate;
#else
using LuaAPI = XLua.LuaDLL.Lua;
using RealStatePtr = System.IntPtr;
using LuaCSFunction = XLua.LuaDLL.lua_CSFunction;
#endif
using System;
using System.Collections.Generic;
using System.Reflection;
<%
require "TemplateCommon"
%>
namespace XLua.CSObjectWrap
{
public class XLua_Gen_Initer_Register__
{
<%
local split_method_perfix = 'wrapInit'
local split_method_count = 0
local wrap_in_split_method = 0
local max_wrap_in_split_method = 50
%>
<%ForEachCsList(wraps, function(wrap)%>
<%if wrap_in_split_method == 0 then%>static void <%=split_method_perfix%><%=split_method_count%>(LuaEnv luaenv, ObjectTranslator translator)
{
<%end%>
translator.DelayWrapLoader(typeof(<%=CsFullTypeName(wrap)%>), translator.__Register<%=CSVariableName(wrap)%>);
<%if wrap_in_split_method == max_wrap_in_split_method then
wrap_in_split_method = 0
split_method_count = split_method_count + 1
%>
}
<%else
wrap_in_split_method = wrap_in_split_method + 1
end
end)%>
<% if generic_wraps then
for generic_def, instances in pairs(generic_wraps) do
for _, args in ipairs(instances) do
local generic_arg_list = "<"
ForEachCsList(args, function(generic_arg, gai)
if gai ~= 0 then generic_arg_list = generic_arg_list .. ", " end
generic_arg_list = generic_arg_list .. CsFullTypeName(generic_arg)
end)
generic_arg_list = generic_arg_list .. ">"
%>
<%if wrap_in_split_method == 0 then%>static void <%=split_method_perfix%><%=split_method_count%>(LuaEnv luaenv, ObjectTranslator translator)
{
<%end%>
translator.DelayWrapLoader(typeof(<%=generic_def.Name:gsub("`%d+", "") .. generic_arg_list%>), translator.__Register<%=CSVariableName(generic_def)%><%=generic_arg_list%>);
<%if wrap_in_split_method == max_wrap_in_split_method then
wrap_in_split_method = 0
split_method_count = split_method_count + 1
%>
}
<%else
wrap_in_split_method = wrap_in_split_method + 1
end
end
end
end%>
<%if wrap_in_split_method ~= 0 then
split_method_count = split_method_count + 1
%>}<%end%>
static void Init(LuaEnv luaenv, ObjectTranslator translator)
{
<%for i = 1, split_method_count do%>
<%=split_method_perfix%><%=(i - 1)%>(luaenv, translator);
<%end%>
<%ForEachCsList(itf_bridges, function(itf_bridge)%>
translator.AddInterfaceBridgeCreator(typeof(<%=CsFullTypeName(itf_bridge)%>), <%=CSVariableName(itf_bridge)%>Bridge.__Create);
<%end)%>
}
static XLua_Gen_Initer_Register__()
{
XLua.LuaEnv.AddIniter(Init);
}
}
}
namespace XLua
{
public partial class ObjectTranslator
{
static XLua.CSObjectWrap.XLua_Gen_Initer_Register__ s_gen_reg_dumb_obj = new XLua.CSObjectWrap.XLua_Gen_Initer_Register__();
static XLua.CSObjectWrap.XLua_Gen_Initer_Register__ gen_reg_dumb_obj {get{return s_gen_reg_dumb_obj;}}
}
internal partial class InternalGlobals
{
<%
local type_to_methods = {}
local seq_tbl = {}
ForEachCsList(extension_methods, function(extension_method, idx)
local parameters = extension_method:GetParameters()
local type = parameters[0].ParameterType
if not type_to_methods[type] then
type_to_methods[type] = {type = type}
table.insert(seq_tbl, type_to_methods[type])
end
table.insert(type_to_methods[type], {method = extension_method, index = idx})
%>
delegate <%=CsFullTypeName(extension_method.ReturnType)%> __GEN_DELEGATE<%=idx%>(<%ForEachCsList(parameters, function(parameter, pi)
%><%if pi ~= 0 then%>, <%end%><%if parameter.IsOut then %>out <% elseif parameter.ParameterType.IsByRef then %>ref <% end %> <%=CsFullTypeName(parameter.ParameterType)%> <%=parameter.Name%><%
end)%>);
<%end)%>
static InternalGlobals()
{
extensionMethodMap = new Dictionary<Type, IEnumerable<MethodInfo>>()
{
<%for _, methods_info in ipairs(seq_tbl) do%>
{typeof(<%=CsFullTypeName(methods_info.type)%>), new List<MethodInfo>(){
<% for _, method_info in ipairs(methods_info) do%>
new __GEN_DELEGATE<%=method_info.index%>(<%=CsFullTypeName(method_info.method.DeclaringType)%>.<%=method_info.method.Name%>)
#if UNITY_WSA && !UNITY_EDITOR
.GetMethodInfo(),
#else
.Method,
#endif
<% end%>
}},
<%end%>
};
genTryArrayGetPtr = StaticLuaCallbacks.__tryArrayGet;
genTryArraySetPtr = StaticLuaCallbacks.__tryArraySet;
}
}
}

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 46c7366d55afbf1459674448d92c44c8
timeCreated: 1501232428
licenseType: Pro
TextScriptImporter:
userData:
assetBundleName:
assetBundleVariant:

@ -0,0 +1,233 @@
#if USE_UNI_LUA
using LuaAPI = UniLua.Lua;
using RealStatePtr = UniLua.ILuaState;
using LuaCSFunction = UniLua.CSharpFunctionDelegate;
#else
using LuaAPI = XLua.LuaDLL.Lua;
using RealStatePtr = System.IntPtr;
using LuaCSFunction = XLua.LuaDLL.lua_CSFunction;
#endif
using System;
<%
require "TemplateCommon"
%>
namespace XLua
{
public partial class ObjectTranslator
{
<%if purevaluetypes.Count > 0 then
local init_class_name = "IniterAdder" .. CSVariableName(purevaluetypes[0].Type)
%>
class <%=init_class_name%>
{
static <%=init_class_name%>()
{
LuaEnv.AddIniter(Init);
}
static void Init(LuaEnv luaenv, ObjectTranslator translator)
{
<%ForEachCsList(purevaluetypes, function(type_info)
if not type_info.Type.IsValueType then return end
local full_type_name = CsFullTypeName(type_info.Type)%>
translator.RegisterPushAndGetAndUpdate<<%=full_type_name%>>(translator.Push<%=CSVariableName(type_info.Type)%>, translator.Get, translator.Update<%=CSVariableName(type_info.Type)%>);<%
end)%>
<%ForEachCsList(tableoptimzetypes, function(type_info)
local full_type_name = CsFullTypeName(type_info.Type)%>
translator.RegisterCaster<<%=full_type_name%>>(translator.Get);<%
end)%>
}
}
static <%=init_class_name%> s_<%=init_class_name%>_dumb_obj = new <%=init_class_name%>();
static <%=init_class_name%> <%=init_class_name%>_dumb_obj {get{return s_<%=init_class_name%>_dumb_obj;}}
<%end%>
<%ForEachCsList(purevaluetypes, function(type_info)
local type_id_var_name = CSVariableName(type_info.Type) .. '_TypeID'
local enum_ref_var_name = CSVariableName(type_info.Type)..'_EnumRef'
local full_type_name = CsFullTypeName(type_info.Type)
local is_enum = type_info.Type.IsEnum
%>int <%=type_id_var_name%> = -1;<%if is_enum then%>
int <%=enum_ref_var_name%> = -1;
<%end%>
public void Push<%=CSVariableName(type_info.Type)%>(RealStatePtr L, <%=full_type_name%> val)
{
if (<%=type_id_var_name%> == -1)
{
bool is_first;
<%=type_id_var_name%> = getTypeId(L, typeof(<%=full_type_name%>), out is_first);
<%if is_enum then%>
if (<%=enum_ref_var_name%> == -1)
{
Utils.LoadCSTable(L, typeof(<%=full_type_name%>));
<%=enum_ref_var_name%> = LuaAPI.luaL_ref(L, LuaIndexes.LUA_REGISTRYINDEX);
}
<%end%>
}
<%if is_enum then%>
if (LuaAPI.xlua_tryget_cachedud(L, (int)val, <%=enum_ref_var_name%>) == 1)
{
return;
}
<%
end
if type_info.Flag == CS.XLua.OptimizeFlag.PackAsTable then
%>
<%if PushObjectNeedTranslator(type_info) then %> ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);<%end%>
LuaAPI.xlua_pushcstable(L, <%=type_info.FieldInfos.Count%>, <%=type_id_var_name%>);
<%ForEachCsList(type_info.FieldInfos, function(fieldInfo)%>
LuaAPI.xlua_pushasciistring(L, "<%=fieldInfo.Name%>");
<%=GetPushStatement(fieldInfo.Type, "val."..fieldInfo.Name)%>;
LuaAPI.lua_rawset(L, -3);
<%end)%>
<%else%>
IntPtr buff = LuaAPI.xlua_pushstruct(L, <%=is_enum and 4 or type_info.Size%>, <%=type_id_var_name%>);
if (!CopyByValue.Pack(buff, 0, <%=is_enum and "(int)" or ""%>val))
{
throw new Exception("pack fail fail for <%=full_type_name%> ,value="+val);
}
<%
end
if is_enum then
%>
LuaAPI.lua_getref(L, <%=enum_ref_var_name%>);
LuaAPI.lua_pushvalue(L, -2);
LuaAPI.xlua_rawseti(L, -2, (int)val);
LuaAPI.lua_pop(L, 1);
<%end%>
}
public void Get(RealStatePtr L, int index, out <%=full_type_name%> val)
{
LuaTypes type = LuaAPI.lua_type(L, index);
if (type == LuaTypes.LUA_TUSERDATA )
{
if (LuaAPI.xlua_gettypeid(L, index) != <%=type_id_var_name%>)
{
throw new Exception("invalid userdata for <%=full_type_name%>");
}
IntPtr buff = LuaAPI.lua_touserdata(L, index);<%if is_enum then%>
int e;
<%end%>if (!CopyByValue.UnPack(buff, 0, out <%=is_enum and "e" or "val"%>))
{
throw new Exception("unpack fail for <%=full_type_name%>");
}<%if is_enum then%>
val = (<%=full_type_name%>)e;
<%end%>
}<%if not is_enum then%>
else if (type ==LuaTypes.LUA_TTABLE)
{
CopyByValue.UnPack(this, L, index, out val);
}<%end%>
else
{
val = (<%=full_type_name%>)objectCasters.GetCaster(typeof(<%=full_type_name%>))(L, index, null);
}
}
public void Update<%=CSVariableName(type_info.Type)%>(RealStatePtr L, int index, <%=full_type_name%> val)
{
<%if type_info.Flag == CS.XLua.OptimizeFlag.PackAsTable then%>
if (LuaAPI.lua_type(L, index) == LuaTypes.LUA_TTABLE)
{
return;
}
<%else%>
if (LuaAPI.lua_type(L, index) == LuaTypes.LUA_TUSERDATA)
{
if (LuaAPI.xlua_gettypeid(L, index) != <%=type_id_var_name%>)
{
throw new Exception("invalid userdata for <%=full_type_name%>");
}
IntPtr buff = LuaAPI.lua_touserdata(L, index);
if (!CopyByValue.Pack(buff, 0, <%=is_enum and "(int)" or ""%>val))
{
throw new Exception("pack fail for <%=full_type_name%> ,value="+val);
}
}
<%end%>
else
{
throw new Exception("try to update a data with lua type:" + LuaAPI.lua_type(L, index));
}
}
<%end)%>
// table cast optimze
<%ForEachCsList(tableoptimzetypes, function(type_info)
local full_type_name = CsFullTypeName(type_info.Type)
%>
public void Get(RealStatePtr L, int index, out <%=full_type_name%> val)
{
LuaTypes type = LuaAPI.lua_type(L, index);
if (type == LuaTypes.LUA_TUSERDATA )
{
val = (<%=full_type_name%>)FastGetCSObj(L, index);
}
else if (type == LuaTypes.LUA_TTABLE)
{
val = new <%=full_type_name%>();
int top = LuaAPI.lua_gettop(L);
<%ForEachCsList(type_info.Fields, function(fieldInfo)%>
if (Utils.LoadField(L, index, "<%=fieldInfo.Name%>"))
{
Get(L, top + 1, out val.<%=fieldInfo.Name%>);
}
LuaAPI.lua_pop(L, 1);
<%end)%>
}<%if not type_info.Type.IsValueType then%>
else if (type == LuaTypes.LUA_TNIL || type == LuaTypes.LUA_TNONE)
{
val = null;
}<%end%>
else
{
throw new Exception("can not cast " + LuaAPI.lua_type(L, index) + " to " + typeof(<%=full_type_name%>));
}
}
<%end)%>
}
public partial class StaticLuaCallbacks
{
internal static bool __tryArrayGet(Type type, RealStatePtr L, ObjectTranslator translator, object obj, int index)
{
<%ForEachCsList(purevaluetypes, function(type_info, idx)
if not type_info.Type.IsValueType then return end
local full_type_name = CsFullTypeName(type_info.Type)
%>
<%=(idx == 0 and '' or 'else ')%>if (type == typeof(<%=full_type_name%>[]))
{
<%=full_type_name%>[] array = obj as <%=full_type_name%>[];
translator.Push<%=CSVariableName(type_info.Type)%>(L, array[index]);
return true;
}<%
end)%>
return false;
}
internal static bool __tryArraySet(Type type, RealStatePtr L, ObjectTranslator translator, object obj, int array_idx, int obj_idx)
{
<%
local is_first = true
ForEachCsList(purevaluetypes, tableoptimzetypes, function(type_info)
local full_type_name = CsFullTypeName(type_info.Type)
%>
<%=(is_first and '' or 'else ')%>if (type == typeof(<%=full_type_name%>[]))
{
<%=full_type_name%>[] array = obj as <%=full_type_name%>[];
translator.Get(L, obj_idx, out array[array_idx]);
return true;
}<%
is_first = false
end)%>
return false;
}
}
}

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: d1a916469d261d447972d287b6c5b7a0
timeCreated: 1481620508
licenseType: Pro
TextScriptImporter:
userData:
assetBundleName:
assetBundleVariant:

@ -0,0 +1,123 @@
#if USE_UNI_LUA
using LuaAPI = UniLua.Lua;
using RealStatePtr = UniLua.ILuaState;
using LuaCSFunction = UniLua.CSharpFunctionDelegate;
#else
using LuaAPI = XLua.LuaDLL.Lua;
using RealStatePtr = System.IntPtr;
using LuaCSFunction = XLua.LuaDLL.lua_CSFunction;
#endif
using System;
<%
require "TemplateCommon"
%>
namespace XLua
{
public static partial class CopyByValue
{
<%ForEachCsList(type_infos, function(type_info)
local full_type_name = CsFullTypeName(type_info.Type)
%>
<%if type_info.IsRoot then
ForEachCsList(type_info.FieldInfos, function(fieldInfo) fieldInfo.Name = UnK(fieldInfo.Name) end)
%>
public static void UnPack(ObjectTranslator translator, RealStatePtr L, int idx, out <%=full_type_name%> val)
{
val = new <%=full_type_name%>();
int top = LuaAPI.lua_gettop(L);
<%ForEachCsList(type_info.FieldInfos, function(fieldInfo)%>
if (Utils.LoadField(L, idx, "<%=fieldInfo.Name%>"))
{
<%if fieldInfo.IsField then%>
translator.Get(L, top + 1, out val.<%=fieldInfo.Name%>);
<%else%>
var <%=fieldInfo.Name%> = val.<%=fieldInfo.Name%>;
translator.Get(L, top + 1, out <%=fieldInfo.Name%>);
val.<%=fieldInfo.Name%> = <%=fieldInfo.Name%>;
<%end%>
}
LuaAPI.lua_pop(L, 1);
<%end)%>
}
<%end%>
public static bool Pack(IntPtr buff, int offset, <%=full_type_name%> field)
{
<%
local offset_inner = 0
if not type_info.FieldGroup then
ForEachCsList(type_info.FieldInfos, function(fieldInfo)
%>
if(!Pack(buff, offset<%=(offset_inner == 0 and "" or (" + " .. offset_inner))%>, field.<%=fieldInfo.Name%>))
{
return false;
}
<%
offset_inner = offset_inner + fieldInfo.Size
end)
else
ForEachCsList(type_info.FieldGroup, function(group)
%>
if(!LuaAPI.xlua_pack_float<%=(group.Count == 1 and "" or group.Count)%>(buff, offset<%=(offset_inner == 0 and "" or (" + " .. offset_inner))%><%
ForEachCsList(group, function(fieldInfo, i)
%>, field.<%=fieldInfo.Name%><%
end)
%>))
{
return false;
}
<%
offset_inner = offset_inner + group.Count * 4
end)
end%>
return true;
}
public static bool UnPack(IntPtr buff, int offset, out <%=full_type_name%> field)
{
field = default(<%=full_type_name%>);
<%
local offset_inner = 0
if not type_info.FieldGroup then
ForEachCsList(type_info.FieldInfos, function(fieldInfo)
if fieldInfo.IsField then
%>
if(!UnPack(buff, offset<%=(offset_inner == 0 and "" or (" + " .. offset_inner))%>, out field.<%=fieldInfo.Name%>))
{
return false;
}
<%else%>
var <%=fieldInfo.Name%> = field.<%=fieldInfo.Name%>;
if(!UnPack(buff, offset<%=(offset_inner == 0 and "" or (" + " .. offset_inner))%>, out <%=fieldInfo.Name%>))
{
return false;
}
field.<%=fieldInfo.Name%> = <%=fieldInfo.Name%>;
<%
end
offset_inner = offset_inner + fieldInfo.Size
end)
else
ForEachCsList(type_info.FieldGroup, function(group)
%>
<%ForEachCsList(group, function(fieldInfo)%>float <%=fieldInfo.Name%> = default(float);
<%end)%>
if(!LuaAPI.xlua_unpack_float<%=(group.Count == 1 and "" or group.Count)%>(buff, offset<%=(offset_inner == 0 and "" or (" + " .. offset_inner))%><%
ForEachCsList(group, function(fieldInfo)
%>, out <%=fieldInfo.Name%><%
end)
%>))
{
return false;
}
<%ForEachCsList(group, function(fieldInfo)%>field.<%=fieldInfo.Name%> = <%=fieldInfo.Name%>;
<%end)%>
<%
offset_inner = offset_inner + group.Count * 4
end)
end%>
return true;
}
<%end)%>
}
}

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: c9ef7e8f2a3b37744aad49b99370c16b
timeCreated: 1481620508
licenseType: Pro
TextScriptImporter:
userData:
assetBundleName:
assetBundleVariant:

@ -0,0 +1,471 @@
-- Tencent is pleased to support the open source community by making xLua available.
-- Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.
-- Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
-- http://opensource.org/licenses/MIT
-- Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
local friendlyNameMap = {
["System.Object"] = "object",
["System.String"] = "string",
["System.Boolean"] = "bool",
["System.Byte"] = "byte",
["System.Char"] = "char",
["System.Decimal"] = "decimal",
["System.Double"] = "double",
["System.Int16"] = "short",
["System.Int32"] = "int",
["System.Int64"] = "long",
["System.SByte"] = "sbyte",
["System.Single"] = "float",
["System.UInt16"] = "ushort",
["System.UInt32"] = "uint",
["System.UInt64"] = "ulong",
["System.Void"] = "void",
}
local csKeywords = {
"abstract", "as", "base", "bool",
"break", "byte", "case", "catch",
"char", "checked", "class", "const",
"continue", "decimal", "default", "delegate",
"do", "double", "else", "enum",
"event", "explicit", "extern", "false",
"finally", "fixed", "float", "for",
"foreach", "goto", "if", "implicit",
"in", "int", "interface",
"internal", "is", "lock", "long",
"namespace", "new", "null", "object",
"operator", "out", "override",
"params", "private", "protected", "public",
"readonly", "ref", "return", "sbyte",
"sealed", "short", "sizeof", "stackalloc",
"static", "string", "struct", "switch",
"this", "throw", "true", "try",
"typeof", "uint", "ulong", "unchecked",
"unsafe", "ushort", "using", "virtual",
"void", "volatile", "while"
}
for _, kw in ipairs(csKeywords) do
csKeywords[kw] = '@'..kw
end
for i = 1, #csKeywords do
csKeywords[i] = nil
end
function UnK(symbol)
return csKeywords[symbol] or symbol
end
local fixChecker = {
--["System.String"] = "LuaAPI.lua_isstring",
["System.Boolean"] = "LuaTypes.LUA_TBOOLEAN == LuaAPI.lua_type",
["System.Byte"] = "LuaTypes.LUA_TNUMBER == LuaAPI.lua_type",
["System.Char"] = "LuaTypes.LUA_TNUMBER == LuaAPI.lua_type",
--["System.Decimal"] = "LuaTypes.LUA_TNUMBER == LuaAPI.lua_type",
["System.Double"] = "LuaTypes.LUA_TNUMBER == LuaAPI.lua_type",
["System.Int16"] = "LuaTypes.LUA_TNUMBER == LuaAPI.lua_type",
["System.Int32"] = "LuaTypes.LUA_TNUMBER == LuaAPI.lua_type",
--["System.Int64"] = "LuaTypes.LUA_TNUMBER == LuaAPI.lua_type",
["System.SByte"] = "LuaTypes.LUA_TNUMBER == LuaAPI.lua_type",
["System.Single"] = "LuaTypes.LUA_TNUMBER == LuaAPI.lua_type",
["System.UInt16"] = "LuaTypes.LUA_TNUMBER == LuaAPI.lua_type",
["System.UInt32"] = "LuaTypes.LUA_TNUMBER == LuaAPI.lua_type",
--["System.UInt64"] = "LuaTypes.LUA_TNUMBER == LuaAPI.lua_type",
["System.IntPtr"] = "LuaTypes.LUA_TLIGHTUSERDATA == LuaAPI.lua_type",
}
local typedCaster = {
["System.Byte"] = "LuaAPI.xlua_tointeger",
["System.Char"] = "LuaAPI.xlua_tointeger",
["System.Int16"] = "LuaAPI.xlua_tointeger",
["System.SByte"] = "LuaAPI.xlua_tointeger",
["System.Single"] = "LuaAPI.lua_tonumber",
["System.UInt16"] = "LuaAPI.xlua_tointeger",
}
local fixCaster = {
["System.Double"] = "LuaAPI.lua_tonumber",
["System.String"] = "LuaAPI.lua_tostring",
["System.Boolean"] = "LuaAPI.lua_toboolean",
["System.Byte[]"] = "LuaAPI.lua_tobytes",
["System.IntPtr"] = "LuaAPI.lua_touserdata",
["System.UInt32"] = "LuaAPI.xlua_touint",
["System.UInt64"] = "LuaAPI.lua_touint64",
["System.Int32"] = "LuaAPI.xlua_tointeger",
["System.Int64"] = "LuaAPI.lua_toint64",
}
local fixPush = {
["System.Byte"] = "LuaAPI.xlua_pushinteger",
["System.Char"] = "LuaAPI.xlua_pushinteger",
["System.Int16"] = "LuaAPI.xlua_pushinteger",
["System.Int32"] = "LuaAPI.xlua_pushinteger",
["System.Int64"] = "LuaAPI.lua_pushint64",
["System.SByte"] = "LuaAPI.xlua_pushinteger",
["System.Single"] = "LuaAPI.lua_pushnumber",
["System.UInt16"] = "LuaAPI.xlua_pushinteger",
["System.UInt32"] = "LuaAPI.xlua_pushuint",
["System.UInt64"] = "LuaAPI.lua_pushuint64",
["System.Double"] = "LuaAPI.lua_pushnumber",
["System.String"] = "LuaAPI.lua_pushstring",
["System.Byte[]"] = "LuaAPI.lua_pushstring",
["System.Boolean"] = "LuaAPI.lua_pushboolean",
["System.IntPtr"] = "LuaAPI.lua_pushlightuserdata",
["System.Decimal"] = "translator.PushDecimal",
["System.Object"] = "translator.PushAny",
}
local notranslator = {
["System.Byte"] = true,
["System.Char"] = true,
["System.Int16"] = true,
["System.Int32"] = true,
["System.Int64"] = true,
["System.SByte"] = true,
["System.Single"] = true,
["System.UInt16"] = true,
["System.UInt32"] = true,
["System.UInt64"] = true,
["System.Double"] = true,
["System.String"] = true,
["System.Boolean"] = true,
["System.Void"] = true,
["System.IntPtr"] = true,
["System.Byte[]"] = true,
}
function ForEachCsList(...)
local list_count = select('#', ...) - 1
local callback = select(list_count + 1, ...)
for i = 1, list_count do
local list = select(i, ...)
for i = 0, (list.Count or list.Length) - 1 do
callback(list[i], i)
end
end
end
function CalcCsList(list, predicate)
local count = 0
for i = 0, (list.Count or list.Length) - 1 do
if predicate(list[i], i) then count = count + 1 end
end
return count
end
function IfAny(list, predicate)
for i = 0, (list.Count or list.Length) - 1 do
if predicate(list[i], i) then return true end
end
return false
end
local genPushAndUpdateTypes
function SetGenPushAndUpdateTypes(list)
genPushAndUpdateTypes = {}
ForEachCsList(list, function(t)
genPushAndUpdateTypes[t] = true
end)
end
local xLuaClasses
function SetXLuaClasses(list)
xLuaClasses = {}
ForEachCsList(list, function(t)
xLuaClasses[t.Name] = true
end)
end
local objType = typeof(CS.System.Object)
local valueType = typeof(CS.System.ValueType)
local function _CsFullTypeName(t)
if t.IsArray then
local element_name, element_is_array = _CsFullTypeName(t:GetElementType())
if element_is_array then
local bracket_pos = element_name:find('%[')
return element_name:sub(1, bracket_pos - 1) .. '[' .. string.rep(',', t:GetArrayRank() - 1) .. ']' .. element_name:sub(bracket_pos, -1), true
else
return element_name .. '[' .. string.rep(',', t:GetArrayRank() - 1) .. ']', true
end
elseif t.IsByRef then
return _CsFullTypeName(t:GetElementType())
elseif t.IsGenericParameter then
return (t.BaseType == objType or t.BaseType == valueType) and t.Name or _CsFullTypeName(t.BaseType) --TODO:应该判断是否类型约束
end
local name = t.FullName:gsub("&", ""):gsub("%+", ".")
if not t.IsGenericType then
return friendlyNameMap[name] or name
end
local genericParameter = ""
ForEachCsList(t:GetGenericArguments(), function(at, ati)
if ati ~= 0 then genericParameter = genericParameter .. ', ' end
genericParameter = genericParameter .. _CsFullTypeName(at)
end)
return name:gsub("`%d+", '<' .. genericParameter .. '>'):gsub("%[[^,%]].*", ""), false
end
function CsFullTypeName(t)
if t.DeclaringType then
local name = _CsFullTypeName(t)
local declaringTypeName = _CsFullTypeName(t.DeclaringType);
return xLuaClasses[declaringTypeName] and ("global::" .. name) or name
else
local name = _CsFullTypeName(t)
return xLuaClasses[name] and ("global::" .. name) or name
end
end
function CSVariableName(t)
if t.IsArray then
return CSVariableName(t:GetElementType()) .. '_'.. t:GetArrayRank() ..'_'
end
return t:ToString():gsub("&", ""):gsub("%+", ""):gsub("`", "_"):gsub("%.", ""):gsub("%[", "_"):gsub("%]", "_"):gsub(",", "")
end
local function getSafeFullName(t)
if t == nil then
return ""
end
if t.IsGenericParameter then
return t.BaseType == objType and t.Name or getSafeFullName(t.BaseType)
end
if not t.FullName then return "" end
return t.FullName:gsub("&", "")
end
function GetCheckStatement(t, idx, is_v_params)
local cond_start = is_v_params and "(LuaTypes.LUA_TNONE == LuaAPI.lua_type(L, ".. idx ..") || " or ""
local cond_end = is_v_params and ")" or ""
local testname = getSafeFullName(t)
if testname == "System.String" or testname == "System.Byte[]" then
return cond_start .. "(LuaAPI.lua_isnil(L, " .. idx .. ") || LuaAPI.lua_type(L, ".. idx ..") == LuaTypes.LUA_TSTRING)" .. cond_end
elseif testname == "System.Int64" then
return cond_start .. "(LuaTypes.LUA_TNUMBER == LuaAPI.lua_type(L, ".. idx ..") || LuaAPI.lua_isint64(L, ".. idx .."))" .. cond_end
elseif testname == "System.UInt64" then
return cond_start .. "(LuaTypes.LUA_TNUMBER == LuaAPI.lua_type(L, ".. idx ..") || LuaAPI.lua_isuint64(L, ".. idx .."))" .. cond_end
elseif testname == "System.Decimal" then
return cond_start .. "(LuaTypes.LUA_TNUMBER == LuaAPI.lua_type(L, ".. idx ..") || translator.IsDecimal(L, ".. idx .."))" .. cond_end
elseif testname == "XLua.LuaTable" then
return cond_start .. "(LuaAPI.lua_isnil(L, " .. idx .. ") || LuaAPI.lua_type(L, ".. idx ..") == LuaTypes.LUA_TTABLE)" .. cond_end
elseif testname == "XLua.LuaFunction" then
return cond_start .. "(LuaAPI.lua_isnil(L, " .. idx .. ") || LuaAPI.lua_type(L, ".. idx ..") == LuaTypes.LUA_TFUNCTION)" .. cond_end
end
return cond_start .. (fixChecker[testname] or ("translator.Assignable<" .. CsFullTypeName(t).. ">")) .. "(L, ".. idx ..")" .. cond_end
end
local delegateType = typeof(CS.System.Delegate)
local ExtensionAttribute = typeof(CS.System.Runtime.CompilerServices.ExtensionAttribute)
function IsExtensionMethod(method)
return method:IsDefined(ExtensionAttribute, false)
end
function IsDelegate(t)
return delegateType:IsAssignableFrom(t)
end
function MethodParameters(method)
if not IsExtensionMethod(method) then
return method:GetParameters()
else
local parameters = method:GetParameters()
if parameters[0].ParameterType.IsInterface then
return parameters
end
local ret = {}
for i = 1, parameters.Length - 1 do
ret[i - 1] = parameters[i]
end
ret.Length = parameters.Length - 1
return ret
end
end
function IsStruct(t)
if t.IsByRef then t = t:GetElementType() end
return t.IsValueType and not t.IsPrimitive
end
function NeedUpdate(t)
if t.IsByRef then t = t:GetElementType() end
return t.IsValueType and not t.IsPrimitive and not t.IsEnum and t ~= typeof(CS.System.Decimal)
end
function GetCasterStatement(t, idx, var_name, need_declare, is_v_params)
local testname = getSafeFullName(t)
local statement = ""
local is_struct = IsStruct(t)
if need_declare then
statement = CsFullTypeName(t) .. " " .. var_name
if is_struct and not typedCaster[testname] and not fixCaster[testname] then
statement = statement .. ";"
else
statement = statement .. " = "
end
elseif not is_struct then
statement = var_name .. " = "
end
if is_v_params then
return statement .. "translator.GetParams<" .. CsFullTypeName(t:GetElementType()).. ">" .. "(L, ".. idx ..")"
elseif typedCaster[testname] then
return statement .. "(" .. CsFullTypeName(t) .. ")" ..typedCaster[testname] .. "(L, ".. idx ..")"
elseif IsDelegate(t) then
return statement .. "translator.GetDelegate<" .. CsFullTypeName(t).. ">" .. "(L, ".. idx ..")"
elseif fixCaster[testname] then
return statement .. fixCaster[testname] .. "(L, ".. idx ..")"
elseif testname == "System.Object" then
return statement .. "translator.GetObject(L, ".. idx ..", typeof(" .. CsFullTypeName(t) .."))"
elseif is_struct then
return statement .. "translator.Get(L, ".. idx ..", out " .. var_name .. ")"
elseif t.IsGenericParameter and not t.DeclaringMethod then
return statement .. "translator.GetByType<"..t.Name..">(L, ".. idx ..")"
else
return statement .. "("..CsFullTypeName(t)..")translator.GetObject(L, ".. idx ..", typeof(" .. CsFullTypeName(t) .."))"
end
end
local paramsAttriType = typeof(CS.System.ParamArrayAttribute)
function IsParams(pi)
if (not pi.IsDefined) then
return pi.IsParamArray
end
return pi:IsDefined(paramsAttriType, false)
end
local obsoluteAttriType = typeof(CS.System.ObsoleteAttribute)
function IsObsolute(f)
return f:IsDefined(obsoluteAttriType, false)
end
local objectType = typeof(CS.System.Object)
function GetSelfStatement(t)
local fulltypename = CsFullTypeName(t)
local is_struct = IsStruct(t)
if is_struct then
return fulltypename .. " gen_to_be_invoked;translator.Get(L, 1, out gen_to_be_invoked)"
else
if t == objectType then
return "object gen_to_be_invoked = translator.FastGetCSObj(L, 1)"
else
return fulltypename .. " gen_to_be_invoked = (" .. fulltypename .. ")translator.FastGetCSObj(L, 1)"
end
end
end
local GetNullableUnderlyingType = CS.System.Nullable.GetUnderlyingType
function GetPushStatement(t, variable, is_v_params)
if is_v_params then
local item_push = GetPushStatement(t:GetElementType(), variable..'[__gen_i]')
return 'if ('.. variable ..' != null) { for (int __gen_i = 0; __gen_i < ' .. variable .. '.Length; ++__gen_i) ' .. item_push .. '; }'
end
if t.IsByRef then t = t:GetElementType() end
local testname = getSafeFullName(t)
if fixPush[testname] then
return fixPush[testname] .. "(L, ".. variable ..")"
elseif genPushAndUpdateTypes[t] then
return "translator.Push".. CSVariableName(t) .."(L, "..variable..")"
elseif t.IsGenericParameter and not t.DeclaringMethod then
return "translator.PushByType(L, "..variable..")"
elseif t.IsInterface or GetNullableUnderlyingType(t) then
return "translator.PushAny(L, "..variable..")"
else
return "translator.Push(L, "..variable..")"
end
end
function GetUpdateStatement(t, idx, variable)
if t.IsByRef then t = t:GetElementType() end
if typeof(CS.System.Decimal) == t then error('Decimal not update!') end
if genPushAndUpdateTypes[t] then
return "translator.Update".. CSVariableName(t) .."(L, ".. idx ..", "..variable..")"
else
return "translator.Update(L, ".. idx ..", "..variable..")"
end
end
function JustLuaType(t)
return notranslator[getSafeFullName(t)]
end
function CallNeedTranslator(overload, isdelegate)
if not overload.IsStatic and not isdelegate then return true end
local ret_type_name = getSafeFullName(overload.ReturnType)
if not notranslator[ret_type_name] then return true end
local parameters = overload:GetParameters()
return IfAny(overload:GetParameters(), function(parameter)
return IsParams(parameter) or (not notranslator[getSafeFullName(parameter.ParameterType)])
end)
end
function MethodCallNeedTranslator(method)
return IfAny(method.Overloads, function(overload) return CallNeedTranslator(overload) end)
end
function AccessorNeedTranslator(accessor)
return not accessor.IsStatic or not JustLuaType(accessor.Type)
end
function PushObjectNeedTranslator(type_info)
return IfAny(type_info.FieldInfos, function(field_info) return not JustLuaType(field_info.Type) end)
end
local GenericParameterAttributes = CS.System.Reflection.GenericParameterAttributes
local enum_and_op = debug.getmetatable(CS.System.Reflection.BindingFlags.Public).__band
local has_generic_flag = function(f1, f2)
return (f1 ~= GenericParameterAttributes.None) and (enum_and_op(f1, f2) == f2)
end
function GenericArgumentList(type)
local generic_arg_list = ""
local type_constraints = ""
if type.IsGenericTypeDefinition then
generic_arg_list = "<"
local constraints = {}
ForEachCsList(type:GetGenericArguments(), function(generic_arg, gai)
local constraint = {}
if gai ~= 0 then generic_arg_list = generic_arg_list .. ", " end
generic_arg_list = generic_arg_list .. generic_arg.Name
if has_generic_flag(generic_arg.GenericParameterAttributes, GenericParameterAttributes.ReferenceTypeConstraint) then
table.insert(constraint, 'class')
end
if has_generic_flag(generic_arg.GenericParameterAttributes, GenericParameterAttributes.NotNullableValueTypeConstraint) then
table.insert(constraint, 'struct')
end
ForEachCsList(generic_arg:GetGenericParameterConstraints(), function(gpc)
if gpc ~= typeof(CS.System.ValueType) or not has_generic_flag(generic_arg.GenericParameterAttributes, GenericParameterAttributes.NotNullableValueTypeConstraint) then
table.insert(constraint, CsFullTypeName(gpc))
end
end)
if not has_generic_flag(generic_arg.GenericParameterAttributes, GenericParameterAttributes.NotNullableValueTypeConstraint) and has_generic_flag(generic_arg.GenericParameterAttributes, GenericParameterAttributes.DefaultConstructorConstraint) then
table.insert(constraint, 'new()')
end
if #constraint > 0 then
table.insert(constraints, 'where ' .. generic_arg.Name .. ' : ' .. table.concat(constraint, ','))
end
end)
generic_arg_list = generic_arg_list .. ">"
if #constraints > 0 then
type_constraints = table.concat(constraints, ',')
end
end
return generic_arg_list, type_constraints
end
function LocalName(name)
return "_" .. name
end

@ -0,0 +1,4 @@
fileFormatVersion: 2
guid: cb41d53afe75a9443b182e284298feeb
TextScriptImporter:
userData: