Example #1
0
        public void DestroyMovieLua(Movie movie)
        {
            if (luaState == null)
            {
                return;
            }

            Lua.lua_State l = (Lua.lua_State)luaState;
            Lua.lua_getglobal(l, "LWF");
            /* -1: LWF */
            if (!Lua.lua_istable(l, -1))
            {
                Lua.lua_pop(l, 1);
                /* 0 */
                return;
            }
            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 */
                return;
            }
            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 */
                return;
            }
            Lua.lua_getfield(l, -1, "Movies");
            /* -2: LWF.Instances.<instanceId> */
            /* -1: LWF.Instances.<instanceId>.Movies */
            Lua.lua_remove(l, -2);
            /* -1: LWF.Instances.<instanceId>.Movies */
            if (!Lua.lua_istable(l, -1))
            {
                Lua.lua_pop(l, 1);
                /* 0 */
                return;
            }
            Lua.lua_pushnil(l);
            /* -2: LWF.Instances.<instanceId>.Movies */
            /* -1: nil */
            Lua.lua_setfield(l, -2, movie.iObjectId.ToString());
            /* LWF.Instances.<instanceId>.Movies.<iObjectId> = nil */
            /* -1: LWF.Instances.<instanceId>.Movies */
            Lua.lua_pop(l, 1);
            /* 0 */
            Luna_LWF_Movie.Destroy(l, movie);
            return;
        }
Example #2
0
 public static void open(Lua.lua_State L)
 {
     Luna.dostring(L, "if __luna==nil then __luna={} end");
     Luna.dostring(L, "    if __luna.copyMethodsFrom==nil then\n        function __luna.copyMethodsFrom(methodsChild, methodsParent)\n            for k,v in pairs(methodsParent) do\n                if k~='__index' and k~='__newindex' and methodsChild[k]==nil then\n                    methodsChild[k]=v\n                end\n            end\n        end\n        function __luna.overwriteMethodsFrom(methodsChild, methodsParent)\n            for k,v in pairs(methodsParent) do\n                if k~='__index' and k~='__newindex' then\n                    if verbose then print('registering', k, methodsChild[k]) end\n                    methodsChild[k]=v\n                end\n            end\n        end\n    end\n    ");
     impl_LunaTraits_LWF_LWF.luna_init_hashmap();
     impl_LunaTraits_LWF_LWF.luna_init_write_hashmap();
     Luna_LWF_LWF.Register(L);
     Luna.dostring(L, "if not LWF then LWF={} end LWF.LWF=__luna.LWF_LWF");
     Luna.dostring(L, "                __luna.LWF_LWF.luna_class='.LWF'");
     impl_LunaTraits_LWF_Button.luna_init_hashmap();
     impl_LunaTraits_LWF_Button.luna_init_write_hashmap();
     Luna_LWF_Button.Register(L);
     Luna.dostring(L, "if not LWF then LWF={} end LWF.Button=__luna.LWF_Button");
     Luna.dostring(L, "                __luna.LWF_Button.luna_class='.Button'");
     impl_LunaTraits_LWF_Movie.luna_init_hashmap();
     impl_LunaTraits_LWF_Movie.luna_init_write_hashmap();
     Luna_LWF_Movie.Register(L);
     Luna.dostring(L, "if not LWF then LWF={} end LWF.Movie=__luna.LWF_Movie");
     Luna.dostring(L, "                __luna.LWF_Movie.luna_class='.Movie'");
     impl_LunaTraits_LWF_Point.luna_init_hashmap();
     impl_LunaTraits_LWF_Point.luna_init_write_hashmap();
     Luna_LWF_Point.Register(L);
     Luna.dostring(L, "if not LWF then LWF={} end LWF.Point=__luna.LWF_Point");
     Luna.dostring(L, "                __luna.LWF_Point.luna_class='.Point'");
 }
Example #3
0
 public static void close(Lua.lua_State L)
 {
     Luna_LWF_LWF.Unregister(L);
     Luna_LWF_Button.Unregister(L);
     Luna_LWF_Movie.Unregister(L);
     Luna_LWF_Point.Unregister(L);
 }
