How to start/use the generated JavaScript within an HTML page?


#1

This question sounds silly, but I could not find any example and I am not a JavaScript-guy. I copied the FancyLines example into my Kotlin project, set it up as a JavaScript one and it compiled into JavaScript. Looks like the one printed on the bottom of the Kotlin web page. But, how do I use/trigger it ?


#2

Have a look at this post: http://blog.jetbrains.com/kotlin/2012/06/kotlin-m2-is-out/ it has a nuber of examples


#3

Thanks Andrey,

somehow overseen those.

The hello-world example worked fine, since at one point a line on top of an opened file showed up where I had the possibilty to choose to setup this project as a pure Kotlin or a JS-Kotlin project. I choose the JS option and everything worked fine.

Then I thought I try the Kotlin-Creatures example, but I do not get the possibilty to choose between a pure Kotlin and a JS-Kotlin project as before in the hello-world example. I tried to provoke this or added some JS-Files to the dependency within the Module, but the only thing I get by building the project is

Information:Kotlin Compiler version 0.4.68
Information:Compilation completed with 26 errors and 5 warnings in 1 sec
Information:26 errors
Information:5 warnings
Error:Body is not allowed for annotation class
Error:Body is not allowed for annotation class
Warning:Useless import, it is hidden further
Warning:Parameter ‘col’ is never used
Warning:Parameter ‘comp’ is never used
D:DevelopmentPlaygroundKotlinTests2KotlinCreaturesKotlinCreaturessrcCanvasState.kt
Warning:Warning:line (8)Useless import, it is hidden further
Error:Error:line (94)Type inference failed: fun <T> jet.List<T>.reversed() : jet.List<T>
cannot be applied to
receiver: java.util.ArrayList<creatures.Shape>  arguments: ()
Error:Error:line (95)Unresolved reference: draw
D:DevelopmentPlaygroundKotlinTests2KotlinCreaturesKotlinCreaturessrcUtils.kt
Error:Error:line (8)Tuples are not supported. In the IDE you can use Alt+Enter to replace tuples with library classes
Error:Error:line (11)Tuples are not supported. In the IDE you can use Alt+Enter to replace tuples with library classes
Error:Error:line (16)Tuples are not supported. In the IDE you can use Alt+Enter to replace tuples with library classes
Error:Error:line (16)Tuples are not supported. In the IDE you can use Alt+Enter to replace tuples with library classes
Error:Error:line (16)Tuples are not supported. In the IDE you can use Alt+Enter to replace tuples with library classes
Error:Error:line (17)Tuples are not supported. In the IDE you can use Alt+Enter to replace tuples with library classes
Error:Error:line (17)Tuples are not supported. In the IDE you can use Alt+Enter to replace tuples with library classes
Error:Error:line (17)Tuples are not supported. In the IDE you can use Alt+Enter to replace tuples with library classes
Error:Error:line (18)Tuples are not supported. In the IDE you can use Alt+Enter to replace tuples with library classes
Error:Error:line (18)Tuples are not supported. In the IDE you can use Alt+Enter to replace tuples with library classes
Error:Error:line (18)Tuples are not supported. In the IDE you can use Alt+Enter to replace tuples with library classes
Error:Error:line (19)Tuples are not supported. In the IDE you can use Alt+Enter to replace tuples with library classes
Error:Error:line (19)Tuples are not supported. In the IDE you can use Alt+Enter to replace tuples with library classes
Error:Error:line (19)Tuples are not supported. In the IDE you can use Alt+Enter to replace tuples with library classes
Error:Error:line (20)Tuples are not supported. In the IDE you can use Alt+Enter to replace tuples with library classes
Error:Error:line (20)Tuples are not supported. In the IDE you can use Alt+Enter to replace tuples with library classes
Error:Error:line (20)Tuples are not supported. In the IDE you can use Alt+Enter to replace tuples with library classes
Error:Error:line (21)Tuples are not supported. In the IDE you can use Alt+Enter to replace tuples with library classes
Error:Error:line (21)Tuples are not supported. In the IDE you can use Alt+Enter to replace tuples with library classes
Error:Error:line (21)Tuples are not supported. In the IDE you can use Alt+Enter to replace tuples with library classes
Error:Error:line (24)Tuples are not supported. In the IDE you can use Alt+Enter to replace tuples with library classes
D:DevelopmentPlaygroundKotlinTests2KotlinCreaturesKotlinCreaturessrcmain.kt
Warning:Warning:line (8)Useless import, it is hidden further
Error:Error:line (51)Type mismatch: inferred type is java.util.ArrayList<T> but jet.List<T> was expected


#4

We have updated this and other js-examples on github, so you can pull last changes and try to run KotlinCreatures again.


#5

Works now. Thanks.