Пример #1
0
        public void Call(Type type, Movie target)
        {
            MovieEventHandlerDictionary dict = null;

            switch (type)
            {
            case Type.LOAD: dict = load; break;

            case Type.POSTLOAD: dict = postLoad; break;

            case Type.UNLOAD: dict = unload; break;

            case Type.ENTERFRAME: dict = enterFrame; break;

            case Type.UPDATE: dict = update; break;

            case Type.RENDER: dict = render; break;
            }
            if (dict != null)
            {
                dict = new MovieEventHandlerDictionary(dict);
                foreach (var h in dict)
                {
                    h.Value(target);
                }
            }
        }
Пример #2
0
 public MovieEventHandlers()
 {
     load       = new MovieEventHandlerDictionary();
     postLoad   = new MovieEventHandlerDictionary();
     unload     = new MovieEventHandlerDictionary();
     enterFrame = new MovieEventHandlerDictionary();
     update     = new MovieEventHandlerDictionary();
     render     = new MovieEventHandlerDictionary();
     empty      = true;
 }
Пример #3
0
	public MovieEventHandlers()
	{
		load = new MovieEventHandlerDictionary();
		postLoad = new MovieEventHandlerDictionary();
		unload = new MovieEventHandlerDictionary();
		enterFrame = new MovieEventHandlerDictionary();
		update = new MovieEventHandlerDictionary();
		render = new MovieEventHandlerDictionary();
		empty = true;
	}
Пример #4
0
	public int AttachMovieLua(Movie movie, bool empty)
	{
		if (luaState==null)
			return 0;

		Lua.lua_State l = (Lua.lua_State)luaState;
		int args = Lua.lua_gettop(l);
		string linkageName;
		string attachName;
		int attachDepth = -1;
		bool reorder = false;
		int offset = empty ? 2 : 3;
		MovieEventHandlerDictionary handlers =
				new MovieEventHandlerDictionary() {
			{"load",null},
			{"postLoad",null},
			{"unload",null},
			{"enterFrame",null},
			{"update",null},
			{"render",null}
		};

		Movie child;

		/* 1: LWF_Movie instance */
		/* 2: linkageName:string */
		/* 3: attachName:string */
		/* 4: table {key:string, handler:function} */
		/* 5: attachDepth:number (option) */
		/* 6: reorder:boolean (option) */
		/* or */
		/* 1: LWF_Movie instance */
		/* 2: attachName:string */
		/* 3: table {key:string, handler:function} */
		/* 4: attachDepth:number (option) */
		/* 5: reorder:boolean (option) */
		linkageName = empty ? "_empty" : Lua.lua_tostring(l, 2).ToString();
		attachName = Lua.lua_tostring(l, offset).ToString();
		if (args >= offset + 1) {
			Lua.lua_getglobal(l, "LWF");
			/* -1: LWF */
			if (!Lua.lua_istable(l, -1)) {
				Lua.lua_pop(l, 1);
				/* 0 */
				goto error;
			}
			Lua.lua_getfield(l, -1, "Instances");
			/* -2: LWF */
			/* -1: LWF.Instances */
			Lua.lua_remove(l, -2);
			/* -1: LWF.Instances */
			if (!Lua.lua_istable(l, -1)) {
				Lua.lua_pop(l, 1);
				/* 0 */
				goto error;
			}
			Lua.lua_getfield(l, -1, instanceIdString);
			/* -2: LWF.Instances */
			/* -1: LWF.Instances.<instanceId> */
			Lua.lua_remove(l, -2);
			/* -1: LWF.Instances.<instanceId> */
			if (!Lua.lua_istable(l, -1)) {
				Lua.lua_pop(l, 1);
				/* 0 */
				goto error;
			}
			Lua.lua_getfield(l, -1, "Handlers");
			/* -2: LWF.Instances.<instanceId> */
			/* -1: LWF.Instances.<instanceId>.Handlers */
			Lua.lua_remove(l, -2);
			/* -1: LWF.Instances.<instanceId>.Handlers */
			if (!Lua.lua_istable(l, -1)) {
				Lua.lua_pop(l, 1);
				/* 0 */
				goto error;
			}

			Lua.lua_pushnil(l);
			/* -2: LWF.Instances.<instanceId>.Handlers */
			/* -1: nil */
			while (Lua.lua_next(l, 4) != 0) {
				/* -3: LWF.Instances.<instanceId>.Handlers */
				/* -2: key: eventName string */
				/* -1: value: handler function */
				string key = Lua.lua_tostring(l, -2).ToString();
				if (key != null && Lua.lua_isfunction(l, -1)) {
					int luaHandlerId = GetEventOffset();
					handlers[key] = (Movie a) => {
						if (!a.lwf.PushHandlerLua(luaHandlerId))
							return;

						/* -1: function */
						Lua.lua_State ls = (Lua.lua_State)a.lwf.luaState;
						Luna_LWF_Movie.push(ls, a, false);
						/* -2: function */
						/* -1: Movie or Button */
						if (Lua.lua_pcall(ls, 1, 0, 0)!=0)
							Lua.lua_pop(ls, 1);
						/* 0 */
					};


					Lua.lua_setfield(l, -3, luaHandlerId.ToString());
					/* LWF.Instances.<instanceId>.Handlers.
						<luaHandlerId> = function */
					/* -2: LWF.Instances.<instanceId>.Handlers */
					/* -1: key */
				} else {
					Lua.lua_pop(l, 1);
					/* -2: LWF.Instances.<instanceId>.Handlers */
					/* -1: key: eventName string */
				}
			}
			/* -1: LWF.Instances.<instanceId>.Handlers */
			Lua.lua_pop(l, 1);
			/* 0 */
		}
		if (args >= offset + 2)
			attachDepth = (int)Lua.lua_tonumber(l, offset + 2);
		if (args >= offset + 3)
			reorder = Lua.lua_toboolean(l, offset + 3)!=0;

		child = movie.AttachMovie(
			linkageName,
			attachName,
			attachDepth,
			reorder,
			handlers["load"],
			handlers["postLoad"],
			handlers["unload"],
			handlers["enterFrame"],
			handlers["update"],
			handlers["render"]);
		Luna_LWF_Movie.push(l, child, false);
		/* -1: LWF_Movie child */
		return 1;

	error:
		Lua.lua_pushnil(l);
		/* -1: nil */
		return 1;
	}
