Dispatching events from Native Code

Hi everybody,

Is there any way to dispatch event from the native code?

I know there’s an example on the documentation. This example use the willLoadMain: delegate to dispatch a runtime event, but, since I am interested on create a plugin to other corona users, I should be able to dispatch this event anywhere inside my code. And, as far as I understand, the CoronaDelegate is used inside the App Project, and I should use just the Plugin Project.

The problem is that I don’t have access to the Corona Runtime, and the lua_State as well. So, I tried to create a new lua_State, and Push the Runtime, but I keep getting the error: “no Runtime to send event to”

Here’s my code:
 

lua\_State \* L = CoronaLuaNew(); CoronaLuaPushRuntime(L); CoronaLuaNewEvent(L,kEventName); CoronaLuaRuntimeDispatchEvent(L,-1);

Anyone from the Corona Support Team?
Can I get the current *lua_State* outside the didMainLoad: method? I should be able to access the CoronaRuntime lua_State in my plugin. How can I do that?

You can save a reference to the CoronaRuntime object that you get from didLoadMain.  Then you can use that runtime time’s lua_State object.

Thanks @dchan!

But, I am working on a Plugin development. As far as I understand, I am not able to use didMainLoad: method inside the Plugin Project.

**UPDATE**
I’ll get the CoronaRuntime reference while I am initialising my plugin and store it. May this causes any problem in the future?

That shouldn’t cause any problems.

Thanks @dchan!

Can you help me with my another question?
http://forums.coronalabs.com/topic/45631-using-constants-on-the-library/

Anyone from the Corona Support Team?
Can I get the current *lua_State* outside the didMainLoad: method? I should be able to access the CoronaRuntime lua_State in my plugin. How can I do that?

You can save a reference to the CoronaRuntime object that you get from didLoadMain.  Then you can use that runtime time’s lua_State object.

Thanks @dchan!

But, I am working on a Plugin development. As far as I understand, I am not able to use didMainLoad: method inside the Plugin Project.

**UPDATE**
I’ll get the CoronaRuntime reference while I am initialising my plugin and store it. May this causes any problem in the future?

That shouldn’t cause any problems.

Thanks @dchan!

Can you help me with my another question?
http://forums.coronalabs.com/topic/45631-using-constants-on-the-library/

Hi dchan

could you give us code example illustrating :

You can save a reference to the CoronaRuntime object that you get from didLoadMain.  Then you can use that runtime time’slua_State object.

Thanks!

Olivier

Refael and dchan, would you be able to offer any ideas as to why I am getting errors when trying to use the lua_State from the runtime?

https://forums.coronalabs.com/topic/58195-uiimagewritetosavedphotosalbum-unable-to-callback-to-lua/

Hi dchan

could you give us code example illustrating :

You can save a reference to the CoronaRuntime object that you get from didLoadMain.  Then you can use that runtime time’slua_State object.

Thanks!

Olivier

Refael and dchan, would you be able to offer any ideas as to why I am getting errors when trying to use the lua_State from the runtime?

https://forums.coronalabs.com/topic/58195-uiimagewritetosavedphotosalbum-unable-to-callback-to-lua/