mevento 3.0.3 → 3.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +59 -0
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# Mevento
|
|
2
|
+
|
|
3
|
+
Mevento is a tiny VM one single file that handles `MEvento code` executions inside JS engine. `MEvento` is simple programming language that allows developers exposing an app host function, that way they have the ability to dynamically execute simple script that call host function.
|
|
4
|
+
|
|
5
|
+
The VM uses a AST Walker to execute MEvento script, so of course the performace is not its concern a lot.
|
|
6
|
+
|
|
7
|
+
## MEvento code syntax
|
|
8
|
+
Syntaxically MEvento is a c-like language, but very limited: no function declaration, no class, just assignation, function call and conditional check.
|
|
9
|
+
|
|
10
|
+
```js
|
|
11
|
+
a = 12
|
|
12
|
+
a = 23
|
|
13
|
+
b = functon1()
|
|
14
|
+
c = function2()
|
|
15
|
+
d = a + b
|
|
16
|
+
if(a == b) {
|
|
17
|
+
log('a = b')
|
|
18
|
+
} else {
|
|
19
|
+
log("a != b")
|
|
20
|
+
}
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## How to use
|
|
24
|
+
The host application can expose functions through Mevento VM that way:
|
|
25
|
+
```ts
|
|
26
|
+
import {MEvento} from 'mevento';
|
|
27
|
+
MEvento.register('log', (args) => console.log); // exposes console.log through MEvento as log function
|
|
28
|
+
MEvento.register('cos2', (args) => Math.cos);
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Let's assume you want to execute a `MEvento code`:
|
|
32
|
+
|
|
33
|
+
```ts
|
|
34
|
+
import {MEvento} from 'mevento';
|
|
35
|
+
|
|
36
|
+
const mevento = MEvento.newInstance();
|
|
37
|
+
|
|
38
|
+
mevento.execute(`log("molo")`)
|
|
39
|
+
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
`MEvento` instance execution is syncrhrone, that's to say, if you wan to consume `async` function exposed through Mevento, you nee to use `MEventoAsync` instead.
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
```ts
|
|
46
|
+
import {MEvento} from 'mevento';
|
|
47
|
+
|
|
48
|
+
MEvento.register('async', async (args) => await asyncF(args[0]));
|
|
49
|
+
const mevento = MEventoAsync.newInstance();
|
|
50
|
+
|
|
51
|
+
await mevento.execute(`async("molo")`)
|
|
52
|
+
|
|
53
|
+
```
|
|
54
|
+
`execute` method on `MEventoAsync` instance return a `Promise`.
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
## Notes
|
|
58
|
+
MEvento does not have scope variables, all variables are visible everywhere.
|
|
59
|
+
|