コード例 #1
0
ファイル: DelegateFactory.cs プロジェクト: sethdu0525/Nova
    public static Delegate CreateDelegate(Type t, LuaFunction func = null)
    {
        if (!dict.TryGetValue(t, out var create))
        {
            throw new LuaException($"Delegate {LuaMisc.GetTypeName(t)} not register");
        }

        if (func == null)
        {
            return(create(null, null, false));
        }

        LuaState    state  = func.GetLuaState();
        LuaDelegate target = state.GetLuaDelegate(func);

        if (target != null)
        {
            return(Delegate.CreateDelegate(t, target, target.method));
        }
        else
        {
            Delegate d = create(func, null, false);
            target = d.Target as LuaDelegate;
            state.AddLuaDelegate(target, func);
            return(d);
        }
    }
コード例 #2
0
    public static Delegate CreateDelegate(Type t, LuaFunction func, LuaTable self)
    {
        DelegateValue Create = null;

        if (!dict.TryGetValue(t, out Create))
        {
            throw new LuaException(string.Format("Delegate {0} not register", LuaMisc.GetTypeName(t)));
        }

        if (func != null)
        {
            LuaState    state  = func.GetLuaState();
            LuaDelegate target = state.GetLuaDelegate(func, self);

            if (target != null)
            {
                return(Delegate.CreateDelegate(t, target, target.method));
            }
            else
            {
                Delegate d = Create(func, self, true);
                target = d.Target as LuaDelegate;
                state.AddLuaDelegate(target, func, self);
                return(d);
            }
        }

        return(Create(func, self, true));
    }
コード例 #3
0
 public static Delegate CreateDelegate(Type t, LuaFunction func = null)
 {
     DelegateFactory.DelegateValue delegateValue = null;
     if (!DelegateFactory.dict.TryGetValue(t, ref delegateValue))
     {
         throw new LuaException(string.Format("Delegate {0} not register", LuaMisc.GetTypeName(t)), null, 1);
     }
     return(delegateValue(func));
 }
コード例 #4
0
        static public string GetTypeName()
        {
            if (typeName == string.Empty)
            {
                typeName = LuaMisc.GetTypeName(type);
            }

            return(typeName);
        }
コード例 #5
0
    public static Delegate CreateDelegate(Type t, LuaFunction func, LuaTable self)
    {
        DelegateValue create = null;

        if (!dict.TryGetValue(t, out create))
        {
            throw new LuaException(string.Format("Delegate {0} not register", LuaMisc.GetTypeName(t)));
        }

        return(create(func, self, true));
    }
コード例 #6
0
ファイル: TypeUtils.cs プロジェクト: mybios/CSharpLuaForUnity
 public static string GetBaseTypeStr(Type t)
 {
     if (t.IsGenericType)
     {
         return(LuaMisc.GetTypeName(t));
     }
     else
     {
         return(t.FullName.Replace("+", "."));
     }
 }
コード例 #7
0
    public static Delegate CreateDelegate(IntPtr L, Type t, LuaFunction func = null)
    {
        DelegateValue create = null;

        if (!dict.TryGetValue(t, out create))
        {
            LuaDLL.luaL_error(L, string.Format("Delegate {0} not register", LuaMisc.GetTypeName(t)));
            return(null);
        }

        return(create(func));
    }
コード例 #8
0
 public static string GetTypeStr(this Type type)
 {
     if (typeof(ICollection).IsAssignableFrom(type))
     {
         return("table");
     }
     if (type.IsGenericType)
     {
         var typeName = LuaMisc.GetTypeName(type);
         int pos      = typeName.IndexOf("<", StringComparison.Ordinal);
         if (pos > 0)
         {
             return(typeName.Substring(0, pos));
         }
     }
     return(LuaMisc.GetTypeName(type));
 }
コード例 #9
0
    public static Delegate CreateDelegate(Type t, LuaFunction func = null)
    {
        DelegateValue create = null;

        if (!dict.TryGetValue(t, out create))
        {
            throw new LuaException(string.Format("Delegate {0} not register", LuaMisc.GetTypeName(t)));
        }

        if (!dict2.ContainsKey(func))
        {
            Delegate del = create(func);
            dict2[func] = del;
            dict3[del]  = func;
        }
        return(dict2[func]);
    }
