push() 공개 정적인 메소드

public static push ( Lua L, LWF obj, bool gc, Lua metatable = null ) : void
L Lua
obj LWF
gc bool
metatable Lua
리턴 void
예제 #1
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);
    }
예제 #2
0
파일: lwf_lua.cs 프로젝트: xubingyue/lwf
        public int AddButtonEventHandlerLua()
        {
            if (luaState == null)
            {
                return(0);
            }

            Lua.lua_State l = (Lua.lua_State)luaState;
            string        instanceName;
            ButtonEventHandlerDictionary handlers = new ButtonEventHandlerDictionary()
            {
                { "load", null },
                { "unload", null },
                { "enterFrame", null },
                { "update", null },
                { "render", null },
                { "press", null },
                { "release", null },
                { "rollOver", null },
                { "rollOut", null },
                { "keyPress", 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] = (Button a) => {
                        if (!a.lwf.PushHandlerLua(luaHandlerId))
                        {
                            return;
                        }

                        /* -1: function */
                        Lua.lua_State ls = (Lua.lua_State)a.lwf.luaState;
                        Luna_LWF_Button.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, 2);
                    /* 0 */
                    goto error;
                }
            }
            /* -1: LWF.Instances.<instanceId>.Handlers */
            Lua.lua_pop(l, 1);
            /* 0 */

            handlerId = AddButtonEventHandler(instanceName,
                                              handlers["load"], handlers["unload"],
                                              handlers["enterFrame"], handlers["update"],
                                              handlers["render"], handlers["press"],
                                              handlers["release"], handlers["rollOver"],
                                              handlers["rollOut"]);
            Lua.lua_pushnumber(l, handlerId);
            /* handlerId */
            return(1);

error:
            Lua.lua_pushnumber(l, -1);
            /* -1: -1 */
            return(1);
        }
예제 #3
0
파일: lwf_lua.cs 프로젝트: xubingyue/lwf
        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);
        }
예제 #4
0
파일: lwf_lua.cs 프로젝트: xubingyue/lwf
        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 */
        }
예제 #5
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);
        }