2022-08-17 14:23:51 +03:00
|
|
|
# Cli
|
|
|
|
|
|
|
|
`on file.onla` to run file.onla
|
|
|
|
`on file.onla --compress -o compressed.conla` to compress file.onla to messagePack format
|
|
|
|
`on file.onla --convert json -o file.json` to compress file.onla to json (supported formats: json, json5, yaml)
|
|
|
|
|
2022-08-04 19:05:56 +03:00
|
|
|
# How to
|
|
|
|
|
|
|
|
`All posibilities in example.json5`
|
|
|
|
|
2022-08-18 17:48:02 +03:00
|
|
|
## How to import modules
|
|
|
|
|
|
|
|
```json5
|
|
|
|
[{ import: { path: "examples/assertions.onla", as: "assertions" } }]
|
|
|
|
```
|
|
|
|
|
2022-08-04 19:05:56 +03:00
|
|
|
## How to print
|
|
|
|
|
|
|
|
```json5
|
|
|
|
[
|
2022-08-06 18:24:39 +03:00
|
|
|
"Just string in array", //equally println: "Just string in array"
|
|
|
|
["array", "of", "strings"], // equally println: ["in Function"]
|
2022-08-04 19:05:56 +03:00
|
|
|
{
|
2022-08-06 18:24:39 +03:00
|
|
|
print: ["in Function"],
|
2022-08-04 19:05:56 +03:00
|
|
|
},
|
|
|
|
{
|
2022-08-06 18:24:39 +03:00
|
|
|
println: ["in Function"],
|
2022-08-04 19:05:56 +03:00
|
|
|
},
|
|
|
|
]
|
|
|
|
```
|
|
|
|
|
|
|
|
## How to calclulate values
|
|
|
|
|
|
|
|
works only with numbers (and variables with number type)
|
|
|
|
|
|
|
|
```json5
|
|
|
|
[
|
|
|
|
{ calc: [2, "*", 3] }, //only 3 arguments
|
|
|
|
{ calc: [{ var: "some_variable" }, "-", 2] }, //{var:"some_var"} this is a way to get a variable
|
|
|
|
]
|
|
|
|
```
|
|
|
|
|
|
|
|
### Supported operators
|
|
|
|
|
|
|
|
1. \+
|
|
|
|
2. \-
|
|
|
|
3. \*
|
|
|
|
4. \/
|
|
|
|
5. \%
|
|
|
|
6. \>\>
|
|
|
|
7. \<\<
|
|
|
|
8. \^
|
|
|
|
9. \&
|
|
|
|
10. \|
|
|
|
|
|
|
|
|
## How to compare values
|
|
|
|
|
|
|
|
```json5
|
|
|
|
[
|
|
|
|
{ comp: [true, "!=", false] }, //only 3 arguments
|
|
|
|
{
|
|
|
|
comp: [
|
|
|
|
{
|
|
|
|
comp: [
|
|
|
|
{ comp: [{ calc: [1, "+", 1] }, ">", 3] },
|
|
|
|
"==",
|
|
|
|
{ var: "var_with_bool_value" },
|
|
|
|
],
|
|
|
|
},
|
|
|
|
"&&",
|
|
|
|
{ comp: [{ comp: [{ calc: [1, "+", 1] }, ">", 3] }, "==", true] },
|
|
|
|
],
|
|
|
|
}, //more complex comparisons: (( 1 + 1 > 3 ) == var_with_bool_value) && (( 1 + 1 > 3 ) == true)
|
|
|
|
]
|
|
|
|
```
|
|
|
|
|
|
|
|
### Supported operators for compare
|
|
|
|
|
|
|
|
1. ==
|
|
|
|
2. !=
|
|
|
|
3. \>
|
|
|
|
4. \<
|
|
|
|
5. \>=
|
|
|
|
6. \<=
|
|
|
|
7. \&\&
|
|
|
|
8. \|\|
|
|
|
|
|
|
|
|
## How to create a variable
|
|
|
|
|
|
|
|
```json5
|
|
|
|
[
|
|
|
|
{
|
|
|
|
let: {
|
|
|
|
str: "A",
|
|
|
|
num: 2,
|
|
|
|
arr: ["Array", "in", "variable"],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
let: {
|
|
|
|
calculated: { calc: [{ var: "num" }, "*", 4] }, //result 8
|
|
|
|
},
|
|
|
|
},
|
2022-08-14 23:34:04 +03:00
|
|
|
|
|
|
|
{
|
|
|
|
let: {
|
|
|
|
referenceVar: { ref: "calculated" },
|
|
|
|
},
|
|
|
|
//creates a reference variable, when the "calculated"
|
|
|
|
// is changed, "referenceVar" will also be changed, in the
|
|
|
|
// future it will be possible to change "referenceVar"
|
|
|
|
// and the "calculated" will be changed
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
let: {
|
|
|
|
array: { arr: [{ var: "num" }, 4] }, //create calculated array result [2, 4]
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
let: {
|
|
|
|
objVar: { obj: { var: "num" } }, //create object (hashmap) variable result {var: "num"}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
let: {
|
|
|
|
wrongObjVar: { var: "num" }, //result 2
|
|
|
|
},
|
|
|
|
},
|
2022-08-04 19:05:56 +03:00
|
|
|
]
|
|
|
|
```
|
|
|
|
|
|
|
|
## How to assign variable
|
|
|
|
|
|
|
|
```json5
|
|
|
|
[
|
|
|
|
{
|
|
|
|
assign: {
|
|
|
|
calculated: { calc: [{ var: "calculated" }, "+", 1] }, // calculated = calculated + 1
|
|
|
|
},
|
|
|
|
},
|
|
|
|
]
|
|
|
|
```
|
|
|
|
|
|
|
|
## Loops
|
|
|
|
|
|
|
|
```json5
|
|
|
|
[
|
|
|
|
{
|
|
|
|
loop: [
|
|
|
|
{
|
|
|
|
if: {
|
|
|
|
condition: { comp: [{ var: "i" }, ">=", 10] }, //if i >= 10 break loop
|
|
|
|
body: ["break"],
|
|
|
|
//else: [..commands] also work
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{ assign: { i: { calc: [{ var: "i" }, "+", 1] } } }, // i += 1
|
|
|
|
{ print: ["\ri = ", { var: "i" }] },
|
|
|
|
{ sleep: 500 }, //sleep 500 ms
|
|
|
|
],
|
|
|
|
},
|
|
|
|
]
|
|
|
|
```
|
|
|
|
|
|
|
|
## Input from console
|
|
|
|
|
|
|
|
```json5
|
|
|
|
[
|
|
|
|
{
|
|
|
|
let: {
|
|
|
|
name: { input: "Your name: " },
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{ print: ["Bye, ", { var: "name" }, "!"] },
|
|
|
|
]
|
|
|
|
```
|
2022-08-08 18:50:02 +03:00
|
|
|
|
|
|
|
## Delete variable
|
|
|
|
|
|
|
|
```json5
|
|
|
|
[
|
|
|
|
{
|
|
|
|
let: {
|
|
|
|
name: { input: "Your name: " },
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{ print: ["Bye, ", { var: "name" }, "!"] },
|
|
|
|
{ delete: "name" }, //deletes variable from memory
|
|
|
|
]
|
|
|
|
```
|
2022-08-08 19:03:16 +03:00
|
|
|
|
|
|
|
## Create scope
|
|
|
|
|
|
|
|
```json5
|
|
|
|
[
|
|
|
|
{scope:[..commands]}
|
|
|
|
]
|
|
|
|
```
|
2022-08-15 18:17:22 +03:00
|
|
|
|
|
|
|
## Create functions
|
|
|
|
|
|
|
|
```json5
|
|
|
|
[
|
|
|
|
"Creating function `sum`",
|
|
|
|
{
|
|
|
|
fn: {
|
|
|
|
name: "sum",
|
|
|
|
args: ["first", "second"],
|
|
|
|
body: [
|
|
|
|
{
|
|
|
|
return: {
|
|
|
|
calc: [{ var: "sum.first" }, "+", { var: "sum.second" }],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
"fn sum(first, second){ return first+second};",
|
|
|
|
"Run function `sum`",
|
|
|
|
|
|
|
|
["sum(2, 2) = ", { sum: [2, 2] }],
|
|
|
|
]
|
|
|
|
```
|