I'm looking into scripting languages to embed into an application.
I've always assumed Lua was the best choice, but I've read some recent news about embedding V8 and was considering using it instead.
My question is two fold:
Does anyone with experience embedding v8 (or any javascript engine) recommend it?
How does it compare with embedding Lua?
I like that v8 has a c++ embedding API. However the Lua API is has had lots of time to be refined (newer isn't always better and all that).
Note: I'm not concerned with which language/library is better or which has better performance. I'm only asking about ease of embedding.
v8 is just ok. I tried to use it as a script interpreter for a video game some time ago with mixed results. On the one hand, it is very fast and the API is simple; but on the other hand it doesn't really do a good job of encapsulating the interpreter's state. Because the code base is littered with global variables, you are basically shit out of luck if you need to reset v8 in the middle of an application, or run it in parallel from multiple threads. These design decisions are understandable from the perspective of Chrome's one-process-per-VM model, but make it somewhat awkward to integrate into something like a game where you might want to run multiple VMs at once (for example in a game server back end), or have some way to quickly serialize/reset the state of the whole interpreter.
For these reasons, I would actually recommend you try giving Lua a second chance. As a language it tends to be much better suited for game programming tasks, plus it has a few nifty features which make game scripting way more convenient (for example, coroutines).
There was a recent post on HackerNews about the author of Nginx discussing the (non-) suitability of V8 as an embedded scripting language: http://news.ycombinator.net/item?id=2519674
Lua is definitely more geared towards general embedding purposes, while V8 probably can be made to work somehow, if you prefer the familiarity of Javascript.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With