コード例 #1
0
 private static int GetMethod(IntPtr L)
 {
     try
     {
         int    num   = LuaDLL.lua_gettop(L);
         Type   type  = (Type)ToLua.CheckObject(L, 1, typeof(Type));
         string name  = ToLua.CheckString(L, 2);
         Type[] array = null;
         if (num > 2)
         {
             array = new Type[num - 2];
             for (int i = 3; i <= num; i++)
             {
                 Type type2 = (Type)ToLua.CheckObject(L, i, typeof(Type));
                 if (type2 == null)
                 {
                     LuaDLL.luaL_typerror(L, i, "Type", null);
                 }
                 array[i - 3] = type2;
             }
         }
         MethodInfo method;
         if (array == null)
         {
             method = type.GetMethod(name);
         }
         else
         {
             method = type.GetMethod(name, array);
         }
         LuaReflection.PushLuaMethod(L, method, type, array);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e, null));
     }
     return(1);
 }
コード例 #2
0
        private static int GetTypeMethod(IntPtr L)
        {
            int result;

            try
            {
                int num = LuaDLL.lua_gettop(L);
                if (num == 2 && TypeChecker.CheckTypes(L, 1, typeof(Type), typeof(string)))
                {
                    Type       type   = (Type)ToLua.ToObject(L, 1);
                    string     name   = ToLua.ToString(L, 2);
                    MethodInfo method = type.GetMethod(name);
                    LuaReflection.PushLuaMethod(L, method, type, null);
                    result = 1;
                }
                else if (num == 3 && TypeChecker.CheckTypes(L, 1, typeof(Type), typeof(string), typeof(Type[])))
                {
                    Type       type2   = (Type)ToLua.ToObject(L, 1);
                    string     name2   = ToLua.ToString(L, 2);
                    Type[]     types   = ToLua.CheckObjectArray <Type>(L, 3);
                    MethodInfo method2 = type2.GetMethod(name2, types);
                    LuaReflection.PushLuaMethod(L, method2, type2, types);
                    result = 1;
                }
                else if (num == 3 && TypeChecker.CheckTypes(L, 1, typeof(Type), typeof(string), typeof(uint)))
                {
                    Type         type3       = (Type)ToLua.ToObject(L, 1);
                    string       name3       = ToLua.ToString(L, 2);
                    BindingFlags bindingAttr = (BindingFlags)LuaDLL.lua_tonumber(L, 3);
                    MethodInfo   method3     = type3.GetMethod(name3, bindingAttr);
                    LuaReflection.PushLuaMethod(L, method3, type3, null);
                    result = 1;
                }
                else if (num == 4 && TypeChecker.CheckTypes(L, 1, typeof(Type), typeof(string), typeof(Type[]), typeof(ParameterModifier[])))
                {
                    Type   type4  = (Type)ToLua.ToObject(L, 1);
                    string name4  = ToLua.ToString(L, 2);
                    Type[] types2 = ToLua.CheckObjectArray <Type>(L, 3);
                    ParameterModifier[] modifiers = ToLua.CheckObjectArray <ParameterModifier>(L, 4);
                    MethodInfo          method4   = type4.GetMethod(name4, types2, modifiers);
                    LuaReflection.PushLuaMethod(L, method4, type4, types2);
                    result = 1;
                }
                else if (num == 6 && TypeChecker.CheckTypes(L, 1, typeof(Type), typeof(string), typeof(uint), typeof(Binder), typeof(Type[]), typeof(ParameterModifier[])))
                {
                    Type                type5        = (Type)ToLua.ToObject(L, 1);
                    string              name5        = ToLua.ToString(L, 2);
                    BindingFlags        bindingAttr2 = (BindingFlags)LuaDLL.lua_tonumber(L, 3);
                    Binder              binder       = (Binder)ToLua.ToObject(L, 4);
                    Type[]              types3       = ToLua.CheckObjectArray <Type>(L, 5);
                    ParameterModifier[] modifiers2   = ToLua.CheckObjectArray <ParameterModifier>(L, 6);
                    MethodInfo          method5      = type5.GetMethod(name5, bindingAttr2, binder, types3, modifiers2);
                    LuaReflection.PushLuaMethod(L, method5, type5, types3);
                    result = 1;
                }
                else if (num == 7 && TypeChecker.CheckTypes(L, 1, typeof(Type), typeof(string), typeof(uint), typeof(Binder), typeof(CallingConventions), typeof(Type[]), typeof(ParameterModifier[])))
                {
                    Type                type6          = (Type)ToLua.ToObject(L, 1);
                    string              name6          = ToLua.ToString(L, 2);
                    BindingFlags        bindingAttr3   = (BindingFlags)LuaDLL.lua_tonumber(L, 3);
                    Binder              binder2        = (Binder)ToLua.ToObject(L, 4);
                    CallingConventions  callConvention = (CallingConventions)((int)ToLua.ToObject(L, 5));
                    Type[]              types4         = ToLua.CheckObjectArray <Type>(L, 6);
                    ParameterModifier[] modifiers3     = ToLua.CheckObjectArray <ParameterModifier>(L, 7);
                    MethodInfo          method6        = type6.GetMethod(name6, bindingAttr3, binder2, callConvention, types4, modifiers3);
                    LuaReflection.PushLuaMethod(L, method6, type6, types4);
                    result = 1;
                }
                else
                {
                    result = LuaDLL.luaL_throw(L, "invalid arguments to method: tolua.gettypemethod");
                }
            }
            catch (Exception e)
            {
                result = LuaDLL.toluaL_exception(L, e, null);
            }
            return(result);
        }