コード例 #10
0
ファイル: ToLuaMenu.cs プロジェクト: lingyun5905/Record
        public BindType(Type t)
        {
            if (typeof(System.MulticastDelegate).IsAssignableFrom(t))
            {
                string ex = string.Format("\nDon't export Delegate {0} as a class, register it in customDelegateList",
                                          LuaMisc.GetTypeName(t));
                throw new NotSupportedException(ex);
            }

            if (IsObsolete(t))
            {
                throw new Exception(string.Format("\n{0} is obsolete, don't export it!", LuaMisc.GetTypeName(t)));
            }

            type      = t;
            nameSpace = ToLuaExport.GetNameSpace(t, out libName);
            name      = ToLuaExport.CombineTypeStr(nameSpace, libName);
            libName   = ToLuaExport.ConvertToLibSign(libName);

            if (name == "object")
            {
                wrapName = "System_Object";
                name     = "System.Object";
            }
            else if (name == "string")
            {
                wrapName = "System_String";
                name     = "System.String";
            }
            else
            {
                wrapName = name.Replace('.', '_');
                wrapName = ToLuaExport.ConvertToLibSign(wrapName);
            }

            int index = CustomSettings.staticClassTypes.IndexOf(type);

            if (index >= 0 || (type.IsAbstract && type.IsSealed))
            {
                IsStatic = true;
            }

            baseType = LuaMisc.GetExportBaseType(type);
        }
コード例 #11
0
ファイル: Method.cs プロジェクト: mybios/CSharpLuaForUnity
    static void GenFunctions()
    {
        HashSet <string> set = new HashSet <string>();

        for (int i = 0; i < methods.Count; i++)
        {
            _MethodBase m = methods[i];

            if (IsGenericMethod(m.Method))
            {
                Debugger.Log("Generic Method {0}.{1} cannot be export to lua", LuaMisc.GetTypeName(type), m.GetTotalName());
                continue;
            }

            string name = GetMethodName(m.Method);

            if (nameCounter[name] > 1)
            {
                if (!set.Contains(name))
                {
                    _MethodBase mi = GenOverrideFunc(name);

                    if (mi == null)
                    {
                        set.Add(name);
                        continue;
                    }
                    else
                    {
                        m = mi;     //非重载函数,或者折叠之后只有一个函数
                    }
                }
                else
                {
                    continue;
                }
            }

            set.Add(name);
            GenFunction(m);
        }
    }
コード例 #12
0
ファイル: TypeUtils.cs プロジェクト: mybios/CSharpLuaForUnity
    //获取类型名字
    public static string GetTypeStr(Type t)
    {
        if (t.IsByRef)
        {
            t = t.GetElementType();
            return(GetTypeStr(t));
        }
        else if (t.IsArray)
        {
            string str = GetTypeStr(t.GetElementType());
            str += LuaMisc.GetArrayRank(t);
            return(str);
        }
        else if (t == extendType)
        {
            return(GetTypeStr(type));
        }
        else if (IsIEnumerator(t))
        {
            return(LuaMisc.GetTypeName(typeof(IEnumerator)));
        }

        return(LuaMisc.GetTypeName(t));
    }
コード例 #13
0
    public static Delegate CreateDelegate(Type t, LuaFunction func, LuaTable self)
    {
        DelegateFactory.DelegateValue delegateValue = null;
        if (!DelegateFactory.dict.TryGetValue(t, out delegateValue))
        {
            throw new LuaException(string.Format("Delegate {0} not register", LuaMisc.GetTypeName(t)), null, 1);
        }
        if (!(func != null))
        {
            return(delegateValue(func, self, true));
        }
        LuaState    luaState    = func.GetLuaState();
        LuaDelegate luaDelegate = luaState.GetLuaDelegate(func, self);

        if (luaDelegate != null)
        {
            return(Delegate.CreateDelegate(t, luaDelegate, luaDelegate.method));
        }
        Delegate @delegate = delegateValue(func, self, true);

        luaDelegate = (@delegate.Target as LuaDelegate);
        luaState.AddLuaDelegate(luaDelegate, func, self);
        return(@delegate);
    }
