LuaInterface.ObjectTranslator.matchParameters C# (CSharp) Method

matchParameters() private method

private matchParameters ( IntPtr luaState, MethodBase method, MethodCache &methodCache ) : bool
luaState IntPtr
method MethodBase
methodCache MethodCache
return bool
        internal bool matchParameters(IntPtr luaState,MethodBase method,ref MethodCache methodCache)
        {
            return metaFunctions.matchParameters(luaState,method,ref methodCache);
        }

Usage Example

示例#1
0
        /// <summary>
        /// __call metafunction of type references.
        /// Searches for and calls a constructor for the type.
        /// Returns nil if the constructor is not found or if the arguments are invalid.
        /// Throws an error if the constructor generates an exception.
        /// </summary>
        int classCall(lua.State L)
        {
            using (luanet.entercfunction(L, interpreter))
            {
                var klass            = _checktyperef(L);
                var validConstructor = new MethodCache();
                lua.remove(L, 1);
                var constructors = klass.UnderlyingSystemType.GetConstructors();

                foreach (ConstructorInfo constructor in constructors)
                {
                    if (translator.matchParameters(L, constructor, ref validConstructor))
                    {
                        if (!translator.memberIsAllowed(constructor))
                        {
                            if (constructors.Length == 1)
                            {
                                return(luaL.error(L, "constructor call failed (access denied)"));
                            }
                            continue;
                        }
                        object result;
                        try { result = constructor.Invoke(validConstructor.args); }
                        catch (TargetInvocationException ex) { return(translator.throwError(L, luaclr.verifyex(ex.InnerException))); }
                        catch (Exception ex) { return(luaL.error(L, "constructor call failed (" + ex.Message + ")")); }
                        translator.push(L, result);
                        return(1);
                    }
                }
                return(luaL.error(L, "constructor arguments do not match (" + klass.UnderlyingSystemType + ")"));
            }
        }
All Usage Examples Of LuaInterface.ObjectTranslator::matchParameters