os.exit() command makes simulator crash

Hi

I tried to implement os.exit() code while pressing the exit button on my menu. But the corona simulator crashes(the send error report pops up).

I use a windows build CoronaSDK-2011.715.msi , tried downloading latest build CoronaSDK-2012.726.msi still it crashes

is there any other command is it normal
[import]uid: 115284 topic_id: 20383 reply_id: 320383[/import]

The os.exit() call does the equivalent of doing an “End Process” via the Task Manager. That is, you’re killing the app in a not-so-nice way. I don’t recommend that you use os.exit().

On iOS, setting up your app to exit itself is considered bad practice and may cause your app to be rejected by the app reviewers.

On Android, having your app exit itself is allowed. Especially if you override the Back key. However, instead of calling os.exit(), you should call the following function instead…
[lua]native.requestExit()[/lua]

This will call Android’s Activity.dismiss() method on the Java side, which will exit the Corona app gracefully. Please note that the native.requestExit() function is not supported on iOS and the Corona Simulator. This function will do nothing on those platforms, which is by design.

I hope this helps! [import]uid: 32256 topic_id: 20383 reply_id: 79914[/import]

thanks Joshua [import]uid: 115284 topic_id: 20383 reply_id: 80548[/import]

One quick question: where can I find API docs or info for functions like “native.requestExit()”??

  • the official API list doesn’t contain it, and I stumbled upon it by mistake while reading through “what’s new” section for coronaSDK build. [import]uid: 117906 topic_id: 20383 reply_id: 82437[/import]

Unfortunately, we haven’t documented the native.requestExit() function yet. Documenting this slipped off our to-do list, so I’ll re-add it to our queue to be documented in the near future. Thank you for bring this up. [import]uid: 32256 topic_id: 20383 reply_id: 82549[/import]

As I was saying previously, I happened to stumble upon this API by mistake while searching the forum. I understand the circumstances of it being missed out of the documentation, but I’m just wondering…is there any way for me to have a look somewhere (perhaps a file in the corona folder) in order to see/discover similar APIs?

Thank you.
[import]uid: 117906 topic_id: 20383 reply_id: 82568[/import]

No, there isn’t any single file that lists all APIs provided via Lua. This is because functions are dynamically added to Lua at runtime from the C++ side of Corona from various C++ files on our end. The best place to look up our API documentation is on the following API page…
http://developer.anscamobile.com/resources/apis

Also, the samples apps included with the Corona SDK shows you have to use our various APIs as well.

There might be a way to get a list of functions supported by each Lua module by doing the following within Lua. I have no idea if this will work or not (I don’t have a black belt in Lua), but it might be worth a shot.
[lua]local function PrintAllFunctionsFor(module)
for key,value in pairs(module) do
print(tostring(module) … “:” … tostring(key));
end
end
PrintAllFunctionsFor(native)
PrintAllFunctionsFor(display)
– etc…[/lua] [import]uid: 32256 topic_id: 20383 reply_id: 82576[/import]

The code above works flawlessly.
Thank you very much for taking the time to provide me with the answer. [import]uid: 117906 topic_id: 20383 reply_id: 82580[/import]