top | item 7455727

Duktape: an embeddable JavaScript engine

109 points| brassybadger | 12 years ago |duktape.org | reply

43 comments

order
[+] chubot|12 years ago|reply
This looks really cool. I always wanted a small embeddable JS engine with a C interface. And it looks like you modelled the C API after the Lua C API? That is what I wanted as well.

Here are some related projects I saved links to. I think there were a few others.

http://code.google.com/p/tiny-js/

http://adaptive-enterprises.com/~d/software/see/

http://sourceforge.net/projects/njs/

v8 is an obvious open source implementation, because it's packaged separately (and used in node.js), but its API is C++ and relatively complex. For a lot of applications, it's overkill.

[+] saurik|12 years ago|reply
JavaScriptCore (the engine from WebKit) also has a very simple C interface (and I've seen it embedded by people as a static library without serious difficulty).
[+] deckiedan|12 years ago|reply
Awesome. This is exactly what I wanted. Hopefully now I can make a standalone statically linked version jslint, lessjs, etc, so I can use them as part of my workflow without needing the whole flipping Node stack installed...
[+] cmicali|12 years ago|reply
This would be amazing.. svgo and less are the only two things between us and a node-free environment - would love to not have to install/deal with npm.
[+] PythonicAlpha|12 years ago|reply
The idea is good, I remember that other projects like Avidemux integrate QtScript or Spidermonkey for scripting.

Has anybody experience, how the integration overhead is? Looks as this could be integrated very simply. The problem is, that it is in alpha stage and how stable and complete is it currently?

[+] brassybadger|12 years ago|reply
Integration is very easy (check out the examples in their git repo), but this is still alpha quality software - there are known limitations, e.g. the one I ran into is that a large JS expression involving function calls might make Duktape run out of bytecode registers.
[+] bichiliad|12 years ago|reply
What is the advantage of something like this? (Not trying to be cynical, I just have no idea).
[+] Pitarou|12 years ago|reply
Developer Productivity

C/C++ is great for low-level and performance sensitive code, but at the cost of ease of use and a potentially slow compile-test-debug cycle. For instance, in a game engine, the Physics and graphics rendering are usually done in C++. But for the rest, you get more bang-for-your-buck with a higher-level language.

Mindshare

Other high-level languages can do the same thing. In fact, Lua and Guile were designed for this exact purpose. But Javascript works well and Javascript programmers are much easier to find. And if, say, you want your users to start writing plug-ins for your application, you'll have more success with a language they're more likely to know.

Performance

Thanks to the great Javascript JIT compilers, you'll probably take a smaller performance hit than with other high-level languages you might choose.

[+] jffry|12 years ago|reply
My first thought is that this could be used much like Lua for allowing customized script extensions to C++ programs.
[+] skrebbel|12 years ago|reply
Is size the main selling point? 4 years ago or so, I integrated SpiderMonkey into a C++ program with relative ease; it has an easy to understand C API and no dependencies.
[+] brassybadger|12 years ago|reply
I'd say the combination of being small, easily embeddable and having a liberal license make it attractive.
[+] igl|12 years ago|reply
Great... If every aspect of lua wasn't better than js.
[+] Turing_Machine|12 years ago|reply
Lua is nice, no doubt about it, but it isn't better in every aspect.

Libraries count. Developer mindshare counts.

It's the same rationale as having so many modern languages that compile to Java. Java itself may not be that great, but man, there sure are a lot of useful libraries for it. Same with Javascript.

[+] angersock|12 years ago|reply
Bloody wonderful!

I'm quite pleased to see a compact and reasonable C interface for a JS engine--v8 can go eat a bag of rocks.

[+] eropple|12 years ago|reply
Agreed. I really like the engineering behind V8, but the interface is such a pain to work with. I actually switched my game from C++ to the JVM so I could use Rhino.
[+] icefox|12 years ago|reply
Why does the readme say "liberal license" when the license file is in fact "MIT license" Why hide the fact that it is under the MIT license? Why is there a folder called licenses and why does it contain an unfilled in license (Copyright (c) <year> <copyright holders>)?
[+] drgath|12 years ago|reply
MIT is considered by most to be a "liberal license", and phrasing it that way makes for better marketing than stating the exact type of license in a "Features" section.

The additional license is for another project (murmurhash2).

[+] bsilvereagle|12 years ago|reply
If this is embedded in C++ I feel like you would be manipulating objects in the JavaScript scripts. JavaScript has OOP bolted on and it is not nearly as nice as Lua or similar alternatives. Why would a developer embed a JavaScript engine compared to something already existing?
[+] yetfeo|12 years ago|reply
I wouldn't describe JavaScript's OOP as bolted on. It's just a different kind of OOP - prototype based rather than class based. You could argue that Lua is more "bolted on OOP" since there are quite a few different libraries that build OOP for it.
[+] hajile|12 years ago|reply
Qt already uses JS in the form of QtQuick with quite a bit of success. JS using a prototypal system means that it can emulate almost any other OOP trivially (while the reverse is much harder).

I prefer embedding lisp, but I realize that most developers don't know that language family (which mostly defeats the point of an embedded scripting language). JS seems to be the closest widely-known languages have come to this ideal, so I'm quite happy with the prospects of using it.

[+] PythonicAlpha|12 years ago|reply
The point is not, if a language is superior or has the better "OOP" quality. People tend to use what they know and JS is currently one of the "in" languages.

What is the benefit, if your scripting language is the price-winner from Harvard Business school or something else, but nobody knows it and wants to learn it. So many (good) languages have passed away, nearly unnoticed.

One of the big attractions of Java and JavaScript: The syntax. The C/C++ like syntax was and is just in fashion ... even when it is criticized by many. But everybody knows it and everybody (it seems) like it.

[+] rmrfrmrf|12 years ago|reply
Probably because Lua is horrible and JavaScript is awesome. Also npmjs.
[+] edwinyzh|12 years ago|reply
Sounds great! I wish there will be a DLL version for Windows, so that people can make wrappers in other languages such as Pascal, Python, etc.
[+] Doctor_Fegg|12 years ago|reply
Any benchmarks for how this typically performs against Lua?