Example #4
0
        public void CallFunctionLua(string function, Movie movie)
        {
            if (luaState == null)
            {
                return;
            }

            Lua.lua_State l = (Lua.lua_State)luaState;
            Lua.lua_getglobal(l, "LWF");
            /* -1: LWF */
            if (!Lua.lua_istable(l, -1))
            {
                Lua.lua_pop(l, 1);
                /* 0 */
                return;
            }
            Lua.lua_getfield(l, -1, "Script");
            /* -2: LWF */
            /* -1: LWF.Script */
            Lua.lua_remove(l, -2);
            /* -1: LWF.Script */
            if (!Lua.lua_istable(l, -1))
            {
                Lua.lua_pop(l, 1);
                /* 0 */
                return;
            }
            Lua.lua_getfield(l, -1, name);
            /* -2: LWF.Script */
            /* -1: LWF.Script.<name> */
            Lua.lua_remove(l, -2);
            /* -1: LWF.Script.<name> */
            if (!Lua.lua_istable(l, -1))
            {
                Lua.lua_pop(l, 1);
                /* 0 */
                return;
            }
            Lua.lua_getfield(l, -1, function);
            /* -2: LWF.Script.<name> */
            /* -1: LWF.Script.<name>.<function> */
            Lua.lua_remove(l, -2);
            /* -1: LWF.Script.<name>.<function> */
            if (!Lua.lua_isfunction(l, -1))
            {
                Lua.lua_pop(l, 1);
                /* 0 */
                return;
            }
            Luna_LWF_Movie.push(l, movie, false);
            /* -2: LWF.Script.<name>.<function> */
            /* -1: LWF_Movie instance */
            if (Lua.lua_pcall(l, 1, 0, 0) != 0)
            {
                Lua.lua_pop(l, 1);
            }
            /* 0 */
        }
Example #5
0
    public static int _bind_gotoAndPlay_overload_2(Lua.lua_State L)
    {
        LWF.Movie self    = Luna_LWF_Movie.check(L, 1);
        int       frameNo = (int)Lua.lua_tonumber(L, 2);

        try {
            self.GotoAndPlay(frameNo);
        } catch (Exception e) { Lua.luaL_error(L, new Lua.CharPtr(e.ToString())); }
        return(0);
    }
Example #6
0
    public static int _bind_gotoAndPlay_overload_1(Lua.lua_State L)
    {
        LWF.Movie self  = Luna_LWF_Movie.check(L, 1);
        string    label = Lua.lua_tostring(L, 2).ToString();

        try {
            self.GotoAndPlay(label);
        } catch (Exception e) { Lua.luaL_error(L, new Lua.CharPtr(e.ToString())); }
        return(0);
    }
Example #7
0
 public static int _bind_getParent(Lua.lua_State L)
 {
     if (Lua.lua_gettop(L) != 1 || Luna.get_uniqueid(L, 1) !=
         LunaTraits_LWF_Button.uniqueID)
     {
         Luna.printStack(L);
         Lua.luaL_error(L, "luna typecheck failed: LWF.Button.parent");
     }
     LWF.Button a = Luna_LWF_Button.check(L, 1);
     Luna_LWF_Movie.push(L, a.parent, false);
     return(1);
 }
Example #8
0
 public static int _bind_getLWF(Lua.lua_State L)
 {
     if (Lua.lua_gettop(L) != 1 || Luna.get_uniqueid(L, 1) !=
         LunaTraits_LWF_Movie.uniqueID)
     {
         Luna.printStack(L);
         Lua.luaL_error(L, "luna typecheck failed: LWF.Movie.lwf");
     }
     LWF.Movie a =
         Luna_LWF_Movie.check(L, 1);
     Luna_LWF_LWF.push(L, a.lwf, false);
     return(1);
 }
Example #9
0
    public static int _bind_prevFrame(Lua.lua_State L)
    {
        if (Lua.lua_gettop(L) != 1 ||
            Luna.get_uniqueid(L, 1) != 29625181)
        {
            Luna.printStack(L); Lua.luaL_error(L, "luna typecheck failed:prevFrame(LWF.Movie self)");
        }

        LWF.Movie self = Luna_LWF_Movie.check(L, 1);
        try {
            self.PrevFrame();
        } catch (Exception e) { Lua.luaL_error(L, new Lua.CharPtr(e.ToString())); }
        return(0);
    }
