uplev xlua
This commit is contained in:
2
Assets/XLua/Src/CodeEmit.cs
Executable file → Normal file
2
Assets/XLua/Src/CodeEmit.cs
Executable file → Normal file
@@ -231,7 +231,7 @@ namespace XLua
|
||||
{
|
||||
var to_be_impl = group.Key;
|
||||
|
||||
var method_builder = defineImplementMethod(impl_type_builder, to_be_impl, to_be_impl.Attributes, "Invoke" + (genID++));
|
||||
var method_builder = defineImplementMethod(impl_type_builder, to_be_impl, to_be_impl.Attributes, "__Gen_Delegate_Imp" + (genID++));
|
||||
|
||||
emitMethodImpl(to_be_impl, method_builder.GetILGenerator(), false);
|
||||
|
||||
|
||||
0
Assets/XLua/Src/CodeEmit.cs.meta
Executable file → Normal file
0
Assets/XLua/Src/CodeEmit.cs.meta
Executable file → Normal file
0
Assets/XLua/Src/CopyByValue.cs
Executable file → Normal file
0
Assets/XLua/Src/CopyByValue.cs
Executable file → Normal file
0
Assets/XLua/Src/CopyByValue.cs.meta
Executable file → Normal file
0
Assets/XLua/Src/CopyByValue.cs.meta
Executable file → Normal file
4
Assets/XLua/Src/DelegateBridge.cs
Executable file → Normal file
4
Assets/XLua/Src/DelegateBridge.cs
Executable file → Normal file
@@ -86,7 +86,7 @@ namespace XLua
|
||||
|
||||
public static class HotfixDelegateBridge
|
||||
{
|
||||
#if UNITY_IPHONE && !UNITY_EDITOR
|
||||
#if (UNITY_IPHONE || UNITY_TVOS) && !UNITY_EDITOR
|
||||
[DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern bool xlua_get_hotfix_flag(int idx);
|
||||
|
||||
@@ -117,7 +117,7 @@ namespace XLua
|
||||
DelegateBridge.DelegateBridgeList = newList;
|
||||
}
|
||||
DelegateBridge.DelegateBridgeList[idx] = val;
|
||||
#if UNITY_IPHONE && !UNITY_EDITOR
|
||||
#if (UNITY_IPHONE || UNITY_TVOS) && !UNITY_EDITOR
|
||||
xlua_set_hotfix_flag(idx, val != null);
|
||||
#endif
|
||||
}
|
||||
|
||||
0
Assets/XLua/Src/DelegateBridge.cs.meta
Executable file → Normal file
0
Assets/XLua/Src/DelegateBridge.cs.meta
Executable file → Normal file
0
Assets/XLua/Src/Editor.meta
Executable file → Normal file
0
Assets/XLua/Src/Editor.meta
Executable file → Normal file
@@ -527,6 +527,14 @@ namespace CSObjectWrapEditor
|
||||
if (mb is FieldInfo && (mb as FieldInfo).FieldType.IsPointer) return true;
|
||||
if (mb is PropertyInfo && (mb as PropertyInfo).PropertyType.IsPointer) return true;
|
||||
|
||||
foreach(var filter in memberFilters)
|
||||
{
|
||||
if (filter(mb))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var exclude in BlackList)
|
||||
{
|
||||
if (mb.DeclaringType.ToString() == exclude[0] && mb.Name == exclude[1])
|
||||
@@ -544,7 +552,15 @@ namespace CSObjectWrapEditor
|
||||
|
||||
//指针目前不支持,先过滤
|
||||
if (mb.GetParameters().Any(pInfo => pInfo.ParameterType.IsPointer)) return true;
|
||||
if (mb is MethodInfo && (mb as MethodInfo).ReturnType.IsPointer) return false;
|
||||
if (mb is MethodInfo && (mb as MethodInfo).ReturnType.IsPointer) return true;
|
||||
|
||||
foreach (var filter in memberFilters)
|
||||
{
|
||||
if (filter(mb))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var exclude in BlackList)
|
||||
{
|
||||
@@ -618,20 +634,28 @@ namespace CSObjectWrapEditor
|
||||
|
||||
GenOne(null, (type, type_info) =>
|
||||
{
|
||||
var type2fields = luaenv.NewTable();
|
||||
foreach(var _type in types)
|
||||
type2fields.Set(_type, _type.GetFields(BindingFlags.Public | BindingFlags.Static).Where(x => !isMemberInBlackList(x)).ToArray());
|
||||
type_info.Set("type2fields", type2fields);
|
||||
type_info.Set("types", types.ToList());
|
||||
}, templateRef.LuaEnumWrap, textWriter);
|
||||
|
||||
textWriter.Close();
|
||||
}
|
||||
|
||||
static string NonmalizeName(string name)
|
||||
{
|
||||
return name.Replace("+", "_").Replace(".", "_").Replace("`", "_").Replace("&", "_").Replace("[", "_").Replace("]", "_").Replace(",", "_");
|
||||
}
|
||||
|
||||
static void GenInterfaceBridge(IEnumerable<Type> types, string save_path)
|
||||
{
|
||||
foreach (var wrap_type in types)
|
||||
{
|
||||
if (!wrap_type.IsInterface) continue;
|
||||
|
||||
string filePath = save_path + wrap_type.ToString().Replace("+", "").Replace(".", "")
|
||||
.Replace("`", "").Replace("&", "").Replace("[", "").Replace("]", "").Replace(",", "") + "Bridge.cs";
|
||||
string filePath = save_path + NonmalizeName(wrap_type.ToString()) + "Bridge.cs";
|
||||
StreamWriter textWriter = new StreamWriter(filePath, false, Encoding.UTF8);
|
||||
GenOne(wrap_type, (type, type_info) =>
|
||||
{
|
||||
@@ -839,7 +863,8 @@ namespace CSObjectWrapEditor
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
var lastPos = xParams.Length - 1;
|
||||
return lastPos < 0 || xParams[lastPos].IsParamArray == yParams[lastPos].IsParamArray;
|
||||
}
|
||||
public int GetHashCode(MethodInfoSimulation obj)
|
||||
{
|
||||
@@ -927,6 +952,7 @@ namespace CSObjectWrapEditor
|
||||
}
|
||||
|
||||
var delegates_groups = types.Select(delegate_type => makeMethodInfoSimulation(delegate_type.GetMethod("Invoke")))
|
||||
.Where(d => d.DeclaringType.FullName != null)
|
||||
.Concat(hotfxDelegates)
|
||||
.GroupBy(d => d, comparer).Select((group) => new { Key = group.Key, Value = group.ToList()});
|
||||
GenOne(typeof(DelegateBridge), (type, type_info) =>
|
||||
@@ -973,8 +999,7 @@ namespace CSObjectWrapEditor
|
||||
|
||||
foreach (var wrap_type in types)
|
||||
{
|
||||
string filePath = save_path + wrap_type.ToString().Replace("+", "").Replace(".", "")
|
||||
.Replace("`", "").Replace("&", "").Replace("[", "").Replace("]", "").Replace(",", "") + "Wrap.cs";
|
||||
string filePath = save_path + NonmalizeName(wrap_type.ToString()) + "Wrap.cs";
|
||||
StreamWriter textWriter = new StreamWriter(filePath, false, Encoding.UTF8);
|
||||
if (wrap_type.IsEnum)
|
||||
{
|
||||
@@ -1096,7 +1121,7 @@ namespace CSObjectWrapEditor
|
||||
var extension_methods_from_lcs = (from t in LuaCallCSharp
|
||||
where isDefined(t, typeof(ExtensionAttribute))
|
||||
from method in t.GetMethods(BindingFlags.Static | BindingFlags.Public)
|
||||
where isDefined(method, typeof(ExtensionAttribute))
|
||||
where isDefined(method, typeof(ExtensionAttribute)) && !isObsolete(method)
|
||||
where !method.ContainsGenericParameters || isSupportedGenericMethod(method)
|
||||
select makeGenericMethodIfNeeded(method))
|
||||
.Where(method => !lookup.ContainsKey(method.GetParameters()[0].ParameterType));
|
||||
@@ -1104,7 +1129,7 @@ namespace CSObjectWrapEditor
|
||||
var extension_methods = (from t in ReflectionUse
|
||||
where isDefined(t, typeof(ExtensionAttribute))
|
||||
from method in t.GetMethods(BindingFlags.Static | BindingFlags.Public)
|
||||
where isDefined(method, typeof(ExtensionAttribute))
|
||||
where isDefined(method, typeof(ExtensionAttribute)) && !isObsolete(method)
|
||||
where !method.ContainsGenericParameters || isSupportedGenericMethod(method)
|
||||
select makeGenericMethodIfNeeded(method)).Concat(extension_methods_from_lcs);
|
||||
GenOne(typeof(DelegateBridgeBase), (type, type_info) =>
|
||||
@@ -1264,6 +1289,8 @@ namespace CSObjectWrapEditor
|
||||
|
||||
public static List<string> assemblyList = null;
|
||||
|
||||
public static List<Func<MemberInfo, bool>> memberFilters = null;
|
||||
|
||||
static void AddToList(List<Type> list, Func<object> get, object attr)
|
||||
{
|
||||
object obj = get();
|
||||
@@ -1376,6 +1403,10 @@ namespace CSObjectWrapEditor
|
||||
{
|
||||
BlackList.AddRange(get_cfg() as List<List<string>>);
|
||||
}
|
||||
if (isDefined(test, typeof(BlackListAttribute)) && typeof(Func<MemberInfo, bool>).IsAssignableFrom(cfg_type))
|
||||
{
|
||||
memberFilters.Add(get_cfg() as Func<MemberInfo, bool>);
|
||||
}
|
||||
|
||||
if (isDefined(test, typeof(AdditionalPropertiesAttribute))
|
||||
&& (typeof(Dictionary<Type, List<string>>)).IsAssignableFrom(cfg_type))
|
||||
@@ -1450,6 +1481,8 @@ namespace CSObjectWrapEditor
|
||||
#else
|
||||
assemblyList = new List<string>();
|
||||
#endif
|
||||
memberFilters = new List<Func<MemberInfo, bool>>();
|
||||
|
||||
foreach (var t in check_types)
|
||||
{
|
||||
MergeCfg(t, null, () => t);
|
||||
@@ -1604,7 +1637,6 @@ namespace CSObjectWrapEditor
|
||||
#if !XLUA_GENERAL
|
||||
static void callCustomGen()
|
||||
{
|
||||
return;
|
||||
foreach (var method in (from type in XLua.Utils.GetAllTypes()
|
||||
from method in type.GetMethods(BindingFlags.Static | BindingFlags.Public)
|
||||
where method.IsDefined(typeof(GenCodeMenuAttribute), false) select method))
|
||||
@@ -1703,27 +1735,6 @@ namespace CSObjectWrapEditor
|
||||
clear(GeneratorConfig.common_path);
|
||||
}
|
||||
|
||||
#if UNITY_2018
|
||||
[MenuItem("XLua/Generate Minimize Code", false, 3)]
|
||||
public static void GenMini()
|
||||
{
|
||||
var start = DateTime.Now;
|
||||
Directory.CreateDirectory(GeneratorConfig.common_path);
|
||||
GetGenConfig(XLua.Utils.GetAllTypes());
|
||||
luaenv.DoString("require 'TemplateCommon'");
|
||||
var gen_push_types_setter = luaenv.Global.Get<LuaFunction>("SetGenPushAndUpdateTypes");
|
||||
gen_push_types_setter.Call(GCOptimizeList.Where(t => !t.IsPrimitive && SizeOf(t) != -1).Distinct().ToList());
|
||||
var xlua_classes_setter = luaenv.Global.Get<LuaFunction>("SetXLuaClasses");
|
||||
xlua_classes_setter.Call(XLua.Utils.GetAllTypes().Where(t => t.Namespace == "XLua").ToList());
|
||||
GenDelegateBridges(XLua.Utils.GetAllTypes(false));
|
||||
GenCodeForClass(true);
|
||||
GenLuaRegister(true);
|
||||
callCustomGen();
|
||||
Debug.Log("finished! use " + (DateTime.Now - start).TotalMilliseconds + " ms");
|
||||
AssetDatabase.Refresh();
|
||||
}
|
||||
#endif
|
||||
|
||||
public delegate IEnumerable<CustomGenTask> GetTasks(LuaEnv lua_env, UserConfig user_cfg);
|
||||
|
||||
public static void CustomGen(string template_src, GetTasks get_tasks)
|
||||
@@ -1818,4 +1829,4 @@ namespace CSObjectWrapEditor
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
0
Assets/XLua/Src/Editor/Generator.cs.meta
Executable file → Normal file
0
Assets/XLua/Src/Editor/Generator.cs.meta
Executable file → Normal file
40
Assets/XLua/Src/Editor/Hotfix.cs
Executable file → Normal file
40
Assets/XLua/Src/Editor/Hotfix.cs
Executable file → Normal file
@@ -24,6 +24,10 @@ using UnityEngine;
|
||||
using UnityEditor;
|
||||
using UnityEditor.Callbacks;
|
||||
using System.Diagnostics;
|
||||
#if UNITY_2019
|
||||
using UnityEditor.Build;
|
||||
using UnityEditor.Build.Reporting;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
namespace XLua
|
||||
@@ -467,9 +471,9 @@ namespace XLua
|
||||
{
|
||||
invoke.Parameters.Add(new ParameterDefinition(self));
|
||||
}
|
||||
foreach (var argType in argTypes)
|
||||
for(int i = 0; i < argTypes.Count; i++)
|
||||
{
|
||||
invoke.Parameters.Add(new ParameterDefinition(argType));
|
||||
invoke.Parameters.Add(new ParameterDefinition(method.Parameters[i].Name, (method.Parameters[i].IsOut ? Mono.Cecil.ParameterAttributes.Out : Mono.Cecil.ParameterAttributes.None), argTypes[i]));
|
||||
}
|
||||
invoke.ImplAttributes = Mono.Cecil.MethodImplAttributes.Runtime;
|
||||
delegateDef.Methods.Add(invoke);
|
||||
@@ -982,6 +986,15 @@ namespace XLua
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int offset = 0;
|
||||
for (int i = 0; i < instructions.Count; i++)
|
||||
{
|
||||
var instruction = instructions[i];
|
||||
instruction.Offset = offset;
|
||||
offset += instruction.GetSize();
|
||||
}
|
||||
|
||||
for (int i = 0; i < instructions.Count; i++)
|
||||
{
|
||||
var instruction = instructions[i];
|
||||
@@ -1576,6 +1589,18 @@ namespace XLua
|
||||
|
||||
namespace XLua
|
||||
{
|
||||
#if UNITY_2019
|
||||
class MyCustomBuildProcessor : IPostBuildPlayerScriptDLLs
|
||||
{
|
||||
public int callbackOrder { get { return 0; } }
|
||||
public void OnPostBuildPlayerScriptDLLs(BuildReport report)
|
||||
{
|
||||
var dir = Path.GetDirectoryName(report.files.Single(file => file.path.EndsWith("Assembly-CSharp.dll")).path);
|
||||
Hotfix.HotfixInject(dir);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
public static class Hotfix
|
||||
{
|
||||
static bool ContainNotAsciiChar(string s)
|
||||
@@ -1590,9 +1615,16 @@ namespace XLua
|
||||
return false;
|
||||
}
|
||||
|
||||
#if !UNITY_2019
|
||||
[PostProcessScene]
|
||||
#endif
|
||||
[MenuItem("XLua/Hotfix Inject In Editor", false, 3)]
|
||||
public static void HotfixInject()
|
||||
{
|
||||
HotfixInject("./Library/ScriptAssemblies");
|
||||
}
|
||||
|
||||
public static void HotfixInject(string assemblyDir)
|
||||
{
|
||||
if (Application.isPlaying)
|
||||
{
|
||||
@@ -1628,7 +1660,7 @@ namespace XLua
|
||||
return;
|
||||
}
|
||||
|
||||
var assembly_csharp_path = "./Library/ScriptAssemblies/Assembly-CSharp.dll";
|
||||
var assembly_csharp_path = Path.Combine(assemblyDir, "Assembly-CSharp.dll");
|
||||
var id_map_file_path = CSObjectWrapEditor.GeneratorConfig.common_path + "Resources/hotfix_id_map.lua.txt";
|
||||
var hotfix_cfg_in_editor = CSObjectWrapEditor.GeneratorConfig.common_path + "hotfix_cfg_in_editor.data";
|
||||
|
||||
@@ -1670,7 +1702,7 @@ namespace XLua
|
||||
var idMapFileNames = new List<string>();
|
||||
foreach (var injectAssemblyPath in injectAssemblyPaths)
|
||||
{
|
||||
args[0] = injectAssemblyPath.Replace('\\', '/');
|
||||
args[0] = Path.Combine(assemblyDir, Path.GetFileName(injectAssemblyPath));
|
||||
if (ContainNotAsciiChar(args[0]))
|
||||
{
|
||||
throw new Exception("project path must contain only ascii characters");
|
||||
|
||||
0
Assets/XLua/Src/Editor/Hotfix.cs.meta
Executable file → Normal file
0
Assets/XLua/Src/Editor/Hotfix.cs.meta
Executable file → Normal file
0
Assets/XLua/Src/Editor/LinkXmlGen.meta
Executable file → Normal file
0
Assets/XLua/Src/Editor/LinkXmlGen.meta
Executable file → Normal file
0
Assets/XLua/Src/Editor/LinkXmlGen/LinkXmlGen.cs
Executable file → Normal file
0
Assets/XLua/Src/Editor/LinkXmlGen/LinkXmlGen.cs
Executable file → Normal file
0
Assets/XLua/Src/Editor/LinkXmlGen/LinkXmlGen.cs.meta
Executable file → Normal file
0
Assets/XLua/Src/Editor/LinkXmlGen/LinkXmlGen.cs.meta
Executable file → Normal file
0
Assets/XLua/Src/Editor/LinkXmlGen/LinkXmlGen.tpl.txt
Executable file → Normal file
0
Assets/XLua/Src/Editor/LinkXmlGen/LinkXmlGen.tpl.txt
Executable file → Normal file
0
Assets/XLua/Src/Editor/LinkXmlGen/LinkXmlGen.tpl.txt.meta
Executable file → Normal file
0
Assets/XLua/Src/Editor/LinkXmlGen/LinkXmlGen.tpl.txt.meta
Executable file → Normal file
0
Assets/XLua/Src/Editor/Template.meta
Executable file → Normal file
0
Assets/XLua/Src/Editor/Template.meta
Executable file → Normal file
3
Assets/XLua/Src/Editor/Template/LuaClassWrap.tpl.txt
Executable file → Normal file
3
Assets/XLua/Src/Editor/Template/LuaClassWrap.tpl.txt
Executable file → Normal 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)
|
||||
|
||||
0
Assets/XLua/Src/Editor/Template/LuaClassWrap.tpl.txt.meta
Executable file → Normal file
0
Assets/XLua/Src/Editor/Template/LuaClassWrap.tpl.txt.meta
Executable file → Normal file
0
Assets/XLua/Src/Editor/Template/LuaClassWrapGCM.tpl.txt
Executable file → Normal file
0
Assets/XLua/Src/Editor/Template/LuaClassWrapGCM.tpl.txt
Executable file → Normal file
0
Assets/XLua/Src/Editor/Template/LuaClassWrapGCM.tpl.txt.meta
Executable file → Normal file
0
Assets/XLua/Src/Editor/Template/LuaClassWrapGCM.tpl.txt.meta
Executable file → Normal file
0
Assets/XLua/Src/Editor/Template/LuaDelegateBridge.tpl.txt
Executable file → Normal file
0
Assets/XLua/Src/Editor/Template/LuaDelegateBridge.tpl.txt
Executable file → Normal file
0
Assets/XLua/Src/Editor/Template/LuaDelegateBridge.tpl.txt.meta
Executable file → Normal file
0
Assets/XLua/Src/Editor/Template/LuaDelegateBridge.tpl.txt.meta
Executable file → Normal file
0
Assets/XLua/Src/Editor/Template/LuaDelegateWrap.tpl.txt
Executable file → Normal file
0
Assets/XLua/Src/Editor/Template/LuaDelegateWrap.tpl.txt
Executable file → Normal file
0
Assets/XLua/Src/Editor/Template/LuaDelegateWrap.tpl.txt.meta
Executable file → Normal file
0
Assets/XLua/Src/Editor/Template/LuaDelegateWrap.tpl.txt.meta
Executable file → Normal file
25
Assets/XLua/Src/Editor/Template/LuaEnumWrap.tpl.txt
Executable file → Normal file
25
Assets/XLua/Src/Editor/Template/LuaEnumWrap.tpl.txt
Executable file → Normal 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
|
||||
|
||||
0
Assets/XLua/Src/Editor/Template/LuaEnumWrap.tpl.txt.meta
Executable file → Normal file
0
Assets/XLua/Src/Editor/Template/LuaEnumWrap.tpl.txt.meta
Executable file → Normal file
25
Assets/XLua/Src/Editor/Template/LuaEnumWrapGCM.tpl.txt
Executable file → Normal file
25
Assets/XLua/Src/Editor/Template/LuaEnumWrapGCM.tpl.txt
Executable file → Normal 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
|
||||
|
||||
0
Assets/XLua/Src/Editor/Template/LuaEnumWrapGCM.tpl.txt.meta
Executable file → Normal file
0
Assets/XLua/Src/Editor/Template/LuaEnumWrapGCM.tpl.txt.meta
Executable file → Normal file
0
Assets/XLua/Src/Editor/Template/LuaInterfaceBridge.tpl.txt
Executable file → Normal file
0
Assets/XLua/Src/Editor/Template/LuaInterfaceBridge.tpl.txt
Executable file → Normal file
0
Assets/XLua/Src/Editor/Template/LuaInterfaceBridge.tpl.txt.meta
Executable file → Normal file
0
Assets/XLua/Src/Editor/Template/LuaInterfaceBridge.tpl.txt.meta
Executable file → Normal file
0
Assets/XLua/Src/Editor/Template/LuaRegister.tpl.txt
Executable file → Normal file
0
Assets/XLua/Src/Editor/Template/LuaRegister.tpl.txt
Executable file → Normal file
0
Assets/XLua/Src/Editor/Template/LuaRegister.tpl.txt.meta
Executable file → Normal file
0
Assets/XLua/Src/Editor/Template/LuaRegister.tpl.txt.meta
Executable file → Normal file
0
Assets/XLua/Src/Editor/Template/LuaRegisterGCM.tpl.txt
Executable file → Normal file
0
Assets/XLua/Src/Editor/Template/LuaRegisterGCM.tpl.txt
Executable file → Normal file
0
Assets/XLua/Src/Editor/Template/LuaRegisterGCM.tpl.txt.meta
Executable file → Normal file
0
Assets/XLua/Src/Editor/Template/LuaRegisterGCM.tpl.txt.meta
Executable file → Normal file
1
Assets/XLua/Src/Editor/Template/LuaWrapPusher.tpl.txt
Executable file → Normal file
1
Assets/XLua/Src/Editor/Template/LuaWrapPusher.tpl.txt
Executable file → Normal 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%>");
|
||||
|
||||
0
Assets/XLua/Src/Editor/Template/LuaWrapPusher.tpl.txt.meta
Executable file → Normal file
0
Assets/XLua/Src/Editor/Template/LuaWrapPusher.tpl.txt.meta
Executable file → Normal file
0
Assets/XLua/Src/Editor/Template/PackUnpack.tpl.txt
Executable file → Normal file
0
Assets/XLua/Src/Editor/Template/PackUnpack.tpl.txt
Executable file → Normal file
0
Assets/XLua/Src/Editor/Template/PackUnpack.tpl.txt.meta
Executable file → Normal file
0
Assets/XLua/Src/Editor/Template/PackUnpack.tpl.txt.meta
Executable file → Normal file
14
Assets/XLua/Src/Editor/Template/TemplateCommon.lua.txt
Executable file → Normal file
14
Assets/XLua/Src/Editor/Template/TemplateCommon.lua.txt
Executable file → Normal 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)
|
||||
|
||||
0
Assets/XLua/Src/Editor/Template/TemplateCommon.lua.txt.meta
Executable file → Normal file
0
Assets/XLua/Src/Editor/Template/TemplateCommon.lua.txt.meta
Executable file → Normal file
0
Assets/XLua/Src/Editor/TemplateRef.cs
Executable file → Normal file
0
Assets/XLua/Src/Editor/TemplateRef.cs
Executable file → Normal file
0
Assets/XLua/Src/Editor/TemplateRef.cs.meta
Executable file → Normal file
0
Assets/XLua/Src/Editor/TemplateRef.cs.meta
Executable file → Normal file
0
Assets/XLua/Src/GenAttributes.cs
Executable file → Normal file
0
Assets/XLua/Src/GenAttributes.cs
Executable file → Normal file
0
Assets/XLua/Src/GenAttributes.cs.meta
Executable file → Normal file
0
Assets/XLua/Src/GenAttributes.cs.meta
Executable file → Normal file
0
Assets/XLua/Src/GenericDelegateBridge.cs
Executable file → Normal file
0
Assets/XLua/Src/GenericDelegateBridge.cs
Executable file → Normal file
0
Assets/XLua/Src/GenericDelegateBridge.cs.meta
Executable file → Normal file
0
Assets/XLua/Src/GenericDelegateBridge.cs.meta
Executable file → Normal file
0
Assets/XLua/Src/InternalGlobals.cs
Executable file → Normal file
0
Assets/XLua/Src/InternalGlobals.cs
Executable file → Normal file
0
Assets/XLua/Src/InternalGlobals.cs.meta
Executable file → Normal file
0
Assets/XLua/Src/InternalGlobals.cs.meta
Executable file → Normal file
0
Assets/XLua/Src/LuaBase.cs
Executable file → Normal file
0
Assets/XLua/Src/LuaBase.cs
Executable file → Normal file
0
Assets/XLua/Src/LuaBase.cs.meta
Executable file → Normal file
0
Assets/XLua/Src/LuaBase.cs.meta
Executable file → Normal file
8
Assets/XLua/Src/LuaDLL.cs
Executable file → Normal file
8
Assets/XLua/Src/LuaDLL.cs
Executable file → Normal file
@@ -33,7 +33,7 @@ namespace XLua.LuaDLL
|
||||
|
||||
public partial class Lua
|
||||
{
|
||||
#if (UNITY_IPHONE || UNITY_WEBGL || UNITY_SWITCH) && !UNITY_EDITOR
|
||||
#if (UNITY_IPHONE || UNITY_TVOS || UNITY_WEBGL || UNITY_SWITCH) && !UNITY_EDITOR
|
||||
const string LUADLL = "__Internal";
|
||||
#else
|
||||
const string LUADLL = "xlua";
|
||||
@@ -292,7 +292,7 @@ namespace XLua.LuaDLL
|
||||
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void lua_pushstring(IntPtr L, string str);
|
||||
#else
|
||||
public static void lua_pushstring(IntPtr L, string str) //ҵ<EFBFBD><EFBFBD>ʹ<EFBFBD><EFBFBD>
|
||||
public static void lua_pushstring(IntPtr L, string str) //业务使用
|
||||
{
|
||||
if (str == null)
|
||||
{
|
||||
@@ -456,7 +456,7 @@ namespace XLua.LuaDLL
|
||||
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int luaopen_i64lib(IntPtr L);//[,,m]
|
||||
|
||||
#if !UNITY_SWITCH || UNITY_EDITOR
|
||||
#if (!UNITY_SWITCH && !UNITY_WEBGL) || UNITY_EDITOR
|
||||
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int luaopen_socket_core(IntPtr L);//[,,m]
|
||||
#endif
|
||||
@@ -542,7 +542,7 @@ namespace XLua.LuaDLL
|
||||
//[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
|
||||
//public static extern void xlua_pushbuffer(IntPtr L, byte[] buff);
|
||||
|
||||
//<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Unity<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɵ<EFBFBD>struct<EFBFBD>϶࣬<EFBFBD>⼸<EFBFBD><EFBFBD>api<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ż<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>struct
|
||||
//对于Unity,仅浮点组成的struct较多,这几个api用于优化这类struct
|
||||
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern bool xlua_pack_float2(IntPtr buff, int offset, float f1, float f2);
|
||||
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
|
||||
|
||||
0
Assets/XLua/Src/LuaDLL.cs.meta
Executable file → Normal file
0
Assets/XLua/Src/LuaDLL.cs.meta
Executable file → Normal file
4
Assets/XLua/Src/LuaEnv.cs
Executable file → Normal file
4
Assets/XLua/Src/LuaEnv.cs
Executable file → Normal file
@@ -71,8 +71,8 @@ namespace XLua
|
||||
|
||||
#if THREAD_SAFE || HOTFIX_ENABLE
|
||||
lock(luaEnvLock)
|
||||
{
|
||||
#endif
|
||||
{
|
||||
LuaIndexes.LUA_REGISTRYINDEX = LuaAPI.xlua_get_registry_index();
|
||||
#if GEN_CODE_MINIMIZE
|
||||
LuaAPI.xlua_set_csharp_wrapper_caller(InternalGlobals.CSharpWrapperCallerPtr);
|
||||
@@ -184,9 +184,7 @@ namespace XLua
|
||||
translator.CreateArrayMetatable(rawL);
|
||||
translator.CreateDelegateMetatable(rawL);
|
||||
translator.CreateEnumerablePairs(rawL);
|
||||
#if THREAD_SAFE || HOTFIX_ENABLE
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
private static List<Action<LuaEnv, ObjectTranslator>> initers = null;
|
||||
|
||||
0
Assets/XLua/Src/LuaEnv.cs.meta
Executable file → Normal file
0
Assets/XLua/Src/LuaEnv.cs.meta
Executable file → Normal file
0
Assets/XLua/Src/LuaException.cs
Executable file → Normal file
0
Assets/XLua/Src/LuaException.cs
Executable file → Normal file
0
Assets/XLua/Src/LuaException.cs.meta
Executable file → Normal file
0
Assets/XLua/Src/LuaException.cs.meta
Executable file → Normal file
0
Assets/XLua/Src/LuaFunction.cs
Executable file → Normal file
0
Assets/XLua/Src/LuaFunction.cs
Executable file → Normal file
0
Assets/XLua/Src/LuaFunction.cs.meta
Executable file → Normal file
0
Assets/XLua/Src/LuaFunction.cs.meta
Executable file → Normal file
0
Assets/XLua/Src/LuaTable.cs
Executable file → Normal file
0
Assets/XLua/Src/LuaTable.cs
Executable file → Normal file
0
Assets/XLua/Src/LuaTable.cs.meta
Executable file → Normal file
0
Assets/XLua/Src/LuaTable.cs.meta
Executable file → Normal file
0
Assets/XLua/Src/MethodWarpsCache.cs
Executable file → Normal file
0
Assets/XLua/Src/MethodWarpsCache.cs
Executable file → Normal file
0
Assets/XLua/Src/MethodWarpsCache.cs.meta
Executable file → Normal file
0
Assets/XLua/Src/MethodWarpsCache.cs.meta
Executable file → Normal file
0
Assets/XLua/Src/ObjectCasters.cs
Executable file → Normal file
0
Assets/XLua/Src/ObjectCasters.cs
Executable file → Normal file
0
Assets/XLua/Src/ObjectCasters.cs.meta
Executable file → Normal file
0
Assets/XLua/Src/ObjectCasters.cs.meta
Executable file → Normal file
0
Assets/XLua/Src/ObjectPool.cs
Executable file → Normal file
0
Assets/XLua/Src/ObjectPool.cs
Executable file → Normal file
0
Assets/XLua/Src/ObjectPool.cs.meta
Executable file → Normal file
0
Assets/XLua/Src/ObjectPool.cs.meta
Executable file → Normal file
161
Assets/XLua/Src/ObjectTranslator.cs
Executable file → Normal file
161
Assets/XLua/Src/ObjectTranslator.cs
Executable file → Normal file
@@ -186,7 +186,7 @@ namespace XLua
|
||||
{
|
||||
continue;
|
||||
}
|
||||
TryDelayWrapLoader(L, nested_type);
|
||||
GetTypeId(L, nested_type);
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -346,76 +346,74 @@ namespace XLua
|
||||
#endif
|
||||
MethodInfo[] genericAction = null;
|
||||
MethodInfo[] genericFunc = null;
|
||||
Dictionary<Type, Func<DelegateBridgeBase, Delegate>> genericDelegateCreatorCache
|
||||
Dictionary<Type, Func<DelegateBridgeBase, Delegate>> delegateCreatorCache
|
||||
= new Dictionary<Type, Func<DelegateBridgeBase, Delegate>>();
|
||||
|
||||
Delegate getDelegateUsingGeneric(DelegateBridgeBase bridge, Type delegateType, MethodInfo delegateMethod)
|
||||
Func<DelegateBridgeBase, Delegate> getCreatorUsingGeneric(DelegateBridgeBase bridge, Type delegateType, MethodInfo delegateMethod)
|
||||
{
|
||||
Func<DelegateBridgeBase, Delegate> genericDelegateCreator;
|
||||
if (!genericDelegateCreatorCache.TryGetValue(delegateType, out genericDelegateCreator))
|
||||
Func<DelegateBridgeBase, Delegate> genericDelegateCreator = null;
|
||||
|
||||
if (genericAction == null)
|
||||
{
|
||||
if (genericAction == null)
|
||||
{
|
||||
var methods = typeof(DelegateBridge).GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly);
|
||||
genericAction = methods.Where(m => m.Name == "Action").OrderBy(m => m.GetParameters().Length).ToArray();
|
||||
genericFunc = methods.Where(m => m.Name == "Func").OrderBy(m => m.GetParameters().Length).ToArray();
|
||||
}
|
||||
if (genericAction.Length != 5 || genericFunc.Length != 5)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
var parameters = delegateMethod.GetParameters();
|
||||
if ((delegateMethod.ReturnType.IsValueType() && delegateMethod.ReturnType != typeof(void)) || parameters.Length > 4)
|
||||
{
|
||||
genericDelegateCreator = (x) => null;
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var pinfo in parameters)
|
||||
{
|
||||
if (pinfo.ParameterType.IsValueType() || pinfo.IsOut || pinfo.ParameterType.IsByRef)
|
||||
{
|
||||
genericDelegateCreator = (x) => null;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (genericDelegateCreator == null)
|
||||
{
|
||||
var typeArgs = parameters.Select(pinfo => pinfo.ParameterType);
|
||||
MethodInfo genericMethodInfo = null;
|
||||
if (delegateMethod.ReturnType == typeof(void))
|
||||
{
|
||||
genericMethodInfo = genericAction[parameters.Length];
|
||||
}
|
||||
else
|
||||
{
|
||||
genericMethodInfo = genericFunc[parameters.Length];
|
||||
typeArgs = typeArgs.Concat(new Type[] { delegateMethod.ReturnType });
|
||||
}
|
||||
if (genericMethodInfo.IsGenericMethodDefinition)
|
||||
{
|
||||
var methodInfo = genericMethodInfo.MakeGenericMethod(typeArgs.ToArray());
|
||||
genericDelegateCreator = (o) =>
|
||||
#if !UNITY_WSA || UNITY_EDITOR
|
||||
Delegate.CreateDelegate(delegateType, o, methodInfo);
|
||||
#else
|
||||
methodInfo.CreateDelegate(delegateType, bridge);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
genericDelegateCreator = (o) =>
|
||||
#if !UNITY_WSA || UNITY_EDITOR
|
||||
Delegate.CreateDelegate(delegateType, o, genericMethodInfo);
|
||||
#else
|
||||
genericMethodInfo.CreateDelegate(delegateType, o);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
genericDelegateCreatorCache.Add(delegateType, genericDelegateCreator);
|
||||
var methods = typeof(DelegateBridge).GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly);
|
||||
genericAction = methods.Where(m => m.Name == "Action").OrderBy(m => m.GetParameters().Length).ToArray();
|
||||
genericFunc = methods.Where(m => m.Name == "Func").OrderBy(m => m.GetParameters().Length).ToArray();
|
||||
}
|
||||
return genericDelegateCreator(bridge);
|
||||
if (genericAction.Length != 5 || genericFunc.Length != 5)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
var parameters = delegateMethod.GetParameters();
|
||||
if ((delegateMethod.ReturnType.IsValueType() && delegateMethod.ReturnType != typeof(void)) || parameters.Length > 4)
|
||||
{
|
||||
genericDelegateCreator = (x) => null;
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var pinfo in parameters)
|
||||
{
|
||||
if (pinfo.ParameterType.IsValueType() || pinfo.IsOut || pinfo.ParameterType.IsByRef)
|
||||
{
|
||||
genericDelegateCreator = (x) => null;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (genericDelegateCreator == null)
|
||||
{
|
||||
var typeArgs = parameters.Select(pinfo => pinfo.ParameterType);
|
||||
MethodInfo genericMethodInfo = null;
|
||||
if (delegateMethod.ReturnType == typeof(void))
|
||||
{
|
||||
genericMethodInfo = genericAction[parameters.Length];
|
||||
}
|
||||
else
|
||||
{
|
||||
genericMethodInfo = genericFunc[parameters.Length];
|
||||
typeArgs = typeArgs.Concat(new Type[] { delegateMethod.ReturnType });
|
||||
}
|
||||
if (genericMethodInfo.IsGenericMethodDefinition)
|
||||
{
|
||||
var methodInfo = genericMethodInfo.MakeGenericMethod(typeArgs.ToArray());
|
||||
genericDelegateCreator = (o) =>
|
||||
#if !UNITY_WSA || UNITY_EDITOR
|
||||
Delegate.CreateDelegate(delegateType, o, methodInfo);
|
||||
#else
|
||||
methodInfo.CreateDelegate(delegateType, bridge);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
genericDelegateCreator = (o) =>
|
||||
#if !UNITY_WSA || UNITY_EDITOR
|
||||
Delegate.CreateDelegate(delegateType, o, genericMethodInfo);
|
||||
#else
|
||||
genericMethodInfo.CreateDelegate(delegateType, o);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return genericDelegateCreator;
|
||||
}
|
||||
|
||||
Delegate getDelegate(DelegateBridgeBase bridge, Type delegateType)
|
||||
@@ -432,22 +430,35 @@ namespace XLua
|
||||
return null;
|
||||
}
|
||||
|
||||
// get by parameters
|
||||
MethodInfo delegateMethod = delegateType.GetMethod("Invoke");
|
||||
var methods = bridge.GetType().GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly).Where(m => !m.IsGenericMethodDefinition && (m.Name.StartsWith("__Gen_Delegate_Imp") || m.Name == "Action")).ToArray();
|
||||
for (int i = 0; i < methods.Length; i++)
|
||||
Func<DelegateBridgeBase, Delegate> delegateCreator;
|
||||
if (!delegateCreatorCache.TryGetValue(delegateType, out delegateCreator))
|
||||
{
|
||||
if (!methods[i].IsConstructor && Utils.IsParamsMatch(delegateMethod, methods[i]))
|
||||
// get by parameters
|
||||
MethodInfo delegateMethod = delegateType.GetMethod("Invoke");
|
||||
var methods = bridge.GetType().GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly).Where(m => !m.IsGenericMethodDefinition && (m.Name.StartsWith("__Gen_Delegate_Imp") || m.Name == "Action")).ToArray();
|
||||
for (int i = 0; i < methods.Length; i++)
|
||||
{
|
||||
if (!methods[i].IsConstructor && Utils.IsParamsMatch(delegateMethod, methods[i]))
|
||||
{
|
||||
var foundMethod = methods[i];
|
||||
delegateCreator = (o) =>
|
||||
#if !UNITY_WSA || UNITY_EDITOR
|
||||
return Delegate.CreateDelegate(delegateType, bridge, methods[i]);
|
||||
Delegate.CreateDelegate(delegateType, o, foundMethod);
|
||||
#else
|
||||
return methods[i].CreateDelegate(delegateType, bridge);
|
||||
foundMethod.CreateDelegate(delegateType, o);
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (delegateCreator == null)
|
||||
{
|
||||
delegateCreator = getCreatorUsingGeneric(bridge, delegateType, delegateMethod);
|
||||
}
|
||||
delegateCreatorCache.Add(delegateType, delegateCreator);
|
||||
}
|
||||
|
||||
ret = getDelegateUsingGeneric(bridge, delegateType, delegateMethod);
|
||||
ret = delegateCreator(bridge);
|
||||
if (ret != null)
|
||||
{
|
||||
return ret;
|
||||
@@ -1148,7 +1159,7 @@ namespace XLua
|
||||
{
|
||||
LuaAPI.lua_pushstring(L, o as string);
|
||||
}
|
||||
else if (o is byte[])
|
||||
else if (type == typeof(byte[]))
|
||||
{
|
||||
LuaAPI.lua_pushstring(L, o as byte[]);
|
||||
}
|
||||
|
||||
0
Assets/XLua/Src/ObjectTranslator.cs.meta
Executable file → Normal file
0
Assets/XLua/Src/ObjectTranslator.cs.meta
Executable file → Normal file
0
Assets/XLua/Src/ObjectTranslatorPool.cs
Executable file → Normal file
0
Assets/XLua/Src/ObjectTranslatorPool.cs
Executable file → Normal file
0
Assets/XLua/Src/ObjectTranslatorPool.cs.meta
Executable file → Normal file
0
Assets/XLua/Src/ObjectTranslatorPool.cs.meta
Executable file → Normal file
0
Assets/XLua/Src/RawObject.cs
Executable file → Normal file
0
Assets/XLua/Src/RawObject.cs
Executable file → Normal file
0
Assets/XLua/Src/RawObject.cs.meta
Executable file → Normal file
0
Assets/XLua/Src/RawObject.cs.meta
Executable file → Normal file
0
Assets/XLua/Src/SignatureLoader.cs
Executable file → Normal file
0
Assets/XLua/Src/SignatureLoader.cs
Executable file → Normal file
0
Assets/XLua/Src/SignatureLoader.cs.meta
Executable file → Normal file
0
Assets/XLua/Src/SignatureLoader.cs.meta
Executable file → Normal file
2
Assets/XLua/Src/StaticLuaCallbacks.cs
Executable file → Normal file
2
Assets/XLua/Src/StaticLuaCallbacks.cs
Executable file → Normal file
@@ -636,7 +636,7 @@ namespace XLua
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !UNITY_SWITCH || UNITY_EDITOR
|
||||
#if (!UNITY_SWITCH && !UNITY_WEBGL) || UNITY_EDITOR
|
||||
[MonoPInvokeCallback(typeof(LuaCSFunction))]
|
||||
internal static int LoadSocketCore(RealStatePtr L)
|
||||
{
|
||||
|
||||
0
Assets/XLua/Src/StaticLuaCallbacks.cs.meta
Executable file → Normal file
0
Assets/XLua/Src/StaticLuaCallbacks.cs.meta
Executable file → Normal file
0
Assets/XLua/Src/TemplateEngine.meta
Executable file → Normal file
0
Assets/XLua/Src/TemplateEngine.meta
Executable file → Normal file
0
Assets/XLua/Src/TemplateEngine/TemplateEngine.cs
Executable file → Normal file
0
Assets/XLua/Src/TemplateEngine/TemplateEngine.cs
Executable file → Normal file
0
Assets/XLua/Src/TemplateEngine/TemplateEngine.cs.meta
Executable file → Normal file
0
Assets/XLua/Src/TemplateEngine/TemplateEngine.cs.meta
Executable file → Normal file
0
Assets/XLua/Src/TypeExtensions.cs
Executable file → Normal file
0
Assets/XLua/Src/TypeExtensions.cs
Executable file → Normal file
0
Assets/XLua/Src/TypeExtensions.cs.meta
Executable file → Normal file
0
Assets/XLua/Src/TypeExtensions.cs.meta
Executable file → Normal file
46
Assets/XLua/Src/Utils.cs
Executable file → Normal file
46
Assets/XLua/Src/Utils.cs
Executable file → Normal file
@@ -407,7 +407,9 @@ namespace XLua
|
||||
FieldInfo[] fields = type.GetFields(flag);
|
||||
EventInfo[] all_events = type.GetEvents(flag | BindingFlags.Public | BindingFlags.NonPublic);
|
||||
|
||||
for (int i = 0; i < fields.Length; ++i)
|
||||
LuaAPI.lua_checkstack(L, 2);
|
||||
|
||||
for (int i = 0; i < fields.Length; ++i)
|
||||
{
|
||||
FieldInfo field = fields[i];
|
||||
string fieldName = field.Name;
|
||||
@@ -578,14 +580,15 @@ namespace XLua
|
||||
}
|
||||
}
|
||||
|
||||
public static void loadUpvalue(RealStatePtr L, Type type, string metafunc, int num)
|
||||
public static void loadUpvalue(RealStatePtr L, Type type, string metafunc, int index)
|
||||
{
|
||||
ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);
|
||||
LuaAPI.xlua_pushasciistring(L, metafunc);
|
||||
LuaAPI.lua_rawget(L, LuaIndexes.LUA_REGISTRYINDEX);
|
||||
translator.Push(L, type);
|
||||
LuaAPI.lua_rawget(L, -2);
|
||||
for (int i = 1; i <= num; i++)
|
||||
LuaAPI.lua_remove(L, -2);
|
||||
for (int i = 1; i <= index; i++)
|
||||
{
|
||||
LuaAPI.lua_getupvalue(L, -i, i);
|
||||
if (LuaAPI.lua_isnil(L, -1))
|
||||
@@ -596,15 +599,27 @@ namespace XLua
|
||||
LuaAPI.lua_setupvalue(L, -i - 2, i);
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < num; i++)
|
||||
for (int i = 0; i < index; i++)
|
||||
{
|
||||
LuaAPI.lua_remove(L, -num - 1);
|
||||
LuaAPI.lua_remove(L, -2);
|
||||
}
|
||||
}
|
||||
|
||||
public static void MakePrivateAccessible(RealStatePtr L, Type type)
|
||||
public static void RegisterEnumType(RealStatePtr L, Type type)
|
||||
{
|
||||
ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);
|
||||
foreach (var name in Enum.GetNames(type))
|
||||
{
|
||||
RegisterObject(L, translator, Utils.CLS_IDX, name, Enum.Parse(type, name));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void MakePrivateAccessible(RealStatePtr L, Type type)
|
||||
{
|
||||
int oldTop = LuaAPI.lua_gettop(L);
|
||||
LuaAPI.lua_checkstack(L, 20);
|
||||
|
||||
int oldTop = LuaAPI.lua_gettop(L);
|
||||
|
||||
LuaAPI.luaL_getmetatable(L, type.FullName);
|
||||
if (LuaAPI.lua_isnil(L, -1))
|
||||
@@ -624,7 +639,8 @@ namespace XLua
|
||||
|
||||
loadUpvalue(L, type, LuaIndexsFieldName, 2);
|
||||
int obj_getter = LuaAPI.lua_gettop(L);
|
||||
int obj_field = obj_getter - 1;
|
||||
loadUpvalue(L, type, LuaIndexsFieldName, 1);
|
||||
int obj_field = LuaAPI.lua_gettop(L);
|
||||
|
||||
loadUpvalue(L, type, LuaNewIndexsFieldName, 1);
|
||||
int obj_setter = LuaAPI.lua_gettop(L);
|
||||
@@ -721,7 +737,6 @@ namespace XLua
|
||||
if (memberType == LazyMemberTypes.FieldGet)
|
||||
{
|
||||
loadUpvalue(L, type, LuaIndexsFieldName, 2);
|
||||
LuaAPI.lua_remove(L, -2);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -755,7 +770,6 @@ namespace XLua
|
||||
if (memberType == LazyMemberTypes.PropertyGet)
|
||||
{
|
||||
loadUpvalue(L, type, LuaIndexsFieldName, 2);
|
||||
LuaAPI.lua_remove(L, -2);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -808,7 +822,9 @@ namespace XLua
|
||||
|
||||
public static void ReflectionWrap(RealStatePtr L, Type type, bool privateAccessible)
|
||||
{
|
||||
int top_enter = LuaAPI.lua_gettop(L);
|
||||
LuaAPI.lua_checkstack(L, 20);
|
||||
|
||||
int top_enter = LuaAPI.lua_gettop(L);
|
||||
ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);
|
||||
//create obj meta table
|
||||
LuaAPI.luaL_getmetatable(L, type.FullName);
|
||||
@@ -841,7 +857,7 @@ namespace XLua
|
||||
LuaAPI.lua_newtable(L);
|
||||
int cls_setter = LuaAPI.lua_gettop(L);
|
||||
|
||||
LuaCSFunction item_getter;
|
||||
LuaCSFunction item_getter;
|
||||
LuaCSFunction item_setter;
|
||||
makeReflectionWrap(L, type, cls_field, cls_getter, cls_setter, obj_field, obj_getter, obj_setter, obj_meta,
|
||||
out item_getter, out item_setter, privateAccessible ? (BindingFlags.Public | BindingFlags.NonPublic) : BindingFlags.Public);
|
||||
@@ -1352,8 +1368,9 @@ namespace XLua
|
||||
LuaAPI.xlua_pushasciistring(L, path[i]);
|
||||
if (0 != LuaAPI.xlua_pgettable(L, -2))
|
||||
{
|
||||
var err = LuaAPI.lua_tostring(L, -1);
|
||||
LuaAPI.lua_settop(L, oldTop);
|
||||
throw new Exception("SetCSTable for [" + type + "] error: " + LuaAPI.lua_tostring(L, -1));
|
||||
throw new Exception("SetCSTable for [" + type + "] error: " + err);
|
||||
}
|
||||
if (LuaAPI.lua_isnil(L, -1))
|
||||
{
|
||||
@@ -1417,7 +1434,8 @@ namespace XLua
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
var lastPos = delegateParams.Length - 1;
|
||||
return lastPos < 0 || delegateParams[lastPos].IsDefined(typeof(ParamArrayAttribute), false) == bridgeParams[lastPos].IsDefined(typeof(ParamArrayAttribute), false);
|
||||
}
|
||||
|
||||
public static bool IsSupportedMethod(MethodInfo method)
|
||||
|
||||
0
Assets/XLua/Src/Utils.cs.meta
Executable file → Normal file
0
Assets/XLua/Src/Utils.cs.meta
Executable file → Normal file
Reference in New Issue
Block a user