Skip to content

Commit

Permalink
emit: wrap支持params
Browse files Browse the repository at this point in the history
  • Loading branch information
chexiongsheng committed Aug 21, 2017
1 parent adb23f4 commit ccda839
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions Assets/XLua/Src/CodeEmit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class CodeEmit
private MethodInfo LuaAPI_lua_pcall = typeof(LuaAPI).GetMethod("lua_pcall");
private MethodInfo ObjectTranslator_GetObject = typeof(ObjectTranslator).GetMethod("GetObject", new Type[] { typeof(RealStatePtr),
typeof(int), typeof(Type)});
private MethodInfo ObjectTranslator_GetParams = typeof(ObjectTranslator).GetMethod("GetParams", new Type[] { typeof(RealStatePtr), typeof(int) });
private MethodInfo LuaAPI_lua_pushvalue = typeof(LuaAPI).GetMethod("lua_pushvalue");
private MethodInfo LuaAPI_lua_remove = typeof(LuaAPI).GetMethod("lua_remove");
private MethodInfo LuaAPI_lua_pushstring = typeof(LuaAPI).GetMethod("lua_pushstring", new Type[] { typeof(RealStatePtr), typeof(string)});
Expand Down Expand Up @@ -266,7 +267,7 @@ public Type EmitDelegateImpl(IEnumerable<IGrouping<MethodInfo, Type>> groups)
return impl_type_builder.CreateType();
}

private void EmitGetObject(ILGenerator il, int offset, Type type, LocalBuilder L, LocalBuilder translator, LocalBuilder offsetBase)
private void EmitGetObject(ILGenerator il, int offset, Type type, LocalBuilder L, LocalBuilder translator, LocalBuilder offsetBase, bool isParam = false)
{
if (!fixCaster.ContainsKey(type) && !typedCaster.ContainsKey(type))
{
Expand Down Expand Up @@ -324,9 +325,16 @@ private void EmitGetObject(ILGenerator il, int offset, Type type, LocalBuilder L
}
else
{
il.Emit(OpCodes.Ldtoken, type);
il.Emit(OpCodes.Call, Type_GetTypeFromHandle); // typeof(type)
il.Emit(OpCodes.Callvirt, ObjectTranslator_GetObject);
if (isParam)
{
il.Emit(OpCodes.Callvirt, ObjectTranslator_GetParams.MakeGenericMethod(new Type[] { type.GetElementType() }));
}
else
{
il.Emit(OpCodes.Ldtoken, type);
il.Emit(OpCodes.Call, Type_GetTypeFromHandle); // typeof(type)
il.Emit(OpCodes.Callvirt, ObjectTranslator_GetObject);
}
if (type.IsValueType)
{
Label not_null = il.DefineLabel();
Expand Down Expand Up @@ -1376,7 +1384,8 @@ MethodBuilder emitMethodWrap(TypeBuilder typeBuilder, List<MethodBase> methodsTo
}
if (!paramInfo.IsOut)
{
EmitGetObject(il, luaPos++, paramRawType, L, translator, null);
bool isParam = paramInfo.IsDefined(typeof(ParamArrayAttribute), false);
EmitGetObject(il, luaPos++, paramRawType, L, translator, null, isParam);
il.Emit(OpCodes.Stloc, argStore);
}
}
Expand Down

0 comments on commit ccda839

Please sign in to comment.