9 ms·
Duktape: an embeddable JavaScript engine
- dottrap 13y agoVery interesting. How large is the binary size?
- userbinator 13y agoThe source is around 60kLOC and 2MB, so it's somewhere between the big ones like V8 and the smaller JS interpreters I know of: http://code.google.com/p/tiny-js/ http://code.google.com/p/tiny-js/ (~2kLOC) http://code.google.com/p/quad-wheel/ http://code.google.com/p/quad-wheel/
- bichiliad 13y agoWhat is the advantage of something like this? (Not trying to be cynical, I just have no idea).
- jffry 13y agoMy first thought is that this could be used much like Lua for allowing customized script extensions to C++ programs.
- Pitarou 13y agoDeveloper 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.
- swah 13y agohttp://c2.com/cgi/wiki?AlternateHardAndSoftLayers http://c2.com/cgi/wiki?AlternateHardAndSoftLayers
- bsilvereagle 13y agoIf 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?
- rmrfrmrf 13y agoProbably because Lua is horrible and JavaScript is awesome. Also npmjs.
- anonymoushn 13y agoAfter my initial fit of laughter, I am now curious which things JavaScript does better. Please enlighten me.
- PythonicAlpha 13y agoThe 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.
- hajile 13y agoQt 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.
- 13y ago
- chubot 13y agoThis 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://code.google.com/p/tiny-js/ http://adaptive-enterprises.com/~d/software/see/ http://adaptive-enterprises.com/~d/software/see/ http://sourceforge.net/projects/njs/ 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 13y agoJavaScriptCore (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).
- yoklov 13y agoIt's LGPL though, which is too restrictive for some projects (especially as a static library).
- saurik 13y agoFWIW, the only times I've seen it as a static library (and the only real place you need a static library) is on iOS (where it was actually extra-dubious and I'm surprised more people didn't point out the problems; specifically this was as part of one of those JavaScript app frameworks like Titanium, although I don't quite remember if it was specifically Titanium), and JavaScriptCore is now provided on the system by Apple as a public framework as of iOS 7. On any other platform you should have no trouble shipping it as a dynamically-linked library due to its simple C API.
- notjosh 13y agoIt's also got a really expressive and transparent Objective-C interface, if you happen to be writing iOS/OS X apps. There's a nice overview here: http://blog.bignerdranch.com/3784-javascriptcore-and-ios-7/ http://blog.bignerdranch.com/3784-javascriptcore-and-ios-7/
- icefox 13y agoWhy 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 13y agoMIT 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).
- PythonicAlpha 13y agoThe 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 13y agoIntegration 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.
- angersock 13y agoBloody 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 13y agoAgreed. 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.
- _pmf_ 13y ago> I actually switched my game from C++ to the JVM so I could use Rhino. Would you mind elaborating a bit what makes v8 tedious to work with?
- angersock 13y agohttps://developers.google.com/v8/embed https://developers.google.com/v8/embed EDIT: V8 is quite powerful, don't get me wrong. But, it requires a bit more knowledge of C++ to use and use well, and sometimes that can be a bit much. Also, if you're exporting functionality via a static library, you really don't always want to use anything other than vanilla C.
- igl 13y agoGreat... If every aspect of lua wasn't better than js.
- Turing_Machine 13y agoLua 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.
- sitkack 13y agohttp://www.reddit.com/r/programming/comments/1uv5n0/duktape_an_embeddable_javascript_engine/ http://www.reddit.com/r/programming/comments/1uv5n0/duktape_...
- deckiedan 13y agoAwesome. 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 13y agoThis 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.
- PaulFreund 13y agoIt always amazes me how often topics I currently work on come up here. I am currently thinking about using http://www.chaiscript.com/ http://www.chaiscript.com/
- Doctor_Fegg 13y agoAny benchmarks for how this typically performs against Lua?
- skrebbel 13y agoIs 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 13y agoI'd say the combination of being small, easily embeddable and having a liberal license make it attractive.
- skrebbel 13y agoSpiderMonkey is easily embeddable like I said. The Mozilla Public License is less liberal than BSD/MIT, but for most practical purposes it's the same. It's not tiny though (for an underbelly feeling, I found an old binary Windows build online of about 800kb). Looking at the current SpiderMonkey docs, things look like they've only improved. Back in the day, I just took SpiderMonkey from the "js" subdirectory of the Firefox repo. They split it off and documented build steps since then. I'm not saying there's no space for contenders here, but don't underestimate the quality of what's out there already. SpiderMonkey really is remarkably easy to interface with.
- brassybadger 13y agoAfter a quick glance it also seems that newer versions of SpiderMonkey only offer a C++ API, so you can't embed it anymore into C apps without some glue code. I checked out jsapi.h in SpiderMonkey24 - maybe some trick is needed to use SM from C?
- pcwalton 13y agoNew versions of SpiderMonkey only expose a C++ API (because of exact rooting), but we'll need to fix that at some point as part of Servo since this is a hazard for Rust. Currently we use an old version of SpiderMonkey for this reason.
- NAFV_P 13y agoIs the name "Duktape" a reference to Perl [0]? [0] http://www.salon.com/1998/10/13/feature_269/ http://www.salon.com/1998/10/13/feature_269/
- edwinyzh 13y agoSounds 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.