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
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
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;
https://sites.google.com/site/xraystudiogame
if you have a look at line 1255 of uikit.mm, you'll see:
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 .
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.
https://sites.google.com/site/xraystudiogame