I would like to call a javascript function from c and use the return value. In first test:
/*JSON{ "type" : "function", "name" : "ExecJS", "generate" : "jswrap_ExecJS", "params" : [ ["function","JsVar","A Function or String to be executed"] ], "return" : ["JsVar","can be used for everything"] } */ JsVar *jswrap_ExecJS(JsVar *func){ JsVar x = *jspExecuteFunction(func, 0,0,0); jsWarn("na sowas: %d\n",x); jsvUnLock(&x); jsWarn("done\n"); }
got this error, after ExecJS(function(){return 99;}); whats wrong ?
WARNING: na sowas: 99 WARNING: done =ASSERT(v->flags == JSV_UNUSED) FAILED AT src/jsvar.c:399 #1[r1,l2] Object {
#2[r1,l2] Name String [1 blocks] "\xFF" #3[r1,l2] Object { #6[r1,l2] Name String [2 blocks] "timers" #8[r2,l1] Array(0) [ ] #9[r1,l2] Name String [2 blocks] "watches" #11[r2,l1] Array(0) [ ] #13[r1,l2] Name String [1 blocks] "net" #14[r1,l2] String [1 blocks] "\x05\x00\x00\x00\x00\xFF\xFF\xFF" #15[r1,l2] Name String [2 blocks] "history" #25[r1,l1] Array(2) [ #26[r1,l2] Name Integer 0 #19[r1,l1] String [5 blocks] "console.log(\"<\",\"<<\",JSON.stringify(process.env),\">>\",\">\")" #224[r1,l2] Name Integer 1 #213[r1,l1] String [3 blocks] "ExecJS(function(){return 99;});" ] } #17[r1,l2] Name String [2 blocks] "console" #18[r1,l1] NativeFunction 0x40123264 (1) { } #28[r1,l2] Name String [1 blocks] "JSON" #27[r1,l1] NativeFunction 0x401232ac (1) { } #33[r1,l2] Name String [2 blocks] "process" #32[r1,l1] NativeFunction 0x40123210 (1) { }
} HALTING.
@JumJum started
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
I would like to call a javascript function from c and use the return value.
In first test:
got this error, after ExecJS(function(){return 99;}); whats wrong ?
WARNING: na sowas: 99
WARNING: done
=ASSERT(v->flags == JSV_UNUSED) FAILED AT src/jsvar.c:399
#1[r1,l2] Object {
}
HALTING.