4 ms·
Lua is amazing in that it is very small, portable, and easily embeddable. But aside from those three things, Lua is semantically almost identical to modern Java
by sdegutis 8y ago
Lua is amazing in that it is very small, portable, and easily embeddable. But aside from those three things, Lua is semantically almost identical to modern JavaScript.
I've embedded both and used them heavily in my various window managers, and these days I personally recommend embedding JavaScript over Lua if possible.
But when a small, portable and lightweight language is needed, there's also Sparkling[1], which is like the best ideas of JavaScript with the minimal footprint and portability of Lua.
[1]: http://h2co3.github.io/sparkling/ http://h2co3.github.io/sparkling/
- vmsp 8y agoWhat JavaScript interpreter do you use for embedding? I know of MuJS [1] but it only supports ES5. [1] https://mujs.com/ https://mujs.com/
- sdegutis 8y agoMy JS-embedded apps only target macOS so I use Apple's builtin JavaScriptCore framework.
- nikki93 8y agoIn my experience LuaJIT in interpreter only mode has better performance than using JSC (you can’t use JIT in JSC either — only WKWebViews can JIT). (edit: sorry this is regarding iOS)
- sdegutis 8y agoMaybe, but my use-cases (window manager and other automation stuff) don't really have a strong need for speed or high performance. Mostly it just sits there idle 99% of the time and runs callbacks quicker than the UI that it manipulates is visibly updated.
- nikki93 8y agoYeah I think it does end up boiling down a lot to use cases because the big differences b/w Lua and JS are in availability of libs / integration and perf. In my case I do a lot of 2d graphics where love2d.org is available and perf is important. :) C interop is also really important, and LuaJIT C FFI is waaaaay nicer to use than JSC C API. I’ve ended up doing a lot of JS with React Native for “app-y” mobile apps though.
- sdegutis 8y agoIf perf is important, I'm surprised you're using Love2d and not just using C++ with SDL and Box2d directly. Afaik Love2d just uses vanilla Lua (and not LuaJIT) which, while faster than similar languages, is still pretty wasteful of cycles when high perf is needed.
- dividuum 8y agoThere's duktape (https://duktape.org/ https://duktape.org/), which, from skipping over the documentation seems very similar to Lua when it comes to embedding: It also uses the stack based approach. Looks like there's some ES6/7 support.
- zeotroph 8y ago> Sparkling All these "Let's do Lua, but right" languages fill me with both hope AND dread. This also shows what Lua could have become if a few more bold decisions were made. But I guess without a large commercial entity behind it, that was inevitable. Is there list of lua-ish (especially wrt. speed and easy C integration) languages somewhere? I did not know this one for example.
- engineer331 8y agoYou might want to check out Squirrel[1]. It has some major differences when compared to Lua[2], such as a C-style syntax and true objects, but like Lua is known for easy embedding in C and C++. The Source Engine includes Squirrel as one of its supported scripting languages[3], and it's used in non-gaming applications such as the Code::Blocks IDE. [1]: http://squirrel-lang.org/ http://squirrel-lang.org/ [2]: http://wiki.squirrel-lang.org/mainsite/Wiki/default.aspx/SquirrelWiki/Lua%20Compared%20to%20Squirrel.html http://wiki.squirrel-lang.org/mainsite/Wiki/default.aspx/Squ... [3]: https://developer.valvesoftware.com/wiki/Squirrel https://developer.valvesoftware.com/wiki/Squirrel
- mingodad 8y agoThere is also a squirrel fork SquiLu[1] that add some Lua code (like pattern matching, some stdlib), extend it with string IO, have several extensions (sqlite3, http server, mpdecimal, axtls, curl, ...), accept a subset of Javascript/Java/C/C++, ... [1]:https://github.com/mingodad/squilu https://github.com/mingodad/squilu
- vvanders 8y ago> Lua is semantically almost identical to modern JavaScript. Having spent a lot of time looking pretty hard at Lua, LuaJIT, and embeddedable variants of JS(duktape and the like) I think that's a bit of a stretch. It's pretty trivial to induce JS memory leaks[1] that can be brutal on embedded platforms. We had a prototype project written in JS and Lua, same functionality but hit issues like this pretty often. Like most memory leaks they weren't straightforward to track down as well. For my money LuaJIT still reigns supreme despite the fact that it's not under active development any more[2]. [1] http://point.davidglasser.net/2013/06/27/surprising-javascript-memory-leak.html http://point.davidglasser.net/2013/06/27/surprising-javascri... [2] https://www.freelists.org/post/luajit/Looking-for-new-LuaJIT-maintainers https://www.freelists.org/post/luajit/Looking-for-new-LuaJIT...
- wruza 8y ago>almost identical to modern JavaScript What do you mean by ‘almost’? You cannot have fair separate threads of execution or substitute function’s global environment in javascript, but this is the other way ‘almost’. What features does js have beyond syntactic sugar and second-hand techniques?