Example #10
0
 public static int _bind_getBlue(Lua.lua_State L)
 {
     if (Lua.lua_gettop(L) != 1 ||
         Luna.get_uniqueid(L, 1) != 29625181)
     {
         Luna.printStack(L); Lua.luaL_error(L, "luna typecheck failed:getBlue(LWF.Movie self ...)");
     }
     LWF.Movie o = Luna_LWF_Movie.check(L, 1);
     try {
         float ret = getBlue(o);
         Lua.lua_pushnumber(L, ret);
     } catch (Exception e) { Lua.luaL_error(L, new Lua.CharPtr(e.ToString())); }
     return(1);
 }
Example #11
0
    public static int __index(Lua.lua_State L)
    {
        if (Lua.lua_gettop(L) == 2 && Luna.get_uniqueid(L, 1) ==
            LunaTraits_LWF_Movie.uniqueID)
        {
            LWF.Movie o =
                Luna_LWF_Movie.check(L, 1);
            string name = Lua.lua_tostring(L, 2).ToString();
            if (o.lwf.GetFieldLua(o, name))
            {
                return(1);
            }
            LWF.Movie movie = o.SearchMovieInstance(name, false);
            if (movie != null)
            {
                Lua.lua_pop(L, 1);
                Luna_LWF_Movie.push(L, movie, false);
                return(1);
            }
            LWF.Button button = o.SearchButtonInstance(name, false);
            if (button != null)
            {
                Lua.lua_pop(L, 1);
                Luna_LWF_Button.push(L, button, false);
                return(1);
            }
        }


        {
            Lua.lua_CFunction fnc = null;
            if (LunaTraits_LWF_Movie.properties.TryGetValue(Lua.lua_tostring(L, 2).ToString(), out fnc))
            {
                Lua.lua_pop(L, 1);                // remove self
                return(fnc(L));
            }
        }

        int mt = Lua.lua_getmetatable(L, 1);

        if (mt == 0)
        {
            Lua.luaL_error(L, "__index");             //end
        }
        Lua.lua_pushstring(L, Lua.lua_tostring(L, 2));
        Lua.lua_rawget(L, -2);
        return(1);
    }
Example #12
0
    public static int _bind_setVisible(Lua.lua_State L)
    {
        if (Lua.lua_gettop(L) != 2 ||
            Luna.get_uniqueid(L, 1) != 29625181 ||
            Lua.lua_isboolean(L, 2))
        {
            Luna.printStack(L); Lua.luaL_error(L, "luna typecheck failed:setVisible(LWF.Movie self ...)");
        }
        LWF.Movie o = Luna_LWF_Movie.check(L, 1);
        bool      v = Lua.lua_toboolean(L, 2) != 0;

        try {
            setVisible(o, v);
        } catch (Exception e) { Lua.luaL_error(L, new Lua.CharPtr(e.ToString())); }
        return(0);
    }
Example #13
0
    public static int _bind_setBlue(Lua.lua_State L)
    {
        if (Lua.lua_gettop(L) != 2 ||
            Luna.get_uniqueid(L, 1) != 29625181 ||
            Lua.lua_isnumber(L, 2) == 0)
        {
            Luna.printStack(L); Lua.luaL_error(L, "luna typecheck failed:setBlue(LWF.Movie self ...)");
        }
        LWF.Movie o = Luna_LWF_Movie.check(L, 1);
        float     v = (float)Lua.lua_tonumber(L, 2);

        try {
            setBlue(o, v);
        } catch (Exception e) { Lua.luaL_error(L, new Lua.CharPtr(e.ToString())); }
        return(0);
    }
