• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Kotlin for Android App Development: Kotlin scripts

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm brand new to Kotlin and have just discovered that Kotlin can be used for scripts as well as in regular programs. Can anyone point me to a good tutorial on the scripting aspects of Kotlin?

I've certainly had a need to write scripts from time to time and have done so in languages like BASIC, REXX, and other more recent languages. If Kotlin can do similar things, I should probably spend a bit of time getting at least an overview on scripting in Kotlin.
 
Author
Posts: 28
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Hugh,

If you know Kotlin, there's nothing you really have to learn to use Kotlin Scripts.

Simply put, try creating a Kotlin file with .kts extension instead of .kt and write your code without a main() function around it ;)

- Peter
 
H. Mungus
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That sounds simple enough :-)

But where can I run it? Or to put it another way, if I write a Kotlin script in, say, IDEA, that I want to run on my phone or another laptop, what has to be installed on that phone or laptop for the script to run correctly?
 
Peter Sommerhoff
Author
Posts: 28
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Hugh,

Why would you want to run a Kotlin script on your phone? Unless you have some mobile Linux distribution, I think you'll have to write an entire Android/iPhone app.

Could you elaborate on your use case?

- Peter
 
Peter Sommerhoff
Author
Posts: 28
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
...if installed correctly, you should be able to run the script from IDEA directly, just like a regular Kotlin file with a main() function.

- Peter
 
H. Mungus
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not following you. Do you mean I have to install IDEA on any device that needs to run a Kotlin script? Or that I don't need to install ANYTHING on the other device and the script will run just fine on the target machine from the development machine? The former seems to require a biggish IDE to be installed but that latter seems more like magic than anything. I was expecting to install some kind of (hopefully small) runtime environment on whatever machine runs the script.
 
H. Mungus
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I didn't really have a specific use case in mind when I asked the question. It just struck me that if a script is useful on one device, I might want to use it on another and that device could be a laptop, a tablet or a phone. Or maybe a bunch of devices, as in the case of, say, a regular download of files. Or let's say I had sales databases on a variety of phones where each person recorded their own sales and a script ran daily to upload the days sales from each salesperson to a central database where everyone could see it and reports spanning the whole sales force could be run.
 
Peter Sommerhoff
Author
Posts: 28
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Hugh,

Sounds like you just want to generally share code between platforms, and Kotlin has the exact same goal Take a look at Kotlin Multiplatform projects, these allow you to have so-called common code that can be reused across platforms.

Kotlin Scripts are a special type of Kotlin file that are useful to test code snippets, share pieces of code, or do smaller tasks as with batch scripts. No need to use scripts for what you're trying to do.

- Peter
 
H. Mungus
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It sounds like Kotlin has already figured out a better way for me to do things than traditional scripts :-) Thanks for the suggestion. I'll have to look into that!

By the way, Peter, thank you for ALL your help in my various questions this week! Much appreciated!

Vielen Dank!
 
Peter Sommerhoff
Author
Posts: 28
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome Hugh, glad I could help!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!