From 698d16961276cc22b5d8dddf6aa6e466e70f4dca Mon Sep 17 00:00:00 2001 From: sergeych Date: Sun, 1 Jun 2025 00:11:48 +0400 Subject: [PATCH] more docs --- README.md | 33 +++++++++++++++++++++++++++++++++ docs/tutorial.md | 11 +++++++++++ 2 files changed, 44 insertions(+) diff --git a/README.md b/README.md index 89e0b14..5237e0a 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,39 @@ __current state of implementation and docs__: - [introduction and tutorial](docs/tutorial.md) - [math and operators](docs/math.md). +## Integration in Kotlin multiplatform + +### Add library + +TBD + +### Execute script: + +```kotlin +assertEquals("hello, world", eval(""" + "hello, " + "world" + """).toString()) +``` + +### Exchanging information + +Script is executed over some `Context`. Create instance of the context, +add your specific vars and functions to it, an call over it: + +```kotlin +val context = Context().apply { + addFn("addArgs") { + var sum = 0.0 + for( a in args) sum += a.toDouble() + ObjReal(sum) + } + addConst("LIGHT_SPEED", ObjReal(299_792_458.0)) +} + +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. + ## Why? Designed to add scripting to kotlin multiplatform application in easy and efficient way. This is attempt to achieve what Lua is for C/++. diff --git a/docs/tutorial.md b/docs/tutorial.md index 98bc092..50efc05 100644 --- a/docs/tutorial.md +++ b/docs/tutorial.md @@ -603,6 +603,17 @@ Ranges could be inside other ranges: assert( (2..3) in (1..10) ) >>> void +There are character ranges too: + + 'd' in 'a'..'e' + >>> true + +and you can use ranges in for-loops: + + for( x in 'a' ..< 'c' ) println(x) + >>> a + >>> b + >>> void See [Ranges](Range.md) for detailed documentation on it.