From 370d8cf605c8d71073bc53b8c956e50ee520897c Mon Sep 17 00:00:00 2001 From: sergeych Date: Tue, 10 Jun 2025 00:55:46 +0400 Subject: [PATCH] better readme --- README.md | 43 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 8352fa9..192d6cc 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,32 @@ -# Lyng: scripting lang for kotlin multiplatform +# Lyng: modern scripting for kotlin multiplatform -in the form of multiplatform library. Key benefits: +A KMP library and a standalone interpreter -- async and multithreaded (on JVM and native) out of the box -- easy and efficient kotlin integration -- dynamic types yet with good checks +- simple, compact, intuitive and elegant modern code style: -__current state of implementation and docs__: +``` +class Point(x,y) { + fun dist() { sqrt(x*x + y*y) } +} +Point(3,4).dist() //< 5 +``` -- [introduction and tutorial](docs/tutorial.md) +- extremely simple Kotlin integration on any platform +- 100% secure: no access to any API you didn't explicitly provide +- 100% coroutines! Every function/script is a coroutine, it does not block the thread, no async/await/suspend keyword garbage: + +``` + delay(1.5) // coroutine is delayed for 1.5s, thread is not blocked! +``` +and it is multithreaded on platforms supporting it (automatically, no code changes required, just +`launch` more coroutines and they will be executed concurrently if possible)/ + +- functional style and OOP together, multiple inheritance, implementing interfaces for existing classes, writing extensions. +- Any unicode letters can be used as identifiers: `assert( sin(π/2) == 1 )`. + + ## Resources: + +- [introduction and tutorial](docs/tutorial.md) - start here please - [Samples directory](docs/samples) ## Integration in Kotlin multiplatform @@ -31,6 +49,7 @@ Script is executed over some `Context`. Create instance of the context, add your specific vars and functions to it, an call over it: ```kotlin +// simple function val context = Context().apply { addFn("addArgs") { var sum = 0.0 @@ -38,8 +57,16 @@ val context = Context().apply { ObjReal(sum) } addConst("LIGHT_SPEED", ObjReal(299_792_458.0)) + + // callback back to kotlin to some suspend fn, for example:: + // suspend fun doSomeWork(text: String): Int + addFn("doSomeWork") { + // this _is_ a suspend lambda, we can call suspend function, + // and it won't consume the thread: + doSomeWork(args[0].toString()).toObj() + } } - +// adding constant: context.eval("addArgs(1,2,3)") // <- 6 ``` Note that the context stores all changes in it so you can make calls on a single context to preserve state between calls.