mevento
v3.0.4
Published
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 scrip
Downloads
97
Readme
Mevento
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.
The VM uses a AST Walker to execute MEvento script, so of course the performace is not its concern a lot.
MEvento code syntax
Syntaxically MEvento is a c-like language, but very limited: no function declaration, no class, just assignation, function call and conditional check.
a = 12
a = 23
b = functon1()
c = function2()
d = a + b
if(a == b) {
log('a = b')
} else {
log("a != b")
}
How to use
The host application can expose functions through Mevento VM that way:
import {MEvento} from 'mevento';
MEvento.register('log', (args) => console.log); // exposes console.log through MEvento as log function
MEvento.register('cos2', (args) => Math.cos);
Let's assume you want to execute a MEvento code
:
import {MEvento} from 'mevento';
const mevento = MEvento.newInstance();
mevento.execute(`log("molo")`)
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.
import {MEvento} from 'mevento';
MEvento.register('async', async (args) => await asyncF(args[0]));
const mevento = MEventoAsync.newInstance();
await mevento.execute(`async("molo")`)
execute
method on MEventoAsync
instance return a Promise
.
Notes
MEvento does not have scope variables, all variables are visible everywhere.