Which Javascript engine would you embed in your ap

2019-01-12 18:27发布

I want to embed Javascript in a hobby game engine of mine. Now that we have the 5th generation of Javascript engines out (all blazing fast) I'm curious what engine would you choose to embed in a C++ framework (that includes actual ease of embeding it)?

Note: Just to make it clear, I'm not interested in DOM scripting or writing Javascript in a browser.

Here's a compilation of links so far and some tips from the thread

Just for the record, I love Lua and have already embedded it in game engines about 5 times at work.

However now this is a hobby project, and I think that Javascript being known by most web developers and because its ECMA, Flash and Flex developers, a game engine that uses Javascript and XML for scripting would be more user-friendly and cater to a larger user base (and one that so far has not had a chance to use their skills for games) than one with Lua (and there are plenty of those around!).

Also for the record I'll go with V8 on this one, mostly because I like it's C++ style.

10条回答
Explosion°爆炸
2楼-- · 2019-01-12 18:52

I've tried both SpiderMonkey and V8. With SpiderMonkey, I couldn't get anything to work. I couldn't even get the examples on mozilla.org to compile.

V8 worked out-of-the-box and I got some basic C++ <-> Javascript interaction going pretty quickly. There are some google lists for people using V8, and I found most of my questions answered there already.

查看更多
等我变得足够好
3楼-- · 2019-01-12 18:57

Mozilla's SpiderMonkey is fairly easy and well-documented. It's a C API, but it's straightforward to wrap it in C++. It can be compiled to be thread-safe, which is useful for games since you'd likely want to have your main logic in one thread and user interface logic in a second thread.

Google's V8 might be a good choice, since you're using C++, but I have no experience with it yet. According to the documentation (thanks to Daniel James), V8 is not thread-safe, although this may change in the future.

There's also WebKit's SquirrelFish, but I couldn't find a standalone version of that when I was looking earlier.

查看更多
ら.Afraid
4楼-- · 2019-01-12 19:00

When speaking of a scripting engine and c++ you could also consider chaiscript. It is close to ecma script (~Javascript) and very easy to embed in c++.

Seller from the webpage:

... ChaiScript, on the other hand, was designed from the ground up with integration with C++ in mind. ... ChaiScript has no meta-compiler, no library dependencies, no build system requirements and no legacy baggage of any kind. At can work seamlessly with any C++ functions you expose to it. It does not have to be told explicitly about any type, it is function centric.

With ChaiScript you can literally begin scripting your application by adding three lines of code to your program and not modifying your build steps at all.

查看更多
Summer. ? 凉城
5楼-- · 2019-01-12 19:00

You may also want to look at V8 from Google. It's pretty new, though.

查看更多
登录 后发表回答