Пример #5
0
	public int AddMovieEventHandlerLua()
	{
		if (luaState==null)
			return 0;

		Lua.lua_State l = (Lua.lua_State)luaState;
		string instanceName;
		MovieEventHandlerDictionary handlers = new MovieEventHandlerDictionary(){
			{"load", null},
			{"postLoad", null},
			{"unload", null},
			{"enterFrame", null},
			{"update", null},
			{"render", null}
		};

		int handlerId;

		/* 1: LWF_LWF instance */
		/* 2: instanceName:string */
		/* 3: table {key:string, handler:function} */
		instanceName = Lua.lua_tostring(l, 2).ToString();

		Lua.lua_getglobal(l, "LWF");
		/* -1: LWF */
		if (!Lua.lua_istable(l, -1)) {
			Lua.lua_pop(l, 1);
			/* 0 */
			goto error;
		}
		Lua.lua_getfield(l, -1, "Instances");
		/* -2: LWF */
		/* -1: LWF.Instances */
		Lua.lua_remove(l, -2);
		/* -1: LWF.Instances */
		if (!Lua.lua_istable(l, -1)) {
			Lua.lua_pop(l, 1);
			/* 0 */
			goto error;
		}
		Lua.lua_getfield(l, -1, instanceIdString);
		/* -2: LWF.Instances */
		/* -1: LWF.Instances.<instanceId> */
		Lua.lua_remove(l, -2);
		/* -1: LWF.Instances.<instanceId> */
		if (!Lua.lua_istable(l, -1)) {
			Lua.lua_pop(l, 1);
			/* 0 */
			goto error;
		}
		Lua.lua_getfield(l, -1, "Handlers");
		/* -2: LWF.Instances.<instanceId> */
		/* -1: LWF.Instances.<instanceId>.Handlers */
		Lua.lua_remove(l, -2);
		/* -1: LWF.Instances.<instanceId>.Handlers */
		if (!Lua.lua_istable(l, -1)) {
			Lua.lua_pop(l, 1);
			/* 0 */
			goto error;
		}

		Lua.lua_pushnil(l);
		/* -2: LWF.Instances.<instanceId>.Handlers */
		/* -1: nil */
		while (Lua.lua_next(l, 3)!=0) {
			/* -3: LWF.Instances.<instanceId>.Handlers */
			/* -2: key: eventName string */
			/* -1: value: handler function */
			string key = Lua.lua_tostring(l, -2).ToString();
			if (key != null && Lua.lua_isfunction(l, -1)) {
				int luaHandlerId = GetEventOffset();
				handlers[key] = (Movie a) => {
					if (!a.lwf.PushHandlerLua(luaHandlerId))
						return;

					/* -1: function */
					Lua.lua_State ls = (Lua.lua_State)a.lwf.luaState;
					Luna_LWF_Movie.push(ls, a, false);
					/* -2: function */
					/* -1: Movie or Button */
					if (Lua.lua_pcall(ls, 1, 0, 0)!=0)
						Lua.lua_pop(ls, 1);
					/* 0 */
				};
				Lua.lua_setfield(l, -3, luaHandlerId.ToString());
				/* LWF.Instances.<instanceId>.Handlers.<luaHandlerId> = function */
				/* -2: LWF.Instances.<instanceId>.Handlers */
				/* -1: key */
			} else {
				Lua.lua_pop(l, 1);
				/* -2: LWF.Instances.<instanceId>.Handlers */
				/* -1: key: eventName string */
			}
		}
		/* -1: LWF.Instances.<instanceId>.Handlers */
		Lua.lua_pop(l, 1);
		/* 0 */

		handlerId = AddMovieEventHandler(instanceName,
			handlers["load"], handlers["postLoad"],
			handlers["unload"], handlers["enterFrame"],
			handlers["update"], handlers["render"]);
		Lua.lua_pushnumber(l, handlerId);
		/* handlerId */
		return 1;

	error:
		Lua.lua_pushnumber(l, -1);
		/* -1: -1 */
		return 1;
	}
