Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
How about dispatch custom broadcast events from plugin? — Gideros Forum

How about dispatch custom broadcast events from plugin?

alexzhengalexzheng Guru
edited May 2013 in General questions
for some simple plugins that just exports one or two static apis and dispatch some events when something happened, it's not quit straightforward to have to create a specific instance to dispatch these events and addEventListener on that instance in lua.
It will be much easy if these events can be dispatched directly and handled in lua by any object such as stage,just as what APPLICATION_START works.

Comments

  • ar2rsawseenar2rsawseen Maintainer
    edited May 2013
    Actually in plugins what you do is to create event object in lua and dispatch it on current instance, there is nothing that prohibits you from getting global stage and dispatching event on it inside plugin likes this:
    //get global stage
    lua_getglobal(L, "stage");
     
    //dispatch event on it
    lua_getfield(L, -1, "dispatchEvent");
     
    lua_pushvalue(L, -2);
     
    lua_getglobal(L, "Event");
    lua_getfield(L, -1, "new");
    lua_remove(L, -2);
     
    lua_call(L, 2, 0);
     
    lua_pop(L, 2);
  • That seems nice.
    I will try it later. :)
Sign In or Register to comment.