more docs
This commit is contained in:
parent
86d59abfbc
commit
698d169612
33
README.md
33
README.md
@ -7,6 +7,39 @@ __current state of implementation and docs__:
|
|||||||
- [introduction and tutorial](docs/tutorial.md)
|
- [introduction and tutorial](docs/tutorial.md)
|
||||||
- [math and operators](docs/math.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?
|
## Why?
|
||||||
|
|
||||||
Designed to add scripting to kotlin multiplatform application in easy and efficient way. This is attempt to achieve what Lua is for C/++.
|
Designed to add scripting to kotlin multiplatform application in easy and efficient way. This is attempt to achieve what Lua is for C/++.
|
||||||
|
@ -603,6 +603,17 @@ Ranges could be inside other ranges:
|
|||||||
assert( (2..3) in (1..10) )
|
assert( (2..3) in (1..10) )
|
||||||
>>> void
|
>>> 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.
|
See [Ranges](Range.md) for detailed documentation on it.
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user