Hello, first time poster here. I am building an audio application which has a built in scripting language. The application is built using JUCE, and I've been using JUCE's native JavascriptEngine for a while. But this is quite limited, and I need to upgrade to something more heavy duty, so I'm looking at V8. My overall design is quite well defined and stable at this point, and I'm hoping that I can integrate V8 without having to make significant changes to it. But I also know that this might be naïve, since V8 is a pretty huge library, and I only have a rough idea about how it works. I have a few specific questions, but more than this I wanted to lay out my design and ask if anyone sees any major red flags or things I might have overlooked.
I will start by giving some context about my program. I’m building an audio application which lets the user sequence events by writing code. For instance, the user might write 1. playMidi(50); 2. wait(1); 3. start(next()); This would play Midi note 50, wait for one second, and then start the next bit of code. This code looks simple, but because of the wait() command, it can’t all be executed at once. Hence, my program splits it up line by line and then executes each line at the right time. Currently, I approach the problem like this: 1. Take a string of user-inputted commands and split it into an array of strings, using \n or ; as a delimiter. 2. Parse each line of code and store its executable AST. 3. Execute each AST at the right time, accounting for wait(). 4. If the user-input commands are changed, trigger a reset, so that the text gets re-parsed. The point here is that the code doesn’t need to be parsed every time, since parsing is quite expensive. I wanted this optimization because when the software is in use, there are going to be a lot of small commands being fired quite frequently, but the commands themselves aren’t going to be changing very often. Having read the embedding tutorial, my plan is to use something like std::vector<v8::UniquePersistent<v8::Script>> to store the list of commands, to use v8::Script::Compile() to parse them, and then script->Run() to execute them. Does this seem about right? I know that there are a lot of details I haven’t worked out yet (especially with handles and garbage collection), but at this point I’m less interested in details and more interested in ways in which this might be the wrong approach. I suspect that my design works at cross purposes to V8's own JIT optimization, which is probably geared towards optimizing large sections of code. Is this something I should worry about? Finally, there are a couple of obvious questions that I should respond to before they come up. First of all, the scripting language is not expected to run on an audio or real-time thread, and I already have solutions in place for transferring information between threads. Secondly, from the example I gave, you might ask why Javascript is necessary at all, and if I should be using something less complicated than V8. I could show you examples of why Javascript and V8 are actually great choices for my project, but I don’t want to make this post more complicated than it needs to be for now. I hope all this make sense--please ask for clarification if it does not. Liam -- -- v8-dev mailing list [email protected] http://groups.google.com/group/v8-dev --- You received this message because you are subscribed to the Google Groups "v8-dev" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/v8-dev/8a8d02d9-b7fe-41f8-98c2-d4ce95656c73n%40googlegroups.com.
