Hello,
I have a question regarding the method communication from Lua to Swift.
I know that Lua has a special way to handle arrays & associative arrays as the same kind of objects.
Here is the situation:
-
Let’s say I fill an array with the players ids.
local playersIds = {} table.insert(playersIds, ‘Player A’) table.insert(playersIds, ‘Player B’)
-
Then I send this array to the app.
local event = { name=‘coronaView’, event=‘PlayersIdsUpdated’, playersIds=playersIds } Runtime:dispatchEvent(event)
-
I would expect to receive a NSArray/Array in the app. Instead, I’m receiving a Dictionary<Int,String>.
The thing is that I want to convert this list to JSON, and send it somewhere.
But the JSONSerialization class on iOS doesn’t handle Dictionary<Int** ,String **> values. The conversion just fails.
I know, there are a lot of solutions here, and it’s not a real problem.
As I’m just starting Lua & Corona, I was just wondering if there is a way to get directly a NSArray from Corona, without implementing something specific in Swift.
Thank you!
PS: The JSON package knows how to differentiate dictionaries and arrays at the encoding (https://docs.coronalabs.com/api/library/json/encode.html).