Why does kotlin2js require `main` to take an array...
# javascript
m
Why does kotlin2js require
main
to take an array of strings for it to be detected but then the generate code passes an empty array?
fun main()
is not used as entry point,
fun main(args : Array<String>)
is used as entry point but
args
will always be an empty array. I'm using
moduleKind = "commonjs"
.
k
This was done for compatibility with Kotlin JVM
And since there's nothing to pass (no command line arguments), we alwas pass an empty array. This can be changed. For example, we could pass reasonable command line arguments when running on node.js
You can disable generation of call to
main
at all. Actually, it's not of much use in browser. I think the better approach is to define some function (
start
, for example) and call it from
body.onload
m
My code will run on node.js, actually.
Thus process.argv or process.argv.slice(1) should be passed. It's not clear to me how you could detect if you are running inside node.js though.
k
typeof process !== 'undefined' && process.versions && !!process.versions.node
You can create an issue on YT: http://kotl.in/issue
m
Thanks. I'll do it.
This is the issue I created: https://youtrack.jetbrains.com/issue/KT-16981 It's my first issue. I hope it's properly written.
k
Thanks!