VCVRack / VCV-Prototype

Other
130 stars 22 forks source link

What JavaScript runtime / context are available? #49

Closed giacecco closed 3 years ago

giacecco commented 3 years ago

By checking on the source code I see that Prototype uses QuickJS as its JavaScript interpreter. However, I also see that some of QuickJS' context is missing, or at least I can't get it to work, e.g. I can't do something that should be correct in QuickJS, that is:

import * as std from "std";

... because I get a strange SyntaxError: expecting '(' error.

My guess is that Prototype's developers have crippled some of the runtime and context, probably in the interest of performance / stability: is that so?

If you are curious, what I wanted to write for Prototype is a sequencer that interacted via the internet with a crowd of users, but to do that I would need to use QuickJS' std.urlGet.

Thanks for any suggestions,

G.

JerrySievert commented 3 years ago

quickjs gives two options to an embedder:

  1. run in "module mode", which enables the import directive, but removes the ability for the embedding program to access any variables or functions in the code
  2. not run in "module mode", which disables the import directive, but allows the embedding program to access variables and functions in the code

since it's a prototype hard requirement to be able to access the variables and call process(block), option two was the only viable approach. this is a decision that quickjs made in the beginning, and embedders can only choose on of these.

giacecco commented 3 years ago

Clear, thanks @JerrySievert , so there is no solution to my problem, unless I write native C++ modules? Perhaps the situation is different for the other scripting languages?

JerrySievert commented 3 years ago

You can check to see what the lua interpreter offers, but I haven’t looked into it myself (most of the interpreters were added by different people)

giacecco commented 3 years ago

I don't know Lua much but I've just tried and observed the same issue: I cannot reference the runtime object providing HTTP functionality 😕