Skip to content

Commit

Permalink
ext/MiniScript: updated MiniScript to latest version
Browse files Browse the repository at this point in the history
  • Loading branch information
andreasdr committed Jan 18, 2024
1 parent f91b5b6 commit 2f32bed
Show file tree
Hide file tree
Showing 44 changed files with 706 additions and 643 deletions.
134 changes: 66 additions & 68 deletions README-MiniScript.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ Also note the focus on easy integration into other products and easy customizabi
- very small implementation of a scripting language
- runs on every CPU, OS, ... due to its simplicity, so its highly portable
- can be easily extended by writing state machine machine states and script methods in C++ as well as custom data types
- built-in data types: null, boolean, integer, float, string, byte array, array, map, set, vector2, vector3, vector4, quaternion, matrix3x3, matrix4x4, transform
- built-in data types: null, boolean, integer, float, string, byte array, array, map, set, vector2, vector3, vector4, quaternion, matrix3x3, matrix4x4, transform, ...
- when calling script C++ methods or script functions with arguments it does optionally use references or value by copy
- supports functions and recursion
- supports inline/lamda functions
- supports operators by operator to method mapping by a preprocessor run
- supports loops and conditions
- supports programming with classes style programming
- for built-in datatypes: string, byte array, array, map, set, vector2, vector3, vector4, quaternion, matrix3x3, matrix4x4, transform
- for built-in datatypes: string, byte array, array, map, set, vector2, vector3, vector4, quaternion, matrix3x3, matrix4x4, transform, ...
- for script classes/objects
- for custom data types
- supports event like programming
Expand All @@ -48,7 +48,7 @@ See an example of if and end:
...
$i = 1
if ($i == 1)
console.log("i -> 1")
console.printLine("i -> 1")
end
...
```
Expand All @@ -58,9 +58,9 @@ See an example of if and else and end:
...
$i = 2
if ($i == 1)
console.log("i -> 1")
console.printLine("i -> 1")
else
console.log("else: ", $i)
console.printLine("else: ", $i)
end
...
```
Expand All @@ -70,17 +70,17 @@ See an example of if, elseif, else and end:
```
...
$i = 2
console.log($i, ":")
console.printLine($i, ":")
if ($i == 0)
console.log("i -> 0")
console.printLine("i -> 0")
elseif ($i == 1)
console.log("i -> 1")
console.printLine("i -> 1")
elseif ($i == 2)
console.log("i -> 2")
console.printLine("i -> 2")
elseif ($i == 3)
console.log("i -> 3")
console.printLine("i -> 3")
else
console.log("else: ", $i)
console.printLine("else: ", $i)
end
...
```
Expand All @@ -94,7 +94,7 @@ forTime takes a single argument "time" - it repeats the loop until "time" in mil
...
$i = 0
forTime(2000)
console.log($i, ": Hello World")
console.printLine($i, ": Hello World")
script.wait(500)
++$i
end
Expand All @@ -106,7 +106,7 @@ forCondition takes a single boolean value as argument. The loop will be executed
...
$i = 0
forCondition($i < 5)
console.log("$ = ", $i)
console.printLine("$ = ", $i)
++$i
end
...
Expand All @@ -121,14 +121,14 @@ Argument variables, parsed in function declarations are populated in function co
...
# function of recursive factorial computation
function: factorial($value)
console.log("factorial(): $value = " + $value)
console.printLine("factorial(): $value = " + $value)
if ($value == 0)
return(1)
end
return($value * factorial($value - 1))
end
...
console.log("factorial(5) = " + factorial(5))
console.printLine("factorial(5) = " + factorial(5))
...
```

Expand All @@ -149,9 +149,9 @@ end
$a = "0"
$b = "1"
$c = "2"
console.log("assignTest(): pre: $a = " + $a + ", $b = " + $b + ", $c = " + $c)
console.printLine("assignTest(): pre: $a = " + $a + ", $b = " + $b + ", $c = " + $c)
assignTest($a, $b, $c)
console.log("assignTest(): post: $a = " + $a + ", $b = " + $b + ", $c = " + $c)
console.printLine("assignTest(): post: $a = " + $a + ", $b = " + $b + ", $c = " + $c)
...
```