Пример #6
0
        public int AddMovieEventHandlerLua()
        {
            if (luaState == null)
            {
                return(0);
            }

            Lua.lua_State l = (Lua.lua_State)luaState;
            string        instanceName;
            MovieEventHandlerDictionary handlers = new MovieEventHandlerDictionary()
            {
                { "load", null },
                { "postLoad", null },
                { "unload", null },
                { "enterFrame", null },
                { "update", null },
                { "render", null }
            };

            int handlerId;

            /* 1: LWF_LWF instance */
            /* 2: instanceName:string */
            /* 3: table {key:string, handler:function} */
            instanceName = Lua.lua_tostring(l, 2).ToString();

            Lua.lua_getglobal(l, "LWF");
            /* -1: LWF */
            if (!Lua.lua_istable(l, -1))
            {
                Lua.lua_pop(l, 1);
                /* 0 */
                goto error;
            }
            Lua.lua_getfield(l, -1, "Instances");
            /* -2: LWF */
            /* -1: LWF.Instances */
            Lua.lua_remove(l, -2);
            /* -1: LWF.Instances */
            if (!Lua.lua_istable(l, -1))
            {
                Lua.lua_pop(l, 1);
                /* 0 */
                goto error;
            }
            Lua.lua_getfield(l, -1, instanceIdString);
            /* -2: LWF.Instances */
            /* -1: LWF.Instances.<instanceId> */
            Lua.lua_remove(l, -2);
            /* -1: LWF.Instances.<instanceId> */
            if (!Lua.lua_istable(l, -1))
            {
                Lua.lua_pop(l, 1);
                /* 0 */
                goto error;
            }
            Lua.lua_getfield(l, -1, "Handlers");
            /* -2: LWF.Instances.<instanceId> */
            /* -1: LWF.Instances.<instanceId>.Handlers */
            Lua.lua_remove(l, -2);
            /* -1: LWF.Instances.<instanceId>.Handlers */
            if (!Lua.lua_istable(l, -1))
            {
                Lua.lua_pop(l, 1);
                /* 0 */
                goto error;
            }

            Lua.lua_pushnil(l);
            /* -2: LWF.Instances.<instanceId>.Handlers */
            /* -1: nil */
            while (Lua.lua_next(l, 3) != 0)
            {
                /* -3: LWF.Instances.<instanceId>.Handlers */
                /* -2: key: eventName string */
                /* -1: value: handler function */
                string key = Lua.lua_tostring(l, -2).ToString();
                if (key != null && Lua.lua_isfunction(l, -1))
                {
                    int luaHandlerId = GetEventOffset();
                    handlers[key] = (Movie a) => {
                        if (!a.lwf.PushHandlerLua(luaHandlerId))
                        {
                            return;
                        }

                        /* -1: function */
                        Lua.lua_State ls = (Lua.lua_State)a.lwf.luaState;
                        Luna_LWF_Movie.push(ls, a, false);
                        /* -2: function */
                        /* -1: Movie or Button */
                        if (Lua.lua_pcall(ls, 1, 0, 0) != 0)
                        {
                            Lua.lua_pop(ls, 1);
                        }
                        /* 0 */
                    };
                    Lua.lua_setfield(l, -3, luaHandlerId.ToString());
                    /* LWF.Instances.<instanceId>.Handlers.<luaHandlerId> = function */
                    /* -2: LWF.Instances.<instanceId>.Handlers */
                    /* -1: key */
                }
                else
                {
                    Lua.lua_pop(l, 1);
                    /* -2: LWF.Instances.<instanceId>.Handlers */
                    /* -1: key: eventName string */
                }
            }
            /* -1: LWF.Instances.<instanceId>.Handlers */
            Lua.lua_pop(l, 1);
            /* 0 */

            handlerId = AddMovieEventHandler(instanceName,
                                             handlers["load"], handlers["postLoad"],
                                             handlers["unload"], handlers["enterFrame"],
                                             handlers["update"], handlers["render"]);
            Lua.lua_pushnumber(l, handlerId);
            /* handlerId */
            return(1);

error:
            Lua.lua_pushnumber(l, -1);
            /* -1: -1 */
            return(1);
        }