コード例 #14
0
    private static int Sort(IntPtr L)
    {
        int result;

        try
        {
            int    num  = LuaDLL.lua_gettop(L);
            Type   type = null;
            object obj  = ToLua.CheckGenericObject(L, 1, typeof(List <>), out type);
            if (num == 1)
            {
                LuaMethodCache.CallMethod("Sort", obj, new object[0]);
                result = 0;
            }
            else if (num == 2 && TypeChecker.CheckTypes(L, 2, typeof(Comparison <>).MakeGenericType(new Type[]
            {
                type
            })))
            {
                Delegate @delegate = (Delegate)ToLua.ToObject(L, 2);
                LuaMethodCache.CallMethod("Sort", obj, new object[]
                {
                    @delegate
                });
                result = 0;
            }
            else if (num == 2 && TypeChecker.CheckTypes(L, 2, typeof(IComparer <>).MakeGenericType(new Type[]
            {
                type
            })))
            {
                object obj2 = ToLua.ToObject(L, 2);
                LuaMethodCache.CallMethod("Sort", obj, new object[]
                {
                    obj2
                });
                result = 0;
            }
            else if (num == 4 && TypeChecker.CheckTypes(L, 2, typeof(int), typeof(int), typeof(IComparer <>).MakeGenericType(new Type[]
            {
                type
            })))
            {
                int    num2 = (int)LuaDLL.lua_tonumber(L, 2);
                int    num3 = (int)LuaDLL.lua_tonumber(L, 3);
                object obj3 = ToLua.ToObject(L, 4);
                LuaMethodCache.CallMethod("Sort", obj, new object[]
                {
                    num2,
                    num3,
                    obj3
                });
                result = 0;
            }
            else
            {
                result = LuaDLL.luaL_throw(L, string.Format("invalid arguments to method: List<{0}>.LastIndexOf", LuaMisc.GetTypeName(type)));
            }
        }
        catch (Exception e)
        {
            result = LuaDLL.toluaL_exception(L, e, null);
        }
        return(result);
    }
