Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
how to dispatch an event in a delegate in plugin ? — Gideros Forum

how to dispatch an event in a delegate in plugin ?

alexzhengalexzheng Guru
edited May 2012 in General questions
I'm writing a very simple plugin, and it's just a copy of gamekit.mm and make some modification.
Now I have a problem, how can I dispatch an event in the delegate method?
for example,
- (void)leaderboardViewControllerDidFinish:(GKLeaderboardViewController *)viewController
{
[self dismissModalViewController];

//how to dispatch an event here?
}

Comments

  • You can find an example of a tableview sending an event for the didSelectRowAtIndexPath delegate method in Mike Hart's UIKit plugin.

    Does it have to be an event? Or can it be a lua function called directly from the plugin?

    There are examples of dispatching an event and also using a callback function here:
    https://github.com/carolight/CBSamplePlugin
  • hi,I looked into Mike Hart's UIKit plugin.
    He made a bidirectional reference in both classes,
    A reference B and B reference A,and A dispatch event using B .

    delegate.L = L;
    delegate.target = this; //the target can dispatch event

    I also thought about this design pattern,but it may be prone to memory bug if not used carefully.

    Is this a weak reference,I google it but can not find.
    GReferenced* target;
  • @alexzheng

    if you have a look at line 1255 of uikit.mm, you'll see:
    <a href="http://forum.gideros.rocks/profile/property" rel="nofollow">@property</a> (nonatomic, assign) GReferenced* target;
    <a href="http://forum.gideros.rocks/profile/property" rel="nofollow">@property</a> (nonatomic, assign) lua_State* L;
    <a href="http://forum.gideros.rocks/profile/property" rel="nofollow">@property</a> (nonatomic, retain) NSArray *dataArray;
    the "assign" rather than "retain" makes it a weak reference. When a property is retain, like the dataArray, then to assign it, you do self.dataArray = newArray etc. That means it is a strong reference, and needs to be released at some point (in this example, in the dealloc). An assigned property does not need a release, it is assumed that the property will be viable until released by whatever created it.

    However, I think that uikit does have some memory release problems - when the view is released, the binder is not released, which is fine for views and buttons that are static for as long as the app is active. I have done some experimentation of doing the binding on the Lua side, rather than on the C side, so that the binder is automatically garbage collected by Lua, but my results are so complex, I thought the whole thing might as well be written in Objective C rather than using Lua. There are a lot of cleverer people than me out there though :).


  • oh,yes, this is a weak reference,I had not looked carefully all the code.
    I thought GReferenced is just a special key world at first. But it seems there is definition for this class,is that an undocument class in goderos?

    Maybe, if there is a ready to use object for dispatch event anywhere will be much simpler.
    We do not need to create an EventDispatcher and get reference to both lua_State and EventDispatcher based object.
Sign In or Register to comment.