more docs
This commit is contained in:
1 parent
86d59abfbc
commit
698d169612
2 files changed
+44
No files matched your search
@@ -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/++.
|
||||
|
||||
Reference in new issue
Block a user