コード例 #15
0
    static int Sort(IntPtr L)
    {
        try
        {
            int    count   = LuaDLL.lua_gettop(L);
            Type   argType = null;
            object obj     = ToLua.CheckGenericObject(L, 1, typeof(List <>), out argType);

            if (count == 1)
            {
                LuaMethodCache.CallMethod("Sort", obj);
                return(0);
            }
            else if (count == 2 && TypeChecker.CheckTypes(L, 2, typeof(System.Comparison <>).MakeGenericType(argType)))
            {
                Delegate arg0 = (Delegate)ToLua.ToObject(L, 2);
                LuaMethodCache.CallMethod("Sort", obj, arg0);
                return(0);
            }
            else if (count == 2 && TypeChecker.CheckTypes(L, 2, typeof(IComparer <>).MakeGenericType(argType)))
            {
                object arg0 = ToLua.ToObject(L, 2);
                LuaMethodCache.CallMethod("Sort", obj, arg0);
                return(0);
            }
            else if (count == 4)
            {
                int    arg0 = (int)LuaDLL.luaL_checknumber(L, 2);
                int    arg1 = (int)LuaDLL.luaL_checknumber(L, 3);
                object arg2 = ToLua.CheckObject(L, 4, typeof(IComparer <>).MakeGenericType(argType));
                LuaMethodCache.CallMethod("Sort", obj, arg0, arg1, arg2);
                return(0);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, string.Format("invalid arguments to method: List<{0}>.LastIndexOf", LuaMisc.GetTypeName(argType))));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
コード例 #16
0
    static int Reverse(IntPtr L)
    {
        try
        {
            int    count   = LuaDLL.lua_gettop(L);
            Type   argType = null;
            object obj     = ToLua.CheckGenericObject(L, 1, typeof(List <>), out argType);

            if (count == 1)
            {
                LuaMethodCache.CallMethod("Reverse", obj);
                return(0);
            }
            else if (count == 3)
            {
                int arg0 = (int)LuaDLL.luaL_checknumber(L, 2);
                int arg1 = (int)LuaDLL.luaL_checknumber(L, 3);
                LuaMethodCache.CallMethod("Reverse", obj, arg0, arg1);
                return(0);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, string.Format("invalid arguments to method: List<{0}>.LastIndexOf", LuaMisc.GetTypeName(argType))));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
コード例 #17
0
    static int IndexOf(IntPtr L)
    {
        try
        {
            int    count   = LuaDLL.lua_gettop(L);
            Type   argType = null;
            object obj     = ToLua.CheckGenericObject(L, 1, typeof(List <>), out argType);

            if (count == 2)
            {
                object arg0 = ToLua.CheckVarObject(L, 2, argType);
                int    o    = (int)LuaMethodCache.CallMethod("IndexOf", obj, arg0);
                LuaDLL.lua_pushinteger(L, o);
                return(1);
            }
            else if (count == 3)
            {
                object arg0 = ToLua.CheckVarObject(L, 2, argType);
                int    arg1 = (int)LuaDLL.luaL_checknumber(L, 3);
                int    o    = (int)LuaMethodCache.CallMethod("IndexOf", obj, arg0, arg1);
                LuaDLL.lua_pushinteger(L, o);
                return(1);
            }
            else if (count == 4)
            {
                object arg0 = ToLua.CheckVarObject(L, 2, argType);
                int    arg1 = (int)LuaDLL.luaL_checknumber(L, 3);
                int    arg2 = (int)LuaDLL.luaL_checknumber(L, 4);
                int    o    = (int)LuaMethodCache.CallMethod("IndexOf", obj, arg0, arg1, arg2);
                LuaDLL.lua_pushinteger(L, o);
                return(1);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, string.Format("invalid arguments to method: List<{0}>.IndexOf", LuaMisc.GetTypeName(argType))));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
コード例 #18
0
    static int FindLastIndex(IntPtr L)
    {
        try
        {
            int    count   = LuaDLL.lua_gettop(L);
            Type   argType = null;
            object obj     = ToLua.CheckGenericObject(L, 1, typeof(List <>), out argType);

            if (count == 2)
            {
                Delegate arg0 = (Delegate)ToLua.CheckObject(L, 2, typeof(System.Predicate <>).MakeGenericType(argType));
                int      o    = (int)LuaMethodCache.CallMethod("FindLastIndex", obj, arg0);
                LuaDLL.lua_pushinteger(L, o);
                return(1);
            }
            else if (count == 3)
            {
                int      arg0 = (int)LuaDLL.luaL_checknumber(L, 2);
                Delegate arg1 = (Delegate)ToLua.CheckObject(L, 3, typeof(System.Predicate <>).MakeGenericType(argType));
                int      o    = (int)LuaMethodCache.CallMethod("FindLastIndex", obj, arg0, arg1);
                LuaDLL.lua_pushinteger(L, o);
                return(1);
            }
            else if (count == 4)
            {
                int      arg0 = (int)LuaDLL.luaL_checknumber(L, 2);
                int      arg1 = (int)LuaDLL.luaL_checknumber(L, 3);
                Delegate arg2 = (Delegate)ToLua.CheckObject(L, 4, typeof(System.Predicate <>).MakeGenericType(argType));
                int      o    = (int)LuaMethodCache.CallMethod("FindLastIndex", obj, arg0, arg1, arg2);
                LuaDLL.lua_pushinteger(L, o);
                return(1);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, string.Format("invalid arguments to method: List<{0}>.FindLastIndex", LuaMisc.GetTypeName(argType))));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
コード例 #19
0
    static int CopyTo(IntPtr L)
    {
        try
        {
            int    count   = LuaDLL.lua_gettop(L);
            Type   argType = null;
            object obj     = ToLua.CheckGenericObject(L, 1, typeof(List <>), out argType);

            if (count == 2)
            {
                object arg0 = ToLua.CheckObject(L, 2, argType.MakeArrayType());
                LuaMethodCache.CallMethod("CopyTo", obj, arg0);
                return(0);
            }
            else if (count == 3)
            {
                object arg0 = ToLua.CheckObject(L, 2, argType.MakeArrayType());
                int    arg1 = (int)LuaDLL.luaL_checknumber(L, 3);
                LuaMethodCache.CallMethod("CopyTo", obj, arg0, arg1);
                return(0);
            }
            else if (count == 5)
            {
                int    arg0 = (int)LuaDLL.luaL_checknumber(L, 2);
                object arg1 = ToLua.CheckObject(L, 3, argType.MakeArrayType());
                int    arg2 = (int)LuaDLL.luaL_checknumber(L, 4);
                int    arg3 = (int)LuaDLL.luaL_checknumber(L, 5);
                LuaMethodCache.CallMethod("CopyTo", obj, arg0, arg1, arg2, arg3);
                return(0);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, string.Format("invalid arguments to method: List<{0}>.CopyTo", LuaMisc.GetTypeName(argType))));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
コード例 #20
0
    static int BinarySearch(IntPtr L)
    {
        try
        {
            int    count   = LuaDLL.lua_gettop(L);
            Type   argType = null;
            object obj     = ToLua.CheckGenericObject(L, 1, TypeOfList, out argType);

            if (count == 2)
            {
                object arg0 = ToLua.CheckVarObject(L, 2, argType);
                int    o    = (int)LuaMethodCache.CallMethod("BinarySearch", obj, arg0);
                LuaDLL.lua_pushinteger(L, o);
                return(1);
            }
            else if (count == 3)
            {
                object arg0 = ToLua.CheckVarObject(L, 2, argType);
                object arg1 = ToLua.CheckObject(L, 3, typeof(IComparer <>).MakeGenericType(argType));
                int    o    = (int)LuaMethodCache.CallMethod("BinarySearch", obj, arg0, arg1);
                LuaDLL.lua_pushinteger(L, o);
                return(1);
            }
            else if (count == 5)
            {
                int    arg0 = (int)LuaDLL.luaL_checknumber(L, 2);
                int    arg1 = (int)LuaDLL.luaL_checknumber(L, 3);
                object arg2 = ToLua.CheckVarObject(L, 4, argType);
                object arg3 = ToLua.CheckObject(L, 5, typeof(IComparer <>).MakeGenericType(argType));
                int    o    = (int)LuaMethodCache.CallMethod("BinarySearch", obj, arg0, arg1, arg2, arg3);
                LuaDLL.lua_pushinteger(L, o);
                return(1);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, string.Format("invalid arguments to method: List<{0}>.BinarySearch", LuaMisc.GetTypeName(argType))));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
コード例 #21
0
ファイル: ToLuaMenu.cs プロジェクト: 737871854/ToLua_Study
        public BindType(Type t)
        {
            if (typeof(System.MulticastDelegate).IsAssignableFrom(t))
            {
                throw new NotSupportedException(string.Format("\nDon't export Delegate {0} as a class, register it in customDelegateList", LuaMisc.GetTypeName(t)));
            }

            type      = t;
            nameSpace = ToLuaExport.GetNameSpace(t, out libName);
            name      = ToLuaExport.CombineTypeStr(nameSpace, libName);
            libName   = ToLuaExport.ConvertToLibSign(libName);

            if (name == "object")
            {
                wrapName = "System_Object";
                name     = "System.Object";
            }
            else if (name == "string")
            {
                wrapName = "System_String";
                name     = "System.String";
            }
            else
            {
                wrapName = name.Replace('.', '_');
                wrapName = ToLuaExport.ConvertToLibSign(wrapName);
            }

            if (type.BaseType != null && type.BaseType != typeof(ValueType))
            {
                baseType = type.BaseType;
            }

            int index = CustomSettings.staticClassTypes.IndexOf(type);

            if (index >= 0 || (type.GetConstructor(Type.EmptyTypes) == null && type.IsAbstract && type.IsSealed))
            {
                IsStatic = true;
                baseType = baseType == typeof(object) ? null : baseType;
            }
        }
コード例 #22
0
    private static int CopyTo(IntPtr L)
    {
        int result;

        try
        {
            int    num  = LuaDLL.lua_gettop(L);
            Type   type = null;
            object obj  = ToLua.CheckGenericObject(L, 1, typeof(List <>), out type);
            if (num == 2 && TypeChecker.CheckTypes(L, 2, type.MakeArrayType()))
            {
                object obj2 = ToLua.ToObject(L, 2);
                LuaMethodCache.CallMethod("CopyTo", obj, new object[]
                {
                    obj2
                });
                result = 0;
            }
            else if (num == 3 && TypeChecker.CheckTypes(L, 2, type.MakeArrayType(), typeof(int)))
            {
                object obj3 = ToLua.ToObject(L, 2);
                int    num2 = (int)LuaDLL.lua_tonumber(L, 3);
                LuaMethodCache.CallMethod("CopyTo", obj, new object[]
                {
                    obj3,
                    num2
                });
                result = 0;
            }
            else if (num == 5 && TypeChecker.CheckTypes(L, 2, typeof(int), type.MakeArrayType(), typeof(int), typeof(int)))
            {
                int    num3 = (int)LuaDLL.lua_tonumber(L, 2);
                object obj4 = ToLua.ToObject(L, 3);
                int    num4 = (int)LuaDLL.lua_tonumber(L, 4);
                int    num5 = (int)LuaDLL.lua_tonumber(L, 5);
                LuaMethodCache.CallMethod("CopyTo", obj, new object[]
                {
                    num3,
                    obj4,
                    num4,
                    num5
                });
                result = 0;
            }
            else
            {
                result = LuaDLL.luaL_throw(L, string.Format("invalid arguments to method: List<{0}>.CopyTo", LuaMisc.GetTypeName(type)));
            }
        }
        catch (Exception e)
        {
            result = LuaDLL.toluaL_exception(L, e, null);
        }
        return(result);
    }
コード例 #23
0
ファイル: ToLuaMenu.cs プロジェクト: Yeyunrong/U3d
        public BindType(Type t)
        {
            //if (CustomSettings.staticClassTypes == null)
            //{
            //    Debug.LogError("\nCustomSettings.staticClassTypes is null ! ");
            //    return;
            //}

            if (t == null)
            {
                throw new NotSupportedException("\nBindType Type is null ! ");
            }

            if (typeof(System.MulticastDelegate).IsAssignableFrom(t))
            {
                throw new NotSupportedException(string.Format("\nDon't export Delegate {0} as a class, register it in customDelegateList", LuaMisc.GetTypeName(t)));
            }

            //if (IsObsolete(t))
            //{
            //    throw new Exception(string.Format("\n{0} is obsolete, don't export it!", LuaMisc.GetTypeName(t)));
            //}

            type      = t;
            nameSpace = ToLuaExport.GetNameSpace(t, out libName);
            name      = ToLuaExport.CombineTypeStr(nameSpace, libName);
            libName   = ToLuaExport.ConvertToLibSign(libName);

            if (name == "object")
            {
                wrapName = "System_Object";
                name     = "System.Object";
            }
            else if (name == "string")
            {
                wrapName = "System_String";
                name     = "System.String";
            }
            else
            {
                wrapName = name.Replace('.', '_');
                wrapName = ToLuaExport.ConvertToLibSign(wrapName);
            }

            if ((type.IsAbstract && type.IsSealed))
            {
                IsStatic = true;
            }

            baseType = LuaMisc.GetExportBaseType(type);
        }
コード例 #24
0
    private static int Reverse(IntPtr L)
    {
        int result;

        try
        {
            int    num = LuaDLL.lua_gettop(L);
            Type   t   = null;
            object obj = ToLua.CheckGenericObject(L, 1, typeof(List <>), out t);
            if (num == 1)
            {
                LuaMethodCache.CallMethod("Reverse", obj, new object[0]);
                result = 0;
            }
            else if (num == 3 && TypeChecker.CheckTypes(L, 2, typeof(int), typeof(int)))
            {
                int num2 = (int)LuaDLL.lua_tonumber(L, 2);
                int num3 = (int)LuaDLL.lua_tonumber(L, 3);
                LuaMethodCache.CallMethod("Reverse", obj, new object[]
                {
                    num2,
                    num3
                });
                result = 0;
            }
            else
            {
                result = LuaDLL.luaL_throw(L, string.Format("invalid arguments to method: List<{0}>.LastIndexOf", LuaMisc.GetTypeName(t)));
            }
        }
        catch (Exception e)
        {
            result = LuaDLL.toluaL_exception(L, e, null);
        }
        return(result);
    }
コード例 #25
0
ファイル: TypeUtils.cs プロジェクト: mybios/CSharpLuaForUnity
    public static bool IsMemberFilter(Type t)
    {
        string name = LuaMisc.GetTypeName(t);

        return(memberInfoFilter.Contains(t) || memberFilter.Find((p) => { return name.Contains(p); }) != null);
    }
コード例 #26
0
    private static int FindLastIndex(IntPtr L)
    {
        int result;

        try
        {
            int    num  = LuaDLL.lua_gettop(L);
            Type   type = null;
            object obj  = ToLua.CheckGenericObject(L, 1, typeof(List <>), out type);
            if (num == 2 && TypeChecker.CheckTypes(L, 2, typeof(Predicate <>).MakeGenericType(new Type[]
            {
                type
            })))
            {
                Delegate @delegate = (Delegate)ToLua.ToObject(L, 2);
                int      n         = (int)LuaMethodCache.CallMethod("FindLastIndex", obj, new object[]
                {
                    @delegate
                });
                LuaDLL.lua_pushinteger(L, n);
                result = 1;
            }
            else if (num == 3 && TypeChecker.CheckTypes(L, 2, typeof(int), typeof(Predicate <>).MakeGenericType(new Type[]
            {
                type
            })))
            {
                int      num2      = (int)LuaDLL.lua_tonumber(L, 2);
                Delegate delegate2 = (Delegate)ToLua.ToObject(L, 3);
                int      n2        = (int)LuaMethodCache.CallMethod("FindLastIndex", obj, new object[]
                {
                    num2,
                    delegate2
                });
                LuaDLL.lua_pushinteger(L, n2);
                result = 1;
            }
            else if (num == 4 && TypeChecker.CheckTypes(L, 2, typeof(int), typeof(int), typeof(Predicate <int>)))
            {
                int      num3      = (int)LuaDLL.lua_tonumber(L, 2);
                int      num4      = (int)LuaDLL.lua_tonumber(L, 3);
                Delegate delegate3 = (Delegate)ToLua.ToObject(L, 4);
                int      n3        = (int)LuaMethodCache.CallMethod("FindLastIndex", obj, new object[]
                {
                    num3,
                    num4,
                    delegate3
                });
                LuaDLL.lua_pushinteger(L, n3);
                result = 1;
            }
            else
            {
                result = LuaDLL.luaL_throw(L, string.Format("invalid arguments to method: List<{0}>.FindLastIndex", LuaMisc.GetTypeName(type)));
            }
        }
        catch (Exception e)
        {
            result = LuaDLL.toluaL_exception(L, e, null);
        }
        return(result);
    }
コード例 #27
0
    static void AutoAddBaseType(BindType bt, bool beDropBaseType)
    {
        Type t = bt.baseType;

        if (t == null)
        {
            return;
        }

        if (CustomSettings.sealedList.Contains(t))
        {
            CustomSettings.sealedList.Remove(t);
            Debugger.LogError("{0} not a sealed class, it is parent of {1}", LuaMisc.GetTypeName(t), bt.name);
        }

        if (t.IsInterface)
        {
            Debugger.LogWarning("{0} has a base type {1} is Interface, use SetBaseType to jump it", bt.name, t.FullName);
            bt.baseType = t.BaseType;
        }
        else if (dropType.IndexOf(t) >= 0)
        {
            Debugger.LogWarning("{0} has a base type {1} is a drop type", bt.name, t.FullName);
            bt.baseType = t.BaseType;
        }
        else if (!beDropBaseType || baseType.IndexOf(t) < 0)
        {
            int index = allTypes.FindIndex((iter) => { return(iter.type == t); });

            if (index < 0)
            {
#if JUMP_NODEFINED_ABSTRACT
                if (t.IsAbstract && !t.IsSealed)
                {
                    Debugger.LogWarning("not defined bindtype for {0}, it is abstract class, jump it, child class is {1}", LuaMisc.GetTypeName(t), bt.name);
                    bt.baseType = t.BaseType;
                }
                else
                {
                    Debugger.LogWarning("not defined bindtype for {0}, autogen it, child class is {1}", LuaMisc.GetTypeName(t), bt.name);
                    bt = new BindType(t);
                    allTypes.Add(bt);
                }
#else
                Debugger.LogWarning("not defined bindtype for {0}, autogen it, child class is {1}", LuaMisc.GetTypeName(t), bt.name);
                bt = new BindType(t);
                allTypes.Add(bt);
#endif
            }
            else
            {
                return;
            }
        }
        else
        {
            return;
        }

        AutoAddBaseType(bt, beDropBaseType);
    }
コード例 #28
0
        public BindType(Type t)
        {
            // 如果是委托及其衍生类,抛出异常
            if (typeof(System.MulticastDelegate).IsAssignableFrom(t))
            {
                throw new NotSupportedException(string.Format("\nDon't export Delegate {0} as a class, register it in customDelegateList", LuaMisc.GetTypeName(t)));
            }

            //if (IsObsolete(t))
            //{
            //    throw new Exception(string.Format("\n{0} is obsolete, don't export it!", LuaMisc.GetTypeName(t)));
            //}

            type = t;
            // 获取 type 的命名空间,并将 libName 更新为从完全限定名到命名空间后一位(也就是带'.'字符)的字符
            nameSpace = ToLuaExport.GetNameSpace(t, out libName);
            // 用"."字符拼接参数 space 与 name 为一个字符串并返回
            name = ToLuaExport.CombineTypeStr(nameSpace, libName);
            // 过滤、替换字符串中指定的字符并返回
            libName = ToLuaExport.ConvertToLibSign(libName);

            // 按规律设置 name 和 wrapName 的值
            if (name == "object")
            {
                wrapName = "System_Object";
                name     = "System.Object";
            }
            else if (name == "string")
            {
                wrapName = "System_String";
                name     = "System.String";
            }
            else
            {
                wrapName = name.Replace('.', '_');
                wrapName = ToLuaExport.ConvertToLibSign(wrapName);
            }

            // 获取 CustomSettings.staticClassTypes(静态类型)中 type 的 index
            int index = CustomSettings.staticClassTypes.IndexOf(type);

            // 如果大等于 0(代表没有这个类型)或 type 是虚类、密封类,设置 IsStatic 为真
            if (index >= 0 || (type.IsAbstract && type.IsSealed))
            {
                IsStatic = true;
            }

            // 获取导出文件的基类
            baseType = LuaMisc.GetExportBaseType(type);
        }
コード例 #29
0
    private static int LastIndexOf(IntPtr L)
    {
        int result;

        try
        {
            int    num  = LuaDLL.lua_gettop(L);
            Type   type = null;
            object obj  = ToLua.CheckGenericObject(L, 1, typeof(List <>), out type);
            if (num == 2 && TypeChecker.CheckTypes(L, 2, type))
            {
                object obj2 = ToLua.ToVarObject(L, 2, type);
                int    n    = (int)LuaMethodCache.CallMethod("LastIndexOf", obj, new object[]
                {
                    obj2
                });
                LuaDLL.lua_pushinteger(L, n);
                result = 1;
            }
            else if (num == 3 && TypeChecker.CheckTypes(L, 2, type, typeof(int)))
            {
                object obj3 = ToLua.ToVarObject(L, 2, type);
                int    num2 = (int)LuaDLL.lua_tonumber(L, 3);
                int    n2   = (int)LuaMethodCache.CallMethod("LastIndexOf", obj, new object[]
                {
                    obj3,
                    num2
                });
                LuaDLL.lua_pushinteger(L, n2);
                result = 1;
            }
            else if (num == 4 && TypeChecker.CheckTypes(L, 2, type, typeof(int), typeof(int)))
            {
                object obj4 = ToLua.ToVarObject(L, 2, type);
                int    num3 = (int)LuaDLL.lua_tonumber(L, 3);
                int    num4 = (int)LuaDLL.lua_tonumber(L, 4);
                int    n3   = (int)LuaMethodCache.CallMethod("LastIndexOf", obj, new object[]
                {
                    obj4,
                    num3,
                    num4
                });
                LuaDLL.lua_pushinteger(L, n3);
                result = 1;
            }
            else
            {
                result = LuaDLL.luaL_throw(L, string.Format("invalid arguments to method: List<{0}>.LastIndexOf", LuaMisc.GetTypeName(type)));
            }
        }
        catch (Exception e)
        {
            result = LuaDLL.toluaL_exception(L, e, null);
        }
        return(result);
    }
コード例 #30
0
ファイル: System_ArrayWrap.cs プロジェクト: castleyoung/tolua
    static int set_Item(IntPtr L)
    {
        try
        {
            Array obj = ToLua.ToObject(L, 1) as Array;

            if (obj == null)
            {
                throw new LuaException("trying to index an invalid object reference");
            }

            int  index = (int)LuaDLL.lua_tointeger(L, 2);
            Type t     = obj.GetType().GetElementType();

            if (t.IsValueType)
            {
                if (t.IsPrimitive)
                {
                    if (SetPrimitiveValue(L, obj, t, index))
                    {
                        return(0);
                    }
                }
                else if (t == typeof(Vector3))
                {
                    Vector3[] array = obj as Vector3[];
                    Vector3   val   = ToLua.ToVector3(L, 3);
                    array[index] = val;
                    return(0);
                }
                else if (t == typeof(Quaternion))
                {
                    Quaternion[] array = obj as Quaternion[];
                    Quaternion   val   = ToLua.ToQuaternion(L, 3);
                    array[index] = val;
                    return(0);
                }
                else if (t == typeof(Vector2))
                {
                    Vector2[] array = obj as Vector2[];
                    Vector2   val   = ToLua.ToVector2(L, 3);
                    array[index] = val;
                    return(0);
                }
                else if (t == typeof(Vector4))
                {
                    Vector4[] array = obj as Vector4[];
                    Vector4   val   = ToLua.ToVector4(L, 3);
                    array[index] = val;
                    return(0);
                }
                else if (t == typeof(Color))
                {
                    Color[] array = obj as Color[];
                    Color   val   = ToLua.ToColor(L, 3);
                    array[index] = val;
                    return(0);
                }
            }

            if (!TypeChecker.CheckType(L, t, 3))
            {
                return(LuaDLL.luaL_typerror(L, 3, LuaMisc.GetTypeName(t)));
            }

            object v = ToLua.CheckVarObject(L, 3, t);
            v = Convert.ChangeType(v, t);
            obj.SetValue(v, index);
            return(0);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }