Ejemplo n.º 1
0
    public static Delegate RemoveDelegate(Delegate obj, Delegate dg)
    {
        LuaDelegate remove = dg.Target as LuaDelegate;

        if (remove == null)
        {
            obj = Delegate.Remove(obj, dg);
            return(obj);
        }

        GLuaState state = remove.func.GetGLuaState();

        Delegate[] ds = obj.GetInvocationList();

        for (int i = 0; i < ds.Length; i++)
        {
            LuaDelegate ld = ds[i].Target as LuaDelegate;

            if (ld != null && ld == remove)
            {
                obj = Delegate.Remove(obj, ds[i]);
                state.DelayDispose(ld.func);
                state.DelayDispose(ld.self);
                break;
            }
        }

        return(obj);
    }
Ejemplo n.º 2
0
    static int op_Subtraction(IntPtr L)
    {
        try
        {
            ToLua.CheckArgsCount(L, 2);
            Delegate arg0 = (Delegate)ToLua.CheckObject(L, 1, typeof(Delegate));
            LuaTypes type = LuaDLL.lua_type(L, 2);

            if (type == LuaTypes.LUA_TFUNCTION)
            {
                GLuaState   state = GLuaState.Get(L);
                LuaFunction func  = ToLua.ToLuaFunction(L, 2);
                Delegate[]  ds    = arg0.GetInvocationList();

                for (int i = 0; i < ds.Length; i++)
                {
                    LuaDelegate ld = ds[i].Target as LuaDelegate;

                    if (ld != null && ld.func == func && ld.self == null)
                    {
                        arg0 = Delegate.Remove(arg0, ds[i]);
                        state.DelayDispose(ld.func);
                        break;
                    }
                }

                func.Dispose();
                ToLua.Push(L, arg0);
                return(1);
            }
            else
            {
                Delegate arg1 = (Delegate)ToLua.CheckObject(L, 2, typeof(Delegate));
                arg0 = DelegateFactory.RemoveDelegate(arg0, arg1);
                ToLua.Push(L, arg0);
                return(1);
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
Ejemplo n.º 3
0
    public static Delegate RemoveDelegate(Delegate obj, LuaFunction func)
    {
        GLuaState state = func.GetGLuaState();

        Delegate[] ds = obj.GetInvocationList();

        for (int i = 0; i < ds.Length; i++)
        {
            LuaDelegate ld = ds[i].Target as LuaDelegate;

            if (ld != null && ld.func == func)
            {
                obj = Delegate.Remove(obj, ds[i]);
                state.DelayDispose(ld.func);
                break;
            }
        }

        return(obj);
    }