Пример #7
0
        public int AttachMovieLua(Movie movie, bool empty)
        {
            if (luaState == null)
            {
                return(0);
            }

            Lua.lua_State l    = (Lua.lua_State)luaState;
            int           args = Lua.lua_gettop(l);
            string        linkageName;
            string        attachName;
            int           attachDepth            = -1;
            bool          reorder                = false;
            int           offset                 = empty ? 2 : 3;
            MovieEventHandlerDictionary handlers =
                new MovieEventHandlerDictionary()
            {
                { "load", null },
                { "postLoad", null },
                { "unload", null },
                { "enterFrame", null },
                { "update", null },
                { "render", null }
            };

            Movie child;

            /* 1: LWF_Movie instance */
            /* 2: linkageName:string */
            /* 3: attachName:string */
            /* 4: table {key:string, handler:function} */
            /* 5: attachDepth:number (option) */
            /* 6: reorder:boolean (option) */
            /* or */
            /* 1: LWF_Movie instance */
            /* 2: attachName:string */
            /* 3: table {key:string, handler:function} */
            /* 4: attachDepth:number (option) */
            /* 5: reorder:boolean (option) */
            linkageName = empty ? "_empty" : Lua.lua_tostring(l, 2).ToString();
            attachName  = Lua.lua_tostring(l, offset).ToString();
            if (args >= offset + 1)
            {
                Lua.lua_getglobal(l, "LWF");
                /* -1: LWF */
                if (!Lua.lua_istable(l, -1))
                {
                    Lua.lua_pop(l, 1);
                    /* 0 */
                    goto error;
                }
                Lua.lua_getfield(l, -1, "Instances");
                /* -2: LWF */
                /* -1: LWF.Instances */
                Lua.lua_remove(l, -2);
                /* -1: LWF.Instances */
                if (!Lua.lua_istable(l, -1))
                {
                    Lua.lua_pop(l, 1);
                    /* 0 */
                    goto error;
                }
                Lua.lua_getfield(l, -1, instanceIdString);
                /* -2: LWF.Instances */
                /* -1: LWF.Instances.<instanceId> */
                Lua.lua_remove(l, -2);
                /* -1: LWF.Instances.<instanceId> */
                if (!Lua.lua_istable(l, -1))
                {
                    Lua.lua_pop(l, 1);
                    /* 0 */
                    goto error;
                }
                Lua.lua_getfield(l, -1, "Handlers");
                /* -2: LWF.Instances.<instanceId> */
                /* -1: LWF.Instances.<instanceId>.Handlers */
                Lua.lua_remove(l, -2);
                /* -1: LWF.Instances.<instanceId>.Handlers */
                if (!Lua.lua_istable(l, -1))
                {
                    Lua.lua_pop(l, 1);
                    /* 0 */
                    goto error;
                }

                Lua.lua_pushnil(l);
                /* -2: LWF.Instances.<instanceId>.Handlers */
                /* -1: nil */
                while (Lua.lua_next(l, 4) != 0)
                {
                    /* -3: LWF.Instances.<instanceId>.Handlers */
                    /* -2: key: eventName string */
                    /* -1: value: handler function */
                    string key = Lua.lua_tostring(l, -2).ToString();
                    if (key != null && Lua.lua_isfunction(l, -1))
                    {
                        int luaHandlerId = GetEventOffset();
                        handlers[key] = (Movie a) => {
                            if (!a.lwf.PushHandlerLua(luaHandlerId))
                            {
                                return;
                            }

                            /* -1: function */
                            Lua.lua_State ls = (Lua.lua_State)a.lwf.luaState;
                            Luna_LWF_Movie.push(ls, a, false);
                            /* -2: function */
                            /* -1: Movie or Button */
                            if (Lua.lua_pcall(ls, 1, 0, 0) != 0)
                            {
                                Lua.lua_pop(ls, 1);
                            }
                            /* 0 */
                        };


                        Lua.lua_setfield(l, -3, luaHandlerId.ToString());

                        /* LWF.Instances.<instanceId>.Handlers.
                         *      <luaHandlerId> = function */
                        /* -2: LWF.Instances.<instanceId>.Handlers */
                        /* -1: key */
                    }
                    else
                    {
                        Lua.lua_pop(l, 1);
                        /* -2: LWF.Instances.<instanceId>.Handlers */
                        /* -1: key: eventName string */
                    }
                }
                /* -1: LWF.Instances.<instanceId>.Handlers */
                Lua.lua_pop(l, 1);
                /* 0 */
            }
            if (args >= offset + 2)
            {
                attachDepth = (int)Lua.lua_tonumber(l, offset + 2);
            }
            if (args >= offset + 3)
            {
                reorder = Lua.lua_toboolean(l, offset + 3) != 0;
            }

            child = movie.AttachMovie(
                linkageName,
                attachName,
                attachDepth,
                reorder,
                handlers["load"],
                handlers["postLoad"],
                handlers["unload"],
                handlers["enterFrame"],
                handlers["update"],
                handlers["render"]);
            Luna_LWF_Movie.push(l, child, false);
            /* -1: LWF_Movie child */
            return(1);

error:
            Lua.lua_pushnil(l);
            /* -1: nil */
            return(1);
        }
Пример #8
0
	public void Call(Type type, Movie target)
	{
		MovieEventHandlerDictionary dict = null;
		switch (type) {
		case Type.LOAD: dict = load; break;
		case Type.POSTLOAD: dict = postLoad; break;
		case Type.UNLOAD: dict = unload; break;
		case Type.ENTERFRAME: dict = enterFrame; break;
		case Type.UPDATE: dict = update; break;
		case Type.RENDER: dict = render; break;
		}
		if (dict != null) {
			dict = new MovieEventHandlerDictionary(dict);
			foreach (var h in dict)
				h.Value(target);
		}
	}