Closed mikekotikov closed 3 years ago
To include a library in the interpreter, you'll need append the raw (must be ES5) JS for it. (You could use https://www.npmjs.com/package/raw-loader for that.)
import rawLibraryScript from '!!raw-loader!../path/to/my/library.js'
const interpreter = new Interpreter('')
interpreter.appendCode(rawLibraryScript )
interpreter.run()
That said, lodash may need some things that the interpreter doesn't have out of the box.
@Webifi thanks! Found another solution that worked: casted lodash to object.
Hi. Came upon a problem with using lodash within the interpreter. Here is a sample of what I'm trying to do:
And I'm getting this error:
TypeError: undefined is not a function at Interpreter../original-repo/interpreter.js.Interpreter.unwind (/mnt/c/Users/mikhail.kotsikau/Projects/test/js-interpreter-lodash/node_modules/js-interpreter/lib/js-interpreter.js:4839:17) at Interpreter../original-repo/interpreter.js.Interpreter.throwException (/mnt/c/Users/mikhail.kotsikau/Projects/test/js-interpreter-lodash/node_modules/js-interpreter/lib/js-interpreter.js:4771:8) at Interpreter../original-repo/interpreter.js.Interpreter.stepCallExpression (/mnt/c/Users/mikhail.kotsikau/Projects/test/js-interpreter-lodash/node_modules/js-interpreter/lib/js-interpreter.js:5270:12) at Interpreter../original-repo/interpreter.js.Interpreter.step (/mnt/c/Users/mikhail.kotsikau/Projects/test/js-interpreter-lodash/node_modules/js-interpreter/lib/js-interpreter.js:2362:48) at Interpreter../original-repo/interpreter.js.Interpreter.run (/mnt/c/Users/mikhail.kotsikau/Projects/test/js-interpreter-lodash/node_modules/js-interpreter/lib/js-interpreter.js:2392:32) at Object.<anonymous> (/mnt/c/Users/mikhail.kotsikau/Projects/test/js-interpreter-lodash/app.js:18:13) at Module._compile (internal/modules/cjs/loader.js:1138:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10) at Module.load (internal/modules/cjs/loader.js:986:32) at Function.Module._load (internal/modules/cjs/loader.js:879:14)
I also tried calling
createNativeFunction
on lodash or assigning it to scope usingsetValueToScope
, but still got errors. Am I doing something wrong? If not, is there some workaround for such case?Thanks in advance!