Expand All @@ -162,14 +162,14 @@ So to be sure to use a global variable in function scope, just use the "$$." or
...
# function to test global variable access
function: globalVariableTest()
console.log("globalVariableTest(): $GLOBAL.globalTest = " + $GLOBAL.globalTest)
console.printLine("globalVariableTest(): $GLOBAL.globalTest = " + $GLOBAL.globalTest)
$GLOBAL.globalTest = "Been there, done that, got the t-shirt"
end
...
$globalTest = "Global Test Variable"
console.log("globalVariableTest(): pre: $globalTest = " + $globalTest)
console.printLine("globalVariableTest(): pre: $globalTest = " + $globalTest)
globalVariableTest()
console.log("globalVariableTest(): post: $globalTest = " + $globalTest)
console.printLine("globalVariableTest(): post: $globalTest = " + $globalTest)
...
```

Expand Down Expand Up @@ -357,14 +357,14 @@ For more math related methods just look into "6. Methods" section.
A byte array is a sequence of byte values. Bytes are the smallest atomic values a CPU does handle.
Using bit math you can also manipulate byte values at bit scope.

To write and read from byte array you can use the read*() and write() methods.
To write and read from byte array you can use the read*() and write*() methods.

Available data types are
- bool (true or false)
- int8 (-128 .. 127)
- int16 (-32768 .. 32767)
- int32 (-2147483646 .. 2147483647)
- int64 (-9,223,372,036,854,775,806 .. -9,223,372,036,854,775,807)
- int32 (-2147483647 .. 2147483646)
- int64 (-9,223,372,036,854,775,807 .. -9,223,372,036,854,775,806)
- float (floating point number)
- small string (string with maximum size of 255 bytes)
- medium string (string with maximum size of 65535 bytes)
Expand Down Expand Up @@ -406,15 +406,15 @@ Reading values using ByteArray::read*():
```
...
$byteArray->setReadPosition(0)
console.log($byteArray->readBool())
console.log($byteArray->readInt8())
console.log($byteArray->readInt16())
console.log($byteArray->readInt32())
console.log($byteArray->readInt64())
console.log($byteArray->readFloat())
console.log($byteArray->readSmallString())
console.log($byteArray->readMediumString())
console.log($byteArray->readLargeString())
console.printLine($byteArray->readBool())
console.printLine($byteArray->readInt8())
console.printLine($byteArray->readInt16())
console.printLine($byteArray->readInt32())
console.printLine($byteArray->readInt64())
console.printLine($byteArray->readFloat())
console.printLine($byteArray->readSmallString())
console.printLine($byteArray->readMediumString())
console.printLine($byteArray->readLargeString())
...
```

Expand All @@ -423,7 +423,7 @@ Reading byte arrays using ByteArray::length() and ByteArray::readInt8():
...
$byteArray->setReadPosition(0)
forCondition($byteArray->getReadPosition() < $byteArray->length())
console.log($i + ": " + $byteArray->readInt8($i))
console.printLine($i + ": " + $byteArray->readInt8($i))
end
...
```
Expand Down Expand Up @@ -497,7 +497,7 @@ Iterating arrays using Array::length() and Array::get():
...
$i = 0
forCondition($i < $array->length())
console.log($i + ": " + $array->get($i))
console.printLine($i + ": " + $array->get($i))
++$i
end
...
Expand All @@ -508,7 +508,7 @@ Iterating arrays using Array::length() and [] operator:
...
$i = 0
forCondition($i < $array->length())
console.log($i + ": " + $array[$i])
console.printLine($i + ": " + $array[$i])
++$i
end
...
Expand All @@ -517,7 +517,7 @@ Iterating arrays using Array::length() and [] operator:
Iterating arrays using Array::forEach() and a lamda function
```
...
$array->forEach(($value) -> { console.log($value) })
$array->forEach(($value) -> { console.printLine($value) })
...
```

Expand Down Expand Up @@ -559,20 +559,20 @@ Removing from map using Map::remove() and a given key:
Reading values from map using Map::get() and given keys:
```
...
console.log("map value for test1 key using map.get(): ", $map->get("test1"))
console.log("map value for test2 key using map.get(): ", $map->get("test2"))
console.log("map value for test3 key using map.get(): ", $map->get("test3"))
console.log("map value for test4 key using map.get(): ", $map->get("test4"))
console.printLine("map value for test1 key using map.get(): ", $map->get("test1"))
console.printLine("map value for test2 key using map.get(): ", $map->get("test2"))
console.printLine("map value for test3 key using map.get(): ", $map->get("test3"))
console.printLine("map value for test4 key using map.get(): ", $map->get("test4"))
...
```

Reading values from map using dot operator:
```
...
console.log("map value for test1 using map dot operator: ", $map.test1)
console.log("map value for test2 using map dot operator: ", $map.test2)
console.log("map value for test3 using map dot operator: ", $map.test3)
console.log("map value for test4 using map dot operator: ", $map.test4)
console.printLine("map value for test1 using map dot operator: ", $map.test1)
console.printLine("map value for test2 using map dot operator: ", $map.test2)
console.printLine("map value for test3 using map dot operator: ", $map.test3)
console.printLine("map value for test4 using map dot operator: ", $map.test4)
...
```

Expand All @@ -587,14 +587,14 @@ Setting key, value pairs to map using dot operator:
Reading map keys:
```
...
console.log("map keys: ", $map->getKeys())
console.printLine("map keys: ", $map->getKeys())
...
```

Reading map values:
```
...
console.log("map values: ", $map->getValues())
console.printLine("map values: ", $map->getValues())
...
```

Expand All @@ -604,7 +604,7 @@ Reading all keys and values from map using Map::get() and Map::getKeys()
$mapKeys = $map->getKeys()
$i = 0
forCondition($i < $mapKeys->length())
console.log($mapKeys[$i] + " = " + $map->get($mapKeys[$i]))
console.printLine($mapKeys[$i] + " = " + $map->get($mapKeys[$i]))
++$i
end
...
Expand All @@ -613,7 +613,7 @@ Reading all keys and values from map using Map::get() and Map::getKeys()
Iterating maps using Map::forEach() and a lamda function
```
...
$map->forEach(($key, $value) -> { console.log($key + " = " + $value) })
$map->forEach(($key, $value) -> { console.printLine($key + " = " + $value) })
...
```

Expand Down Expand Up @@ -654,23 +654,23 @@ Removing keys from set using Set::remove():
Checking if keys exist in set using Set::has() and given keys:
```
...
console.log("set does have test1 key using set.has(): ", $set->has("test1"))
console.log("set does have test2 key using set.has(): ", $set->has("test2"))
console.log("set does have test3 key using set.has(): ", $set->has("test3"))
console.log("set does have test4 key using set.has(): ", $set->has("test4"))
console.log("set does have test5 key using set.has(): ", $set->has("test5"))
console.printLine("set does have test1 key using set.has(): ", $set->has("test1"))
console.printLine("set does have test2 key using set.has(): ", $set->has("test2"))
console.printLine("set does have test3 key using set.has(): ", $set->has("test3"))
console.printLine("set does have test4 key using set.has(): ", $set->has("test4"))
console.printLine("set does have test5 key using set.has(): ", $set->has("test5"))
...
```


Checking if keys exist in set using dot operator and given keys:
```
...
console.log("set key for test1 using set dot operator: ", $set.test1)
console.log("set key for test2 using set dot operator: ", $set.test2)
console.log("set key for test3 using set dot operator: ", $set.test3)
console.log("set key for test4 using set dot operator: ", $set.test4)
console.log("set key for test5 using set dot operator: ", $set.test5)
console.printLine("set key for test1 using set dot operator: ", $set.test1)
console.printLine("set key for test2 using set dot operator: ", $set.test2)
console.printLine("set key for test3 using set dot operator: ", $set.test3)
console.printLine("set key for test4 using set dot operator: ", $set.test4)
console.printLine("set key for test5 using set dot operator: ", $set.test5)
...
```

Expand All @@ -687,14 +687,14 @@ Inserting/Removing set keys by using dot operator and boolean assignment:
Reading all keys as array from set:
```
...
console.log("set keys: ", $set->getKeys())
console.printLine("set keys: ", $set->getKeys())
...
```

Iterating sets using Set::forEach() and a lamda function
```
...
$set->forEach(($key) -> { console.log($key) })
$set->forEach(($key) -> { console.printLine($key) })
...
```

Expand Down Expand Up @@ -728,7 +728,7 @@ Please see a example below.
},
showMeWhatYouGot: () ->
{
console.log(
console.printLine(
"This amazing car has ",
$this.wheelCount,
" wheels, is colored ",
Expand Down Expand Up @@ -760,7 +760,7 @@ Please see a example below.
$color = null
$horsePower = null
$car->getProperties($wheelCount, $color, $horsePower)
console.log(
console.printLine(
"Car properties, wheels: ",
$wheelCount,
", color: ",
Expand All @@ -787,7 +787,7 @@ function: showMeWhatYouGot($this)
if ($this.convertible == true)
$carType = "convertible"
end
console.log(
console.printLine(
"This amazing ",
$carType,
" has ",
Expand Down Expand Up @@ -1362,18 +1362,16 @@ end
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Pretty print variable to console |
| <sub>console.dump($value: Mixed): Null</sub> |
| Print to console |
| <sub>console.log(...): Null</sub> |
| Print to console without trainling new line |
| <sub>console.print(...): Null</sub> |
| Print to console with a trailing new line |
| <sub>console.println(...): Null</sub> |
| <sub>console.printLine(...): Null</sub> |
| Read all input into string value |
| <sub>console.readAll(): String</sub> |
| Read all input into array of strings |
| <sub>console.readAllAsArray(): Array</sub> |
| Read a line from input |
| <sub>console.readln(): String</sub> |
| <sub>console.readLine(): String</sub> |

## 7.4. Error console/stream methods

Expand All @@ -1382,7 +1380,7 @@ end
| Print to error console/stream without trainling new line |
| <sub>console.error.print(...): Null</sub> |
| Print to error console/stream with a trailing new line |
| <sub>console.error.println(...): Null</sub> |
| <sub>console.error.printLine(...): Null</sub> |

## 7.5. Cryptography Base64 methods

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ void ApplicationMethods::registerMethods(MiniScript* miniScript) {
if (MiniScript::getStringValue(arguments, 0, command, false) == true) {
returnValue.setValue(ApplicationMethods::execute(command));
} else {
_Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName()));
_Console::printLine(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName()));
miniScript->startErrorScript();
}
}
Expand Down Expand Up @@ -156,7 +156,7 @@ void ApplicationMethods::registerMethods(MiniScript* miniScript) {
miniScript->stopScriptExecution();
miniScript->stopRunning();
} else {
_Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName()));
_Console::printLine(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName()));
miniScript->startErrorScript();
}
}
Expand Down
Loading

0 comments on commit 2f32bed

Please sign in to comment.