SpiderMonkey vs JavaScriptCore vs?
Asked Answered
D

3

7

I have a C++ desktop application (written in wxWidgets) and I want to add support for some scripting language.

Scripting would mostly be used for run-time conversions of strings, numbers and dates by user supplied JavaScript code.

I'd like to use JavaScript because it is widely used and everyone is familiar with the syntax.

Googling around, it seems I have two options:

  • SpiderMonkey from Mozilla
  • JavaScriptCore from WebKit

Has anyone tried those? Which one would be easier to set up? Do you know of some other implementation that is better for my needs?

BTW, I target Windows and Linux platforms.

Diazonium answered 21/5, 2009 at 22:24 Comment(0)
A
13

There is also Google's V8 JavaScript engine, builds nicely on Linux, embedding API seems quite straightforward too: (Compared to SpiderMonkey's, never looked at the JavaScriptCore API) http://code.google.com/apis/v8/get_started.html

Ataghan answered 30/7, 2009 at 6:4 Comment(0)
E
6

Of course, you could also use Lua, which not only is designed specifically for this, it's vastly faster than any JS.

Also, it's has well-designed semantics, a very minimal core, simple C API, great portability, a very mature JIT, the most helpful online community I've seen, etc...

Erotomania answered 21/5, 2009 at 22:50 Comment(7)
I did consider Lua, but I would like to save users of my application from learning a new language. The other potential problem is lack of functions to deal with date/time. AFAICT, you can only get the system time, and that's all. However, my application needs to be able to parse string input as date, and then do stuff like "add 3 days" or "find difference in days between 2 dates" etc.Aplite
regardless of which language you embed into your app, you have to expose some special API. adding some date managing capabilities can be done in less than 100 lines of Lua. The 'no new language' is a real issue, OTOH.Erotomania
"vastly faster than any js"? [citation needed]! Link please.Selfforgetful
@Sean McMillan, unfortunately, good benchmarks are few and far between. Also, see the date: JS has evolved a lot in the last couple of years. Still, Lua hasn't stayed still, and LuaJIT 2.0 has already surpassed Java for many high-performance tasks, in some (real) cases it's even better than most C compilers.Erotomania
Actually, Lua isn't always faster. I believe that google v8 is much faster than lua.Melson
V8 is usually somewhat faster than plain Lua; but nowhere near LuaJIT2Erotomania
LuaJIT2 beats V8 at about 4x. LuaJIT2 is almost near C level for most things.Sabol
T
3

JavaScriptCore has a stable C API (and ABI), and has been available (and used as) a standard system framework on macos.

[edit: oh, and it works on linux and windows as a standalone library, although i believe only debian distributes it as such]

Transilient answered 21/5, 2009 at 22:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.