Skip to content

Commit

Permalink
Merge pull request #1067 from ps5mh/feature_asmdef
Browse files Browse the repository at this point in the history
* fix gen code for asmdef feature
  • Loading branch information
xuyanghuang-tencent authored Jun 12, 2023
2 parents 0d1e3eb + c5a8537 commit d860056
Show file tree
Hide file tree
Showing 14 changed files with 20 additions and 10 deletions.
3 changes: 3 additions & 0 deletions Assets/XLua/Src/DelegateBridge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,12 @@ public abstract class DelegateBridgeBase : LuaBase

protected int errorFuncRef;

protected RealStatePtr rawL;

public DelegateBridgeBase(int reference, LuaEnv luaenv) : base(reference, luaenv)
{
errorFuncRef = luaenv.errorFuncRef;
rawL = luaenv.rawL;
}

public bool TryGetDelegate(Type key, out Delegate value)
Expand Down
9 changes: 7 additions & 2 deletions Assets/XLua/Src/Editor/Hotfix.cs
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ public class Hotfix
{
private TypeReference objType = null;
private TypeReference delegateBridgeType = null;
private TypeReference delegateBridgeWrapType = null;
private AssemblyDefinition injectAssembly = null;

private MethodReference delegateBridgeGetter = null;
Expand Down Expand Up @@ -293,6 +294,7 @@ public void Init(AssemblyDefinition injectAssembly, AssemblyDefinition xluaAssem
var delegateBridgeTypeDef = xluaAssembly.MainModule.Types.Single(t => t.FullName == "XLua.DelegateBridge");
var delegateBridgeTypeWrapDef = genAssembly.MainModule.Types.SingleOrDefault(t => t.FullName == "XLua.DelegateBridge_Wrap");
delegateBridgeType = injectModule.TryImport(delegateBridgeTypeDef);
delegateBridgeWrapType = injectModule.TryImport(delegateBridgeTypeWrapDef);
delegateBridgeGetter = injectModule.TryImport(xluaAssembly.MainModule.Types.Single(t => t.FullName == "XLua.HotfixDelegateBridge")
.Methods.Single(m => m.Name == "Get"));
hotfixFlagGetter = injectModule.TryImport(xluaAssembly.MainModule.Types.Single(t => t.FullName == "XLua.HotfixDelegateBridge")
Expand Down Expand Up @@ -1280,6 +1282,7 @@ bool injectMethod(MethodDefinition method, HotfixFlagInTool hotfixType)
{
processor.InsertBefore(insertPoint, processor.Create(OpCodes.Ldc_I4, bridgeIndexByKey.Count));
processor.InsertBefore(insertPoint, processor.Create(OpCodes.Call, delegateBridgeGetter));
processor.InsertBefore(insertPoint, processor.Create(OpCodes.Castclass, delegateBridgeWrapType));
}
else
{
Expand Down Expand Up @@ -1422,6 +1425,7 @@ bool injectGenericMethod(MethodDefinition method, HotfixFlagInTool hotfixType)
processor.InsertBefore(insertPoint, jmpInstruction);
processor.InsertBefore(insertPoint, processor.Create(OpCodes.Ldc_I4, bridgeIndexByKey.Count));
processor.InsertBefore(insertPoint, processor.Create(OpCodes.Call, delegateBridgeGetter));
processor.InsertBefore(insertPoint, processor.Create(OpCodes.Castclass, delegateBridgeWrapType));
processor.InsertBefore(insertPoint, processor.Create(OpCodes.Stloc, injection));
}
else
Expand Down Expand Up @@ -1716,9 +1720,10 @@ public static void HotfixInject(string assemblyDir)
}
}

var genCodeAssemblyPath = (from assembly in AppDomain.CurrentDomain.GetAssemblies()
var genCodeAssemblyPathInProject = (from assembly in AppDomain.CurrentDomain.GetAssemblies()
select assembly.GetType("XLua.DelegateBridge_Wrap")).FirstOrDefault(x => x != null).Module.FullyQualifiedName;

var genCodeAssemblyFileName = Path.GetFileName(genCodeAssemblyPathInProject);
var genCodeAssemblyPath = Path.Combine(assemblyDir, genCodeAssemblyFileName);
List< string> args = new List<string>() { assembly_csharp_path,
typeof(LuaEnv).Module.FullyQualifiedName,
genCodeAssemblyPath,
Expand Down
2 changes: 1 addition & 1 deletion Assets/XLua/Src/Editor/Template/LuaDelegateBridge.tpl.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ namespace XLua
lock (luaEnv.luaEnvLock)
{
#endif
RealStatePtr L = luaEnv.L;
RealStatePtr L = this.rawL;
int errFunc = LuaAPI.pcall_prepare(L, errorFuncRef, luaReference);
<%if CallNeedTranslator(delegate, "") then %>ObjectTranslator translator = luaEnv.translator;<%end%>
<%
Expand Down
16 changes: 9 additions & 7 deletions Assets/XLua/Src/Editor/Template/LuaInterfaceBridge.tpl.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ namespace XLua.CSObjectWrap
{
public class <%=CSVariableName(type)%>Bridge : LuaBase, <%=CsFullTypeName(type)%>
{
RealStatePtr rawL;
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)
{
rawL = luaenv.L;
}

<%
Expand Down Expand Up @@ -55,7 +57,7 @@ namespace XLua.CSObjectWrap
lock (luaEnv.luaEnvLock)
{
#endif
RealStatePtr L = luaEnv.L;
RealStatePtr L = this.rawL;
int err_func = LuaAPI.load_error_func(L, luaEnv.errorFuncRef);
<%if CallNeedTranslator(method, "") then %>ObjectTranslator translator = luaEnv.translator;<%end%>

Expand Down Expand Up @@ -114,7 +116,7 @@ namespace XLua.CSObjectWrap
lock (luaEnv.luaEnvLock)
{
#endif
RealStatePtr L = luaEnv.L;
RealStatePtr L = this.rawL;
int oldTop = LuaAPI.lua_gettop(L);
<%if not JustLuaType(property.PropertyType) then %>ObjectTranslator translator = luaEnv.translator;<%end%>
LuaAPI.lua_getref(L, luaReference);
Expand All @@ -138,7 +140,7 @@ namespace XLua.CSObjectWrap
lock (luaEnv.luaEnvLock)
{
#endif
RealStatePtr L = luaEnv.L;
RealStatePtr L = this.rawL;
int oldTop = LuaAPI.lua_gettop(L);
<%if not JustLuaType(property.PropertyType) then %>ObjectTranslator translator = luaEnv.translator;<%end%>
LuaAPI.lua_getref(L, luaReference);
Expand Down Expand Up @@ -166,7 +168,7 @@ namespace XLua.CSObjectWrap
lock (luaEnv.luaEnvLock)
{
#endif
RealStatePtr L = luaEnv.L;
RealStatePtr L = this.rawL;
int err_func = LuaAPI.load_error_func(L, luaEnv.errorFuncRef);
<%if CallNeedTranslator(event:GetAddMethod(), "") then %>ObjectTranslator translator = luaEnv.translator;<%end%>

Expand Down Expand Up @@ -209,7 +211,7 @@ namespace XLua.CSObjectWrap
lock (luaEnv.luaEnvLock)
{
#endif
RealStatePtr L = luaEnv.L;
RealStatePtr L = this.rawL;
int err_func = LuaAPI.load_error_func(L, luaEnv.errorFuncRef);
<%if CallNeedTranslator(event:GetRemoveMethod(), "") then %>ObjectTranslator translator = luaEnv.translator;<%end%>

Expand Down Expand Up @@ -270,7 +272,7 @@ namespace XLua.CSObjectWrap
lock (luaEnv.luaEnvLock)
{
#endif
RealStatePtr L = luaEnv.L;
RealStatePtr L = this.rawL;
int err_func = LuaAPI.load_error_func(L, luaEnv.errorFuncRef);
<%if CallNeedTranslator(method, "") then %>ObjectTranslator translator = luaEnv.translator;<%end%>

Expand Down Expand Up @@ -333,7 +335,7 @@ namespace XLua.CSObjectWrap
lock (luaEnv.luaEnvLock)
{
#endif
RealStatePtr L = luaEnv.L;
RealStatePtr L = this.rawL;
int err_func = LuaAPI.load_error_func(L, luaEnv.errorFuncRef);
<%if CallNeedTranslator(method, "") then %>ObjectTranslator translator = luaEnv.translator;<%end%>

Expand Down
Binary file modified Tools/FilesSignature.exe
Binary file not shown.
Binary file modified Tools/FilesSignature.pdb
Binary file not shown.
Binary file modified Tools/KeyPairsGen.exe
Binary file not shown.
Binary file modified Tools/KeyPairsGen.pdb
Binary file not shown.
Binary file modified Tools/XLua.Mini.dll
Binary file not shown.
Binary file modified Tools/XLua.Mini.pdb
Binary file not shown.
Binary file modified Tools/XLuaGenerate.exe
Binary file not shown.
Binary file modified Tools/XLuaGenerate.pdb
Binary file not shown.
Binary file modified Tools/XLuaHotfixInject.exe
Binary file not shown.
Binary file modified Tools/XLuaHotfixInject.pdb
Binary file not shown.

0 comments on commit d860056

Please sign in to comment.