Example #14
0
    public static int _bind_localToGlobal(Lua.lua_State L)
    {
        if (Lua.lua_gettop(L) != 2 ||
            Luna.get_uniqueid(L, 1) != 29625181 ||
            Luna.get_uniqueid(L, 2) != LunaTraits_LWF_Point.uniqueID)
        {
            Luna.printStack(L); Lua.luaL_error(L, "luna typecheck failed:localToGlobal(LWF.Movie self)");
        }

        LWF.Movie self  = Luna_LWF_Movie.check(L, 1);
        LWF.Point point = Luna_LWF_Point.check(L, 2);
        try {
            LWF.Point ret = self.LocalToGlobal(point);
            Luna_LWF_Point.push(L, ret, true, "LWF_Point");
        } catch (Exception e) { Lua.luaL_error(L, new Lua.CharPtr(e.ToString())); }
        return(1);
    }
Example #15
0
    public static int _bind_gotoFrame(Lua.lua_State L)
    {
        if (Lua.lua_gettop(L) != 2 ||
            Luna.get_uniqueid(L, 1) != 29625181 ||
            Lua.lua_isnumber(L, 2) == 0)
        {
            Luna.printStack(L); Lua.luaL_error(L, "luna typecheck failed:gotoFrame(LWF.Movie self)");
        }

        LWF.Movie self    = Luna_LWF_Movie.check(L, 1);
        int       frameNo = (int)Lua.lua_tonumber(L, 2);

        try {
            self.GotoFrame(frameNo);
        } catch (Exception e) { Lua.luaL_error(L, new Lua.CharPtr(e.ToString())); }
        return(0);
    }
Example #16
0
    public static int _bind_scaleTo(Lua.lua_State L)
    {
        if (Lua.lua_gettop(L) != 3 ||
            Luna.get_uniqueid(L, 1) != 29625181 ||
            Lua.lua_isnumber(L, 2) == 0 ||
            Lua.lua_isnumber(L, 3) == 0)
        {
            Luna.printStack(L); Lua.luaL_error(L, "luna typecheck failed:scaleTo(LWF.Movie self)");
        }

        LWF.Movie self = Luna_LWF_Movie.check(L, 1);
        float     vx   = (float)Lua.lua_tonumber(L, 2);
        float     vy   = (float)Lua.lua_tonumber(L, 3);

        try {
            self.ScaleTo(vx, vy);
        } catch (Exception e) { Lua.luaL_error(L, new Lua.CharPtr(e.ToString())); }
        return(0);
    }
Example #17
0
    public static int attachMovie(Lua.lua_State L)
    {
        LWF.Movie a;
        int       args = Lua.lua_gettop(L);

        if (args < 3 || args > 6)
        {
            goto error;
        }
        if (Luna.get_uniqueid(L, 1) != LunaTraits_LWF_Movie.uniqueID)
        {
            goto error;
        }
        if (Lua.lua_isstring(L, 2) == 0 || Lua.lua_isstring(L, 3) == 0)
        {
            goto error;
        }
        if (args >= 4 && !Lua.lua_istable(L, 4))
        {
            goto error;
        }
        if (args >= 5 && Lua.lua_isnumber(L, 5) == 0)
        {
            goto error;
        }
        if (args >= 6 && !Lua.lua_isboolean(L, 6))
        {
            goto error;
        }

        a = Luna_LWF_Movie.check(L, 1);
        return(a.lwf.AttachMovieLua(a));

error:
        Luna.printStack(L);
        Lua.luaL_error(L, "luna typecheck failed: LWF.Movie.attachMovie");
        return(1);
    }
Example #18
0
    public static int __newindex(Lua.lua_State L)
    {
        Lua.lua_CFunction fnc = null;
        if (LunaTraits_LWF_Movie.write_properties.TryGetValue(Lua.lua_tostring(L, 2).ToString(), out fnc))
        {
            Lua.lua_insert(L, 2);            // swap key and value
            Lua.lua_settop(L, 2);            // delete key
            return(fnc(L));
        }
        if (Lua.lua_gettop(L) == 3 && Luna.get_uniqueid(L, 1) ==
            LunaTraits_LWF_Movie.uniqueID)
        {
            LWF.Movie o =
                Luna_LWF_Movie.check(L, 1);
            string name = Lua.lua_tostring(L, 2).ToString();
            if (o.lwf.SetFieldLua(o, name))
            {
                return(0);
            }
        }

        Lua.luaL_error(L, "__newindex doesn't allow defining non-property member");
        return(0);
    }
