Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ease of embedding javascript

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.

like image 274
deft_code Avatar asked Jun 13 '11 18:06

deft_code


2 Answers

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).

like image 139
Mikola Avatar answered Oct 03 '22 00:10

Mikola


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.

like image 38
Yannick Versley Avatar answered Oct 02 '22 23:10

Yannick Versley