Simon
Newcomer
How does Lua compare to other scripting languages such as JavaScript?
When would you use one over the other?
When would you use one over the other?
Thx!There are lots of similarities, but on a whole the languages are quite different. Lua is a much more simple (I would say elegant) language in many respects.
Javascript is heavily used in webpages and web MVC frameworks like angular, as well as in web services running under nodeJS. Javascript can also be found in NoSQL databases like mongo.
Lua is a small scripting language that is very good for embedding in other applications. This is exemplified by it's use in the game industry. A game can be written to use Lua extensions and users can then create additional content. Roblox, Garry's Mod, World Of Warcraft are just a few names. Lua is also found in bootloaders (FreeBSD), routers (openwrt), and cellular modems (Sierra Wireless).
Both languages can be used as general scripting languages to an extent, however, both have different focuses. NodeJs is heavily web focused. It can be extended through the npm package manager. Lua is VERY small but it can be extended through the LuaRocks Package manager.
Javascript is a better language to learn if you want to do web stuff. Period. If you're young and you want to learn to extend video games or you play Roblox, Lua is a good choice. If you want a general scripting language Lua could be a good choice, but it requires much more work to be useful compared to something like Python or Ruby. I like Ruby, but haven't done much Python. Python is by far the most popular scripting language right now for general desktop scripting.
I use Lua as a general scripting language because I think it's an elegant, fun language to write. Because the Lua language is so small, it means the author (you!) needs to provide a great deal of the logic, where other languages provide larger standard libraries. I like the smaller Lua method because my solutions are only exactly as big as they need to be (tiny), and I have much more control over how it works.
Hope that helps!
Dinsdale
Thx for the linksNot that I have done a tone of Lua/C++, but I recommend using the Sol 2 project with C++. It's a header only interface between Lua and C++. It removes the necessity to manipulate the Lua stack. Very slick.
![]()
ThePhD/sol2
Sol3 (sol2 v3.0) - a C++ <-> Lua API wrapper with advanced features and top notch performance - is here, and it's great! Documentation: - ThePhD/sol2github.com
The name is a little confusing, I always knew the project as Sol2. He's recently started calling it Sol3, or Sol2 v3. I dunno? It's fast and very slick. Docs are here: sol 3.2 — sol 3.2.3 documentation
I almost forgot about this little nugget: If you want to embed javascript, there is a project by Peter MacDonald called jsish:
JSI is a "javascript-ish" interpreter that can be embedded into a C/C++ application. He used an older version of it very effectively in a project where we worked together a few years back. I was using it as a desktop scripting engine for a short period. It's a very cool project but Peter is an "army of one". Interestingly, Peter MacDonald developed one of the first Linux distributions. He claims it's *the* first, though others disagree. Peter MacDonald (computer programmer) - Wikipedia.
Let's un-hard that for you: Part 1: Lua, Sol 3 and C++ (Oh, my!)
There have been multiple attempts to create a typed Lua. I have minimally tried Ravi - Ravi Programming Language by ravilangTo me JavaScript and Lua are near identical languages. Lua is better designed but the "better designed" mostly only comes up in weird edge situations.
To me the big advantage of JavaScript is you have access to TypeScript. TypeScript adds gradual typing to JavaScript (this means that you aren't required to type everything, but if you choose to type something, the TypeScript checker will alert you when the types you claimed get violated). I find my Lua programs often run into big problems when they get large with me getting sloppy about ad hoc structures, I'll have a variable being passed into a function and I won't be able to remember what its fields are. With TypeScript I can just click a variable in Sublime Text and it tells me its type and possible fields.
The big advantage of Lua is that you have access to LuaJIT. It is very hard to embed JavaScript into another binary. You basically have to embed most of a web browser into your application, and I'm not sure I know how to do it efficiently on locked-down platforms like iOS or a game console. There are stripped down JS embed libraries like duktape but I have yet to find one which is *either* efficient or supports ES6.
Not at all. JS is filled with so many bad design decisions that it shows all the time. Weird cases like the empty string being treated as falsey in if statements break many techniques that you can easily use in Lua, to name one example.but the "better designed" mostly only comes up in weird edge situations.
Lua has tl now, which is already looking very promising. That basically does the same thing as TypeScript but for Lua.To me the big advantage of JavaScript is you have access to TypeScript
Don't use so many ad hoc structures then. You can easily build a simple class system or use one as a library. If you properly document your classes, the only difference is that you might have to navigate the documentation manually or teach your editor where to look it up.Lua programs often run into big problems when they get large with me getting sloppy about ad hoc structures
There's also Civetweb which is effectively JSI but with lua instead, and with sqlite, lfs, xml support builtin, also embeddable. It also seems to be a one man project.I almost forgot about this little nugget: If you want to embed javascript, there is a project by Peter MacDonald called jsish:
JSI is a "javascript-ish" interpreter that can be embedded into a C/C++ application. He used an older version of it very effectively in a project where we worked together a few years back. I was using it as a desktop scripting engine for a short period. It's a very cool project but Peter is an "army of one". Interestingly, Peter MacDonald developed one of the first Linux distributions. He claims it's *the* first, though others disagree. Peter MacDonald (computer programmer) - Wikipedia.
Have you heard of quickjs? Its another small and embeddable Javascript engine that supports ES2020 which supersedes ES6(ES2015), but by no means the most efficient. Created by the same person who wrote ffmpeg, qemu and tcc. That has spurred a whole host projects downstream like txiki.js a tiny event loop JavaScript runtime in the likes of Deno, and Sciter.JS a mini web engine compared to electron.The big advantage of Lua is that you have access to LuaJIT. It is very hard to embed JavaScript into another binary. You basically have to embed most of a web browser into your application, and I'm not sure I know how to do it efficiently on locked-down platforms like iOS or a game console. There are stripped down JS embed libraries like duktape but I have yet to find one which is *either* efficient or supports ES6.