Example #19
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);
        }
Example #20
0
        public int AddEventHandlerLua(Movie movie = null, Button button = null)
        {
            if (luaState == null)
            {
                return(0);
            }

            Lua.lua_State l = (Lua.lua_State)luaState;
            string        ev;
            int           luaHandlerId;
            int           handlerId;

            /* 1: LWF_LWF instance */
            /* 2: string */
            /* 3: function */
            ev = 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_pushvalue(l, 3);
            /* -2: LWF.Instances.<instanceId>.Handlers */
            /* -1: function */
            luaHandlerId = GetEventOffset();
            Lua.lua_setfield(l, -2, luaHandlerId.ToString());
            /* LWF.Instances.<instanceId>.Handlers.<luaHandlerId> = function */
            /* -1: LWF.Instances.<instanceId>.Handlers */
            Lua.lua_pop(l, 1);
            /* 0 */

            if (movie != null)
            {
                if (string.IsNullOrEmpty(ev) || MovieEvents.ContainsKey(ev))
                {
                    /* Movie event */
                    handlerId = movie.AddEventHandler(ev, (Movie m) => {
                        Lua.lua_State _l = (Lua.lua_State)m.lwf.luaState;
                        if (!m.lwf.PushHandlerLua(luaHandlerId))
                        {
                            return;
                        }
                        /* -1: function */

                        Luna_LWF_Movie.push(_l, m, false);
                        /* -2: function */
                        /* -1: Movie */
                        if (Lua.lua_pcall(_l, 1, 0, 0) != 0)
                        {
                            Lua.lua_pop(_l, 1);
                        }
                    });
                }
                else
                {
                    handlerId = movie.AddEventHandler(ev, () => {
                        Lua.lua_State _l = (Lua.lua_State)movie.lwf.luaState;
                        if (!movie.lwf.PushHandlerLua(luaHandlerId))
                        {
                            return;
                        }
                        /* -1: function */

                        /* User defined event */
                        Lua.lua_createtable(_l, 0, 2);
                        /* -2: function */
                        /* -1: table */
                        Lua.lua_pushstring(_l, ev);
                        /* -3: function */
                        /* -2: table */
                        /* -1: string(type) */
                        Lua.lua_setfield(_l, -2, "type");
                        /* -2: function */
                        /* -1: table */
                        if (Lua.lua_istable(_l, 2))
                        {
                            Lua.lua_getfield(_l, 2, "param");
                            /* -3: function */
                            /* -2: table */
                            /* -1: param */
                        }
                        else
                        {
                            Lua.lua_pushnil(_l);
                            /* -3: function */
                            /* -2: table */
                            /* -1: nil */
                        }
                        Lua.lua_setfield(_l, -2, "param");
                        /* -2: function */
                        /* -1: table */
                        if (Lua.lua_pcall(_l, 1, 0, 0) != 0)
                        {
                            Lua.lua_pop(_l, 1);
                        }
                        /* 0 */
                    });
                }
            }
            else if (button != null)
            {
                if (string.Compare(ev, "keyPress") == 0)
                {
                    handlerId = button.AddEventHandler(ev, (Button b, int k) => {
                        if (!b.lwf.PushHandlerLua(luaHandlerId))
                        {
                            return;
                        }

                        /* -1: function */
                        Lua.lua_State _l = (Lua.lua_State)b.lwf.luaState;
                        Luna_LWF_Button.push(_l, b, false);
                        Lua.lua_pushnumber(_l, k);
                        /* -3: function */
                        /* -2: Button */
                        /* -1: int */
                        if (Lua.lua_pcall(l, 2, 0, 0) != 0)
                        {
                            Lua.lua_pop(l, 1);
                        }
                        /* 0 */
                    });
                }
                else
                {
                    handlerId = button.AddEventHandler(ev, (Button b) => {
                        if (!b.lwf.PushHandlerLua(luaHandlerId))
                        {
                            return;
                        }

                        /* -1: function */
                        Lua.lua_State _l = (Lua.lua_State)b.lwf.luaState;
                        Luna_LWF_Button.push(_l, b, false);
                        /* -2: function */
                        /* -1: Button */
                        if (Lua.lua_pcall(l, 1, 0, 0) != 0)
                        {
                            Lua.lua_pop(l, 1);
                        }
                        /* 0 */
                    });
                }
            }
            else
            {
                handlerId = AddEventHandler(ev, (Movie m, Button b) => {
                    if (!m.lwf.PushHandlerLua(luaHandlerId))
                    {
                        return;
                    }

                    /* -1: function */
                    Lua.lua_State _l = (Lua.lua_State)m.lwf.luaState;
                    Luna_LWF_Movie.push(_l, m, false);
                    Luna_LWF_Button.push(_l, b, false);
                    /* -3: function */
                    /* -2: Movie */
                    /* -1: Button */
                    if (Lua.lua_pcall(l, 2, 0, 0) != 0)
                    {
                        Lua.lua_pop(l, 1);
                    }
                    /* 0 */
                });
            }

            Lua.lua_pushnumber(l, handlerId);
            /* -1: handlerId */
            return(1);

error:
            Lua.lua_pushnumber(l, -1);
            /* -1: -1 */
            return(1);
        }
Example #21
0
        public void DestroyMovieLua(Movie movie)
        {
            if (luaState == null)
            {
                return;
            }

            Lua.lua_State l = (Lua.lua_State)luaState;
            Lua.lua_getglobal(l, "LWF");
            /* -1: LWF */
            if (!Lua.lua_istable(l, -1))
            {
                Lua.lua_pop(l, 1);
                /* 0 */
                return;
            }
            Lua.lua_getfield(l, -1, "Script");
            /* -2: LWF */
            /* -1: LWF.Script */
            Lua.lua_remove(l, -2);
            /* -1: LWF.Script */
            if (!Lua.lua_istable(l, -1))
            {
                Lua.lua_pop(l, 1);
                /* 0 */
                return;
            }
            Lua.lua_getfield(l, -1, name);
            /* -2: LWF.Script */
            /* -1: LWF.Script.<name> */
            Lua.lua_remove(l, -2);
            /* -1: LWF.Script.<name> */
            if (!Lua.lua_istable(l, -1))
            {
                Lua.lua_pop(l, 1);
                /* 0 */
                return;
            }
            Lua.lua_getfield(l, -1, "Destroy");
            /* -2: LWF.Script.<name> */
            /* -1: LWF.Script.<name>.Destroy */
            Lua.lua_remove(l, -2);
            /* -1: LWF.Script.<name>.Destroy */
            if (Lua.lua_isfunction(l, -1))
            {
                Luna_LWF_LWF.push(l, this, false);
                /* -2: LWF.Script.<name>.Destroy */
                /* -1: LWF instance */
                if (Lua.lua_pcall(l, 1, 0, 0) != 0)
                {
                    Lua.lua_pop(l, 1);
                }
                /* 0 */
            }
            Lua.lua_getglobal(l, "LWF");
            /* -1: LWF */
            if (!Lua.lua_istable(l, -1))
            {
                Lua.lua_pop(l, 1);
                /* 0 */
                return;
            }
            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 */
                return;
            }
            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 */
                return;
            }
            Lua.lua_getfield(l, -1, "Movies");
            /* -2: LWF.Instances.<instanceId> */
            /* -1: LWF.Instances.<instanceId>.Movies */
            Lua.lua_remove(l, -2);
            /* -1: LWF.Instances.<instanceId>.Movies */
            if (!Lua.lua_istable(l, -1))
            {
                Lua.lua_pop(l, 1);
                /* 0 */
                return;
            }
            Lua.lua_pushnil(l);
            /* -2: LWF.Instances.<instanceId>.Movies */
            /* -1: nil */
            Lua.lua_setfield(l, -2, movie.iObjectId.ToString());
            /* LWF.Instances.<instanceId>.Movies.<iObjectId> = nil */
            /* -1: LWF.Instances.<instanceId>.Movies */
            Lua.lua_pop(l, 1);
            /* 0 */
            Luna_LWF_Movie.Destroy(l, movie);
            return;
        }
Example #22
0
        public void CallEventFunctionLua(int eventId, Movie movie, Button button)
        {
            if (luaState == null)
            {
                return;
            }

            if (!m_eventFunctions.ContainsKey(eventId))
            {
                return;
            }

            Lua.lua_State l = (Lua.lua_State)luaState;
            Lua.lua_getglobal(l, "LWF");
            /* -1: LWF */
            if (!Lua.lua_istable(l, -1))
            {
                Lua.lua_pop(l, 1);
                /* 0 */
                return;
            }
            Lua.lua_getfield(l, -1, "Script");
            /* -2: LWF */
            /* -1: LWF.Script */
            Lua.lua_remove(l, -2);
            /* -1: LWF.Script */
            if (!Lua.lua_istable(l, -1))
            {
                Lua.lua_pop(l, 1);
                /* 0 */
                return;
            }
            Lua.lua_getfield(l, -1, name);
            /* -2: LWF.Script */
            /* -1: LWF.Script.<name> */
            Lua.lua_remove(l, -2);
            /* -1: LWF.Script.<name> */
            if (!Lua.lua_istable(l, -1))
            {
                Lua.lua_pop(l, 1);
                /* 0 */
                return;
            }
            string ev = "Event_";

            Lua.lua_getfield(l, -1,
                             (ev + data.strings[data.events[eventId].stringId]));
            /* -2: LWF.Script.<name> */
            /* -1: LWF.Script.<name>.Event_<eventName> */
            Lua.lua_remove(l, -2);
            /* -1: LWF.Script.<name>.Event_<eventName>*/

            if (!Lua.lua_isfunction(l, -1))
            {
                Lua.lua_pop(l, 1);
                /* 0 */
                return;
            }
            Luna_LWF_Movie.push(l, movie, false);
            /* -2: LWF.Script.<name>.Event_<eventName> */
            /* -1: LWF_Movie instance */
            Luna_LWF_Button.push(l, button, false);
            /* -3: LWF.Script.<name>.Event_<eventName> */
            /* -2: LWF_Movie instance */
            /* -1: LWF_Button instance */
            if (Lua.lua_pcall(l, 2, 0, 0) != 0)
            {
                Lua.lua_pop(l, 1);
            }
            /* 0 */
        }
Example #23
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);
        }
Example #24
0
        public int AddEventHandlerLua()
        {
            if (luaState == null)
            {
                return(0);
            }

            Lua.lua_State l = (Lua.lua_State)luaState;
            string        ev;
            int           luaHandlerId;
            int           handlerId;

            /* 1: LWF_LWF instance */
            /* 2: string */
            /* 3: function */
            ev = 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_pushvalue(l, 3);
            /* -2: LWF.Instances.<instanceId>.Handlers */
            /* -1: function */
            luaHandlerId = GetEventOffset();
            Lua.lua_setfield(l, -2, luaHandlerId.ToString());
            /* LWF.Instances.<instanceId>.Handlers.<luaHandlerId> = function */
            /* -1: LWF.Instances.<instanceId>.Handlers */
            Lua.lua_pop(l, 1);
            /* 0 */

            handlerId = AddEventHandler(ev, (Movie m, Button b) => {
                if (!m.lwf.PushHandlerLua(luaHandlerId))
                {
                    return;
                }

                /* -1: function */
                Lua.lua_State _l = (Lua.lua_State)m.lwf.luaState;
                Luna_LWF_Movie.push(_l, m, false);
                Luna_LWF_Button.push(_l, b, false);
                /* -3: function */
                /* -2: Movie */
                /* -1: Button */
                if (Lua.lua_pcall(l, 2, 0, 0) != 0)
                {
                    Lua.lua_pop(l, 1);
                }
                /* 0 */
            });
            Lua.lua_pushnumber(l, handlerId);
            /* -1: handlerId */
            return(1);

error:
            Lua.lua_pushnumber(l, -1);
            /* -1: -1 */
            return(1);
        }