commandline arguments?

Hi all,

quick question: How can I pass commandline arguments to a Corona program?

Kind regards

You should be able to get launchArgs. You can see an example here:

https://docs.coronalabs.com/api/event/notification/type.html

Rob

You can acquire a Mac or Win32 desktop app’s command line argments on startup from your “main.lua” file like this…

-- The "..." provides a table of launch arguments on all platforms. local launchArgs = ... if localArgs then -- This table's "args" field provides a desktop app's command line arguments. -- This is an array of strings. Will be nil if no command line args were provided. local commandLineArgs = launchArgs.args end

As of daily build #2963, Corona made Win32 desktop apps are single instance apps by default.  This matches Corona’s behavior on other platforms.  So, when you attempt to launch another instance of your app while an instance is already running, its command line arguments (if provided) are passed over to the first instance via a Lua “system” event of type “applicationOpen”.  Have a look at the following documentation for more details.

   https://docs.coronalabs.com/daily/api/event/system/type.html

   https://docs.coronalabs.com/daily/api/event/system/commandLineArgs.html

If you don’t want your Win32 app to be single instance only, then you can change it back to the old behavior via the “build.settings” option documented in the link below.  For multi-instance Win32 apps, you’ll never receive a system event of type “applicationOpen”.  Instead, a new instance of your app is created and its command line arguments will be provided to the “main.lua” file via “…” as shown in the code above.

   https://docs.coronalabs.com/daily/guide/distribution/win32Build/index.html#singleinstance

I hope this helps!

thanks a lot, I managed to get it working!

You should be able to get launchArgs. You can see an example here:

https://docs.coronalabs.com/api/event/notification/type.html

Rob

You can acquire a Mac or Win32 desktop app’s command line argments on startup from your “main.lua” file like this…

-- The "..." provides a table of launch arguments on all platforms. local launchArgs = ... if localArgs then -- This table's "args" field provides a desktop app's command line arguments. -- This is an array of strings. Will be nil if no command line args were provided. local commandLineArgs = launchArgs.args end

As of daily build #2963, Corona made Win32 desktop apps are single instance apps by default.  This matches Corona’s behavior on other platforms.  So, when you attempt to launch another instance of your app while an instance is already running, its command line arguments (if provided) are passed over to the first instance via a Lua “system” event of type “applicationOpen”.  Have a look at the following documentation for more details.

   https://docs.coronalabs.com/daily/api/event/system/type.html

   https://docs.coronalabs.com/daily/api/event/system/commandLineArgs.html

If you don’t want your Win32 app to be single instance only, then you can change it back to the old behavior via the “build.settings” option documented in the link below.  For multi-instance Win32 apps, you’ll never receive a system event of type “applicationOpen”.  Instead, a new instance of your app is created and its command line arguments will be provided to the “main.lua” file via “…” as shown in the code above.

   https://docs.coronalabs.com/daily/guide/distribution/win32Build/index.html#singleinstance

I hope this helps!

thanks a lot, I managed to get it working!