uplev xlua

This commit is contained in:
2020-08-05 07:08:47 +08:00
parent 52cc2a59aa
commit b3f98bfda1
298 changed files with 444 additions and 250 deletions

3
Assets/XLua/Src/Editor/Template/LuaClassWrap.tpl.txt Executable file → Normal file
View File

@@ -413,7 +413,8 @@ namespace XLua.CSObjectWrap
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]")%>;
<%=GetCasterStatement(valueType, 3, "gen_value", true)%>;
gen_to_be_invoked[key] = gen_value;
<% else
in_pos = 0;
ForEachCsList(parameters, function(parameter, pi)

View File

View File

View File

View File

View File

View File

View File

25
Assets/XLua/Src/Editor/Template/LuaEnumWrap.tpl.txt Executable file → Normal file
View File

@@ -19,7 +19,13 @@ namespace XLua.CSObjectWrap
{
using Utils = XLua.Utils;
<%ForEachCsList(types, function(type)
local fields = type:GetFields(enum_or_op(CS.System.Reflection.BindingFlags.Public, CS.System.Reflection.BindingFlags.Static))
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
{
@@ -30,11 +36,15 @@ namespace XLua.CSObjectWrap
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);
@@ -49,9 +59,10 @@ namespace XLua.CSObjectWrap
{
translator.Push<%=CSVariableName(type)%>(L, (<%=CsFullTypeName(type)%>)LuaAPI.xlua_tointeger(L, 1));
}
<%if fields.Length > 0 then%>
<%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)
@@ -67,6 +78,16 @@ namespace XLua.CSObjectWrap
{
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

View File

25
Assets/XLua/Src/Editor/Template/LuaEnumWrapGCM.tpl.txt Executable file → Normal file
View File

@@ -20,7 +20,13 @@ namespace XLua
public partial class ObjectTranslator
{
<%ForEachCsList(types, function(type)
local fields = type:GetFields(enum_or_op(CS.System.Reflection.BindingFlags.Public, CS.System.Reflection.BindingFlags.Static))
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)
@@ -29,11 +35,15 @@ namespace XLua
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);
@@ -46,9 +56,10 @@ namespace XLua
{
Push<%=v_type_name%>(L, (<%=CsFullTypeName(type)%>)LuaAPI.xlua_tointeger(L, 1));
}
<%if fields.Length > 0 then%>
<%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)
@@ -64,6 +75,16 @@ namespace XLua
{
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

View File

View File

View File

0
Assets/XLua/Src/Editor/Template/LuaRegister.tpl.txt Executable file → Normal file
View File

View File

0
Assets/XLua/Src/Editor/Template/LuaRegisterGCM.tpl.txt Executable file → Normal file
View File

View File

1
Assets/XLua/Src/Editor/Template/LuaWrapPusher.tpl.txt Executable file → Normal file
View File

@@ -76,6 +76,7 @@ namespace XLua
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%>");

View File

0
Assets/XLua/Src/Editor/Template/PackUnpack.tpl.txt Executable file → Normal file
View File

View File

14
Assets/XLua/Src/Editor/Template/TemplateCommon.lua.txt Executable file → Normal file
View File

@@ -210,8 +210,14 @@ local function _CsFullTypeName(t)
end
function CsFullTypeName(t)
local name = _CsFullTypeName(t)
return xLuaClasses[name] and ("global::" .. name) or name
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)
@@ -411,6 +417,10 @@ 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)

View File