public LuaMethodWrapper(ObjectTranslator translator, IReflect targetType, string methodName, BindingFlags bindingType) { this._LastCalledMethod = new MethodCache(); this._Translator = translator; this._MethodName = methodName; this._TargetType = targetType; if (targetType != null) { this._ExtractTarget = translator.typeChecker.getExtractor(targetType); } this._BindingType = bindingType; this._Members = targetType.UnderlyingSystemType.GetMember(methodName, MemberTypes.Method, (bindingType | BindingFlags.Public) | BindingFlags.IgnoreCase); }
public static int callConstructor(IntPtr luaState) { ObjectTranslator objectTranslator = ObjectTranslator.FromState(luaState); MethodCache methodCache = default(MethodCache); object rawNetObject = objectTranslator.getRawNetObject(luaState, 1); if (rawNetObject == null || !(rawNetObject is IReflect)) { LuaDLL.luaL_error(luaState, "trying to call constructor on an invalid type reference"); LuaDLL.lua_pushnil(luaState); return(1); } IReflect reflect = (IReflect)rawNetObject; LuaDLL.lua_remove(luaState, 1); ConstructorInfo[] constructors = reflect.get_UnderlyingSystemType().GetConstructors(); ConstructorInfo[] array = constructors; for (int i = 0; i < array.Length; i++) { ConstructorInfo constructorInfo = array[i]; bool flag = objectTranslator.metaFunctions.matchParameters(luaState, constructorInfo, ref methodCache); if (flag) { try { objectTranslator.push(luaState, constructorInfo.Invoke(methodCache.args)); } catch (TargetInvocationException e) { objectTranslator.metaFunctions.ThrowError(luaState, e); LuaDLL.lua_pushnil(luaState); } catch { LuaDLL.lua_pushnil(luaState); } return(1); } } string text = (constructors.Length != 0) ? constructors[0].get_Name() : "unknown"; LuaDLL.luaL_error(luaState, string.Format("{0} does not contain constructor({1}) argument match", reflect.get_UnderlyingSystemType(), text)); LuaDLL.lua_pushnil(luaState); return(1); }
public static int callConstructor(IntPtr luaState) { ObjectTranslator translator = ObjectTranslator.FromState(luaState); MethodCache methodCache = new MethodCache(); object obj2 = translator.getRawNetObject(luaState, 1); if ((obj2 == null) || !(obj2 is IReflect)) { LuaDLL.luaL_error(luaState, "trying to call constructor on an invalid type reference"); LuaDLL.lua_pushnil(luaState); return(1); } IReflect reflect = (IReflect)obj2; LuaDLL.lua_remove(luaState, 1); ConstructorInfo[] constructors = reflect.UnderlyingSystemType.GetConstructors(); foreach (ConstructorInfo info in constructors) { if (translator.metaFunctions.matchParameters(luaState, info, ref methodCache)) { try { translator.push(luaState, info.Invoke(methodCache.args)); } catch (TargetInvocationException exception) { translator.metaFunctions.ThrowError(luaState, exception); LuaDLL.lua_pushnil(luaState); } catch { LuaDLL.lua_pushnil(luaState); } return(1); } } string str = (constructors.Length != 0) ? constructors[0].Name : "unknown"; LuaDLL.luaL_error(luaState, string.Format("{0} does not contain constructor({1}) argument match", reflect.UnderlyingSystemType, str)); LuaDLL.lua_pushnil(luaState); return(1); }
public LuaMethodWrapper(ObjectTranslator translator, object target, IReflect targetType, MethodBase method) { this._LastCalledMethod = new MethodCache(); this._Translator = translator; this._Target = target; this._TargetType = targetType; if (targetType != null) { this._ExtractTarget = translator.typeChecker.getExtractor(targetType); } this._Method = method; this._MethodName = method.Name; if (method.IsStatic) { this._BindingType = BindingFlags.Static; } else { this._BindingType = BindingFlags.Instance; } }
internal bool matchParameters(IntPtr luaState, MethodBase method, ref MethodCache methodCache) { return(this.metaFunctions.matchParameters(luaState, method, ref methodCache)); }
internal bool matchParameters(IntPtr luaState, MethodBase method, ref MethodCache methodCache) { bool flag = true; ParameterInfo[] parameters = method.GetParameters(); int num = 1; int num2 = LuaDLL.lua_gettop(luaState); ArrayList arrayList = new ArrayList(); List <int> list = new List <int>(); List <MethodArgs> list2 = new List <MethodArgs>(); ParameterInfo[] array = parameters; for (int i = 0; i < array.Length; i++) { ParameterInfo parameterInfo = array[i]; ExtractValue extractValue; if (!parameterInfo.get_IsIn() && parameterInfo.get_IsOut()) { list.Add(arrayList.Add(null)); } else if (num > num2) { if (!parameterInfo.get_IsOptional()) { flag = false; break; } arrayList.Add(parameterInfo.get_DefaultValue()); } else if (this._IsTypeCorrect(luaState, num, parameterInfo, out extractValue)) { int num3 = arrayList.Add(extractValue(luaState, num)); list2.Add(new MethodArgs { index = num3, extractValue = extractValue }); if (parameterInfo.get_ParameterType().get_IsByRef()) { list.Add(num3); } num++; } else if (this._IsParamsArray(luaState, num, parameterInfo, out extractValue)) { object luaParamValue = extractValue(luaState, num); Type elementType = parameterInfo.get_ParameterType().GetElementType(); Array array2 = this.TableToArray(luaParamValue, elementType); int index = arrayList.Add(array2); list2.Add(new MethodArgs { index = index, extractValue = extractValue, isParamsArray = true, paramsArrayType = elementType }); num++; } else { if (!parameterInfo.get_IsOptional()) { flag = false; break; } arrayList.Add(parameterInfo.get_DefaultValue()); } } if (num != num2 + 1) { flag = false; } if (flag) { methodCache.args = arrayList.ToArray(); methodCache.cachedMethod = method; methodCache.outList = list.ToArray(); methodCache.argTypes = list2.ToArray(); } return(flag); }
internal bool matchParameters(IntPtr luaState, MethodBase method, ref MethodCache methodCache) { bool flag = true; ParameterInfo[] parameters = method.GetParameters(); int currentLuaParam = 1; int num2 = LuaDLL.lua_gettop(luaState); ArrayList list = new ArrayList(); List <int> list2 = new List <int>(); List <MethodArgs> list3 = new List <MethodArgs>(); foreach (ParameterInfo info in parameters) { if (!info.IsIn && info.IsOut) { list2.Add(list.Add(null)); } else { ExtractValue value2; if (currentLuaParam > num2) { if (info.IsOptional) { list.Add(info.DefaultValue); goto Label_01A4; } flag = false; break; } if (this._IsTypeCorrect(luaState, currentLuaParam, info, out value2)) { int item = list.Add(value2(luaState, currentLuaParam)); MethodArgs args = new MethodArgs { index = item, extractValue = value2 }; list3.Add(args); if (info.ParameterType.IsByRef) { list2.Add(item); } currentLuaParam++; } else if (this._IsParamsArray(luaState, currentLuaParam, info, out value2)) { object luaParamValue = value2(luaState, currentLuaParam); Type elementType = info.ParameterType.GetElementType(); Array array = this.TableToArray(luaParamValue, elementType); int num5 = list.Add(array); MethodArgs args2 = new MethodArgs { index = num5, extractValue = value2, isParamsArray = true, paramsArrayType = elementType }; list3.Add(args2); currentLuaParam++; } else if (info.IsOptional) { list.Add(info.DefaultValue); } else { flag = false; break; } Label_01A4 :; } } if (currentLuaParam != (num2 + 1)) { flag = false; } if (flag) { methodCache.args = list.ToArray(); methodCache.cachedMethod = method; methodCache.outList = list2.ToArray(); methodCache.argTypes = list3.ToArray(); } return(flag); }