Help me to understand how to dispatch event from my Obj C code

Hi,

So I’ve been trying to implement a login function on my C code and then I need to dispatch event along with some parameters.

This is my dispatch event code like :

// Create event and add message to it CoronaLuaNewEvent( L, kEvent ); lua\_pushstring( L, [sessionID UTF8String] ); lua\_setfield( L, -2, "sessionID" ); lua\_pushstring( L, [timeStamp UTF8String] ); lua\_setfield( L, -2, "timeStamp" ); lua\_pushstring( L, [mapID UTF8String] ); lua\_setfield( L, -2, "mapID" ); // Dispatch event to library's listener CoronaLuaDispatchEvent( L, library-\>GetListener(), 0 );

As you can see I’m trying to dispatch event with several properties : sessionID, timeStamp and mapID,

my lua code can receive the event but event.sessionID, event.timeStamp, etc always nil.

Is the code above the right way to add more properties in the event object? I can’t seem to find a good explanation on what lua_pushsting and lua_setfield do nor I understand where that -2 comes from.

Any help?

Thanks

Try:

CoronaLuaDispatchEvent( L, library-\>GetListener(), 1 );

hmm… what does the index (0/1) mean?

It’s not an index, it’s the number of results the function should return.

http://docs.coronalabs.com/daily/native/C/CoronaLua.html#TOC

Which in your case is 1 (the event table)

Try:

CoronaLuaDispatchEvent( L, library-\>GetListener(), 1 );

hmm… what does the index (0/1) mean?

It’s not an index, it’s the number of results the function should return.

http://docs.coronalabs.com/daily/native/C/CoronaLua.html#TOC

Which in your case is 1 (the event table)