Enterprise: lua_State in delegates

How can we handle callbacks to the app when 3rd party SDK delegates fires? The lua_State is unknown to the delegates.

We’ve created Enterprise plugins for Chartboost, Airpush and TapJoy, and all of them have a neat set of delegates we’d like to subscribe to. As an example, Chartboost has a caching system, where we call Chartboost cacheInterstitial. When Chartboost is done loading the interstitial in the background, the delegate method didCacheInterstitial is invoked. But it does not know about the lua_State, so how do we make use of the delegate to report back to the Corona app?

Need this answered for both Android and iOS.

Thanks! [import]uid: 21746 topic_id: 34514 reply_id: 334514[/import]

Hey! The ads-provider Project Template solves this scenario nicely :slight_smile: I think I have what I need now, if not, I’ll post here again. [import]uid: 21746 topic_id: 34514 reply_id: 137228[/import]

Hey! The ads-provider Project Template solves this scenario nicely :slight_smile: I think I have what I need now, if not, I’ll post here again. [import]uid: 21746 topic_id: 34514 reply_id: 137228[/import]

what was your trick? I’m kind of grinding on the exact same issue [import]uid: 95944 topic_id: 34514 reply_id: 138874[/import]

Hi, take a look at the above mentioned example. You create a reference to the CoronaRuntime when calling the class constructor, and in your delegate implementation you can get the CoronaRuntime back from there.

YourPlugin::YourPlugin( id<coronaruntime> runtime )<br>: fRuntime( runtime ), fListener( NULL )<br>{<br>}<br>

and

<br>void<br>PluginChartboost::DispatchEvent(bool isError) const<br>{<br> lua_State *L = fRuntime.L;<br> <br> CoronaLuaNewEvent( L, kEvent );<br> <br> lua_pushboolean( L, isError );<br> lua_setfield( L, -2, "isError" );<br> <br> CoronaLuaDispatchEvent( L, fListener, 0 );<br>}<br>

Also, implement a destructor to remove the reference to the CoronaRuntime:

<br>YourPlugin::~YourPlugin()<br>{<br> CoronaLuaDeleteRef( fRuntime.L, fListener );<br>}<br> [import]uid: 21746 topic_id: 34514 reply_id: 138884[/import]

ok, then this part may sound noobish since I am new to objective-c:

how would you meet the ends for a delegate reception like:

@interface PlayhavenDelegate () <phpublishercontentrequestdelegate><br>@end<br><br>@implementation PlayhavenDelegate<br><br>-(void)request:(PHPublisherContentRequest *)request contentDidDismissWithType:(PHPublisherContentDismissType *)type{<br> NSString *message = [NSString stringWithFormat:@"[OK] User dismissed request: type %@", type];<br> NSLog(@" ****************** dismissed message %@", message);<br>}<br><br>@end<br><br>

to call our method:

<br>void<br>PluginChartboost::DispatchEvent(bool isError) const<br>{<br> lua_State *L = fRuntime.L;<br> <br> CoronaLuaNewEvent( L, kEvent );<br> <br> lua_pushboolean( L, isError );<br> lua_setfield( L, -2, "isError" );<br> <br> CoronaLuaDispatchEvent( L, fListener, 0 );<br>}<br>

Is it some syntactical thing I’m missing? [import]uid: 95944 topic_id: 34514 reply_id: 138888[/import]

I guess the thing is that I can access fRuntime, but I keep getting the following error:

Thread 1: EXC\_BAD\_ACCESS (code=2,address=0x14)  

I think lua_State is expired by the time I try to hit it via the delegate method

[import]uid: 95944 topic_id: 34514 reply_id: 138932[/import]

ok, nevermind. Figured it out. That was fun

(for others)
http://stackoverflow.com/questions/7892382/how-to-handle-objective-c-delegation-from-c [import]uid: 95944 topic_id: 34514 reply_id: 139042[/import]

what was your trick? I’m kind of grinding on the exact same issue [import]uid: 95944 topic_id: 34514 reply_id: 138874[/import]

Hi, take a look at the above mentioned example. You create a reference to the CoronaRuntime when calling the class constructor, and in your delegate implementation you can get the CoronaRuntime back from there.

YourPlugin::YourPlugin( id<coronaruntime> runtime )<br>: fRuntime( runtime ), fListener( NULL )<br>{<br>}<br>

and

<br>void<br>PluginChartboost::DispatchEvent(bool isError) const<br>{<br> lua_State *L = fRuntime.L;<br> <br> CoronaLuaNewEvent( L, kEvent );<br> <br> lua_pushboolean( L, isError );<br> lua_setfield( L, -2, "isError" );<br> <br> CoronaLuaDispatchEvent( L, fListener, 0 );<br>}<br>

Also, implement a destructor to remove the reference to the CoronaRuntime:

<br>YourPlugin::~YourPlugin()<br>{<br> CoronaLuaDeleteRef( fRuntime.L, fListener );<br>}<br> [import]uid: 21746 topic_id: 34514 reply_id: 138884[/import]

ok, then this part may sound noobish since I am new to objective-c:

how would you meet the ends for a delegate reception like:

@interface PlayhavenDelegate () <phpublishercontentrequestdelegate><br>@end<br><br>@implementation PlayhavenDelegate<br><br>-(void)request:(PHPublisherContentRequest *)request contentDidDismissWithType:(PHPublisherContentDismissType *)type{<br> NSString *message = [NSString stringWithFormat:@"[OK] User dismissed request: type %@", type];<br> NSLog(@" ****************** dismissed message %@", message);<br>}<br><br>@end<br><br>

to call our method:

<br>void<br>PluginChartboost::DispatchEvent(bool isError) const<br>{<br> lua_State *L = fRuntime.L;<br> <br> CoronaLuaNewEvent( L, kEvent );<br> <br> lua_pushboolean( L, isError );<br> lua_setfield( L, -2, "isError" );<br> <br> CoronaLuaDispatchEvent( L, fListener, 0 );<br>}<br>

Is it some syntactical thing I’m missing? [import]uid: 95944 topic_id: 34514 reply_id: 138888[/import]

I guess the thing is that I can access fRuntime, but I keep getting the following error:

Thread 1: EXC\_BAD\_ACCESS (code=2,address=0x14)  

I think lua_State is expired by the time I try to hit it via the delegate method

[import]uid: 95944 topic_id: 34514 reply_id: 138932[/import]

ok, nevermind. Figured it out. That was fun

(for others)
http://stackoverflow.com/questions/7892382/how-to-handle-objective-c-delegation-from-c [import]uid: 95944 topic_id: 34514 reply_id: 139042[/import]

I’m developing a plug-in for Chartboost.
I can easily load Chartboost interstitial banner.

But I’m unable to override the delegate methods (didCloseInterstitial, didFailToLoadInterstitial, didCacheInterstitial) etc.

Can you guys please guide me to solve this problem. I am new to enterprise and Objective-C.
[import]uid: 40227 topic_id: 34514 reply_id: 140634[/import]

I’m developing a plug-in for Chartboost.
I can easily load Chartboost interstitial banner.

But I’m unable to override the delegate methods (didCloseInterstitial, didFailToLoadInterstitial, didCacheInterstitial) etc.

Can you guys please guide me to solve this problem. I am new to enterprise and Objective-C.
[import]uid: 40227 topic_id: 34514 reply_id: 140634[/import]

@jesse.manuel, can you post the final code you got, because I’m getting the same error, and I didn’t really see the connection in your link. Thanks

@jesse.manuel, can you post the final code you got, because I’m getting the same error, and I didn’t really see the connection in your link. Thanks