Using espruino non-interactively

Posted on
  • Hi, I browsed the code posted on github for a while and I wonder if it's (without modifications) possible to use espruino to parse script inside string.

    Something like:
    char *script = "var temperature; ........";
    jspExecute(script); ?

    I saw that espruino also works with interrupt routines and when used interactively, it has main loop doing various stuff, but that's not necessary for me.

    If it's not possible without mods, I'd love to modify it and post it back. (But I could use some directions as the code is not that small.)

  • Use this: eval()

    Little example:
    myProg = 'print("Hello world");';
    eval(myProg);

  • Perfect, thank you :)

  • If you mean using Espruino directly from C code, you want something like:

    JsVar *v = jsvNewFromString("......");
    jsvUnLock(jspEvaluateVar(jsiGetParser(),­ lineToExecute, 0));
    jsvUnLock(v);
    

    Note that EvaluateVar returns a result as well.

    Espruino can't execute directly from char* strings (only from JsVar-based strings).

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Using espruino non-interactively

Posted by Avatar for format @format

Actions