Arguments: argv
and argc
Passing command-line arguments to your application
Cheerp supports recieving arguments in main
. For example, you might have a main
function that looks like this:
Targeting the browserIf you are targeting the browser, main is supported, but in most cases you should try to use webMain instead and recieve arguments in a different way.
The ways to provide arguments depend on which target you are compiling to.
JavaScript modules
For JavaScript modules, you can pass the arguments through the initialization function like this:
WASI-CLI
When targeting WASI, Cheerp uses the WASI-CLI interface to get arguments, meaning that it will work on any runtime that has implemented the WASI-CLI proposal.
Other
When targeting something else, you can provide environment variables and program arguments by defining a global variable called CHEERP_ARGV
.
For example:
Limitations
It is not possible to receive arguments in main
when the main
function is in a different section than the target.
Comparison to webMain
webMain
cannot take arguments. To take arguments, use main
.