Hacker News new | ask | show | jobs
by bsilvereagle 4474 days ago
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?
4 comments

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.
That would be a silly argument. Lua's metatables are strictly more expressive than js's prototypes, and few libraries assume the presence of any sort of OO.
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.

Do you happen to know an embeddable Lisp that can easily bind to C++ objects (rather like AngelScript or luabind)? I too would mostly rather a Lisp, but doing all the plumbing sucks.
If Lua's semantics are acceptable, you can make a loader that runs your Lisp in Lua. This is probably less effort than it sounds like. Moonscript is a decent example of a mostly expression-oriented language as a Lua loader, so it should be simple to make it read a Lisp instead.
Interesting approach, thank you. I don't much care for Lua (either as a language or as an API, especially when dealing with C++), but this is a pretty neat concept to think about.
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.

Probably because Lua is horrible and JavaScript is awesome. Also npmjs.
After my initial fit of laughter, I am now curious which things JavaScript does better. Please enlighten me.