10 ms·
Lua's presence is honestly hugely because it is so easy to embed in other programs. If you needed some scripting capabilities, Lua was the way. Whether it's a w
by rektide 3y ago
Lua's presence is honestly hugely because it is so easy to embed in other programs. If you needed some scripting capabilities, Lua was the way. Whether it's a webserver (nginx) or editor (vim) or a window manager (awesome), Lua was the easiest & best at hand option to integrate.
There is a huge opportunity, IMO, for more players here. Deno definitely has some good gestures toward a this. Wasm though seems like the likely general heir, and will have many different offerings for how to do that (Deno being one!).
- Rochus 3y ago> hugely because it is so easy to embed in other programs Not only; Lua is also an example of excellent language design: a minimum of concepts for a maximum of expressability; it's minimal, complete and elegant. > Deno definitely has some good gestures toward a this Lua is much leaner, only ~100k machine code. WAMR looks like a better candidate than Deno, but concerning performance and simplicity it has still to catch up.
- qznc 3y agoForth and Lisp/Scheme and TCL are in the same league. However, they are more alien to C programmers, I assume.
- Rochus 3y agoTCL, Forth and Lisp are languages with minimum possible syntax, delegating all higher-level concepts to runtime structures and conventions (e.g. which list position means what), whereas Lua for its syntax and semantics inherited, pruned and elegantly integrated the best features of Modula-2 and other languages. It is true that Lua is more familiar to C developers than the mentioned languages, since both Lua and C look back to the ALGOL ancestry; but Lua - unlike C - clearly follows the Pascal heritage.
- stefanos82 3y agoI've just used `cloc`-ed Lua repo's entire code base, excluding makefile's and markdown's: 33619 lines in total of C, Lua, and C / C++ Header code; very lightweight code base.
- Rochus 3y agoLua 5.1 has 11'081 SLOC in 32 .c and 1'506 SLOC in 23 .h files (without tests and examples).
- ufo 3y agoAnd that includes the test suite! Over 1/3 of that is inside the tests directory.
- brabel 3y agoThere's a single C file you can compile really easily with `gcc -o lua luaall.c`. It compiles the whole thing in a couple of seconds!
- stefanos82 3y agoYou meant to say `onelua.c` file; indeed it's a fascinating language, I have to admit.
- ufo 3y agoOne of the reasons why Lua is minimal is that it makes it easier to embed. It's no coincidence :) https://www.lua.org/doc/cacm2011.pdf https://www.lua.org/doc/cacm2011.pdf
- AlecSchueler 3y agoFascinating document, does anyone know if there's an html version?
- ufo 3y agoThere is, but the figures are broken :/ https://cacm.acm.org/magazines/2011/7/109909-passing-a-language-through-the-eye-of-a-needle/fulltext https://cacm.acm.org/magazines/2011/7/109909-passing-a-langu...
- pkphilip 3y agoSo also Groovy. I have embedded Groovy in web applications to use as a rule engine. It is also very easy to install. https://docs.groovy-lang.org/latest/html/documentation/guide-integrating.html https://docs.groovy-lang.org/latest/html/documentation/guide...
- brabel 3y agoI think a "competitor" to Lua would be Guile [1], but I am not sure if it gets close to Lua in terms of lightweightness... it was designed to be used in the GNU project, with similar objects as Lua: to be light, easily embeddable. It's a Scheme (Lisp) so maybe not for everyone's taste... its "coolest" use i know of is for configuring Guix [2] (the GNU version of Nix). [1] https://www.gnu.org/software/guile/ https://www.gnu.org/software/guile/ [2] https://guix.gnu.org https://guix.gnu.org
- JdeBP 3y agoThe competitors in practice were REXX and TCL. All three provide embeddable interpreters as libraries, and easy ways to extend what is available in scripts with custom domain-specific functions that one could call from them.
- geospeck 3y agomruby[1] fits that category too. It can be used with H2O[2] server as well. There was a discussion here a couple of months ago regarding some use cases[3]. [1]https://mruby.org https://mruby.org [2]https://h2o.examp1e.net/configure/mruby.html https://h2o.examp1e.net/configure/mruby.html [3]https://news.ycombinator.com/item?id=34937297 https://news.ycombinator.com/item?id=34937297
- vvanders 3y agoIt's not just that it's easy to embed but it's also tiny as well, I've run it on many embedded platforms. It wasn't until quickjs came along that there was anything even in the same ballpark. When you factor in LuaJIT[1] and the incredible performance/zero-overhead-FFI[2] it really is a neat language. [1] https://luajit.org/ https://luajit.org/ [2] https://github.com/dyu/ffi-overhead https://github.com/dyu/ffi-overhead
- dleslie 3y agoJanet is another language that's just trivial to embed, but it's newer so it has less traction.
- cpeterso 3y agoLink: https://janet-lang.org/ https://janet-lang.org/
- jacknews 3y agoReally enjoying Janet, but it has some sad and seemingly unnecessary syntax differences to the rest of the lisps and lisp-likes.
- apgwoz 3y agoI have ignored it because quasiquote is `;’ and that just pisses me off. I should not have such a strong reaction, but I do.
- apgwoz 3y agoUgh. I meant `;` is unquote-splicing, which is an operator within a quasiquote. Sorry for my brain fart.
- jacknews 3y agoYes, we shouldn't, but sometimes superficial features can be quite important. I've ignored CL because it seems like the BASIC or bloated kitchen-sink of lisp/likes, but probably mainly because 'car'? 'cdr'? 'setq'? seriously?
- jhbadger 3y agoBut that's just how Lisp works. Emacs Lisp (not CL) uses those too. It's Scheme that decided to rename car and cdr (and by doing so obscure how things are implemented underneath).
- 3y ago
- alexjplant 3y ago> webserver (nginx) How timely! Right now I'm learning Lapis [1] by building a toy CRUD app that I plan on deploying to fly.io. Lua reminds me of Go insofar as it's a really "dumb" language. You can't get too cute and there are a few powerful abstractions that let you accomplish a lot. Coming from Python (which is an endless horizon of PEPs and build artifact standards and name mangling and kwargs and... well, you get the idea) it's kind of a breath of fresh air. As for 1-based indexing: it makes more sense. We're all just used to 0-based because that's how C worked. If you stop and think about it early C was really just a veneer on top of assembly and since addressing an array in memory meant having a pointer to the first element that meant that it was arr[0]. We have no need for this decades later. [1] https://leafo.net/lapis/ https://leafo.net/lapis/
- fanf2 3y agoYears ago I wrote a DNS-over-HTTPS proxy as an nginx / OpenResty module in Lua. The Lua code included a very stripped-down DNS message parser. The 1-based indexes and closed (instead of half-open) intervals were a massive pain in the arse. The code has a tricky mixture of odd and even offsets that would all have been even in C, and it would have been much easier to replace the magic numbers with named constants. https://github.com/fanf2/doh101/blob/master/roles/doh101/files/doh.lua https://github.com/fanf2/doh101/blob/master/roles/doh101/fil...
- vvanders 3y agoOh you can totally get too cute with metatables. I've seen inheritance/straight-OO(Java/C++ style), component based design, and eventing/message based approaches all with the core primitives that Lua provides. I think my favorite one was one that used yield[1] with the parameters being the number of frames to resume the execution of the coroutine. That was used by a number of our game designers to write AI scripting that felt close to literate programming(I.E. "move x, look for player, yield 30, if found player, go here, etc). You could build a whole AI state machine that fit into one page of code and was very easy to follow. [1] https://www.lua.org/manual/5.1/manual.html#pdf-coroutine.yield https://www.lua.org/manual/5.1/manual.html#pdf-coroutine.yie...
- hgs3 3y ago> There is a huge opportunity, IMO, for more players here. There are quite a few embeddable scripting languages [1]. I think these days it's less common to embed a language mostly because there are good high-level languages that applications can be predominantly written in. [1] https://github.com/dbohdan/embedded-scripting-languages https://github.com/dbohdan/embedded-scripting-languages
- Blackthorn 3y agoI've honestly not found it easy to embed as-is, at least in C++. Getting functions into Lua is a challenge. Sol2 makes life soooo much easier for it.
- shadowgovt 3y agoGetting functions into Lua is my favorite use of macros in c++.
- otikik 3y agoLuaJIT has FFI capabilities, it's not a one-liner but it's also not bad: https://gist.github.com/matiasinsaurralde/0a4ecf8f3e0d8768b3983cc1134a9f9b https://gist.github.com/matiasinsaurralde/0a4ecf8f3e0d8768b3...
- Blackthorn 3y agoThe problems I've had are passing data structures between...really gets rough.
- tourgen 3y ago[dead]
- jezek2 3y agoEasy embedding is one of the goals of FixScript [1] (my language). It consists of a single C file (and a header). It even includes a JIT while not being gigantic. It also provides a more direct C API which I think is more friendly for embedding. It has strong support for backward and forward compatibility, a great feature for embedding usage to not make your scripts obsolete and generally working in any version of the host application. [1] https://www.fixscript.org/blog/introduction https://www.fixscript.org/blog/introduction
- sieabahlpark 3y ago[dead]
- robotnikman 3y agoIts also the go-to language for lot of games when it comes to modding, or scripting things like custom missions or scenarios.
- rapnie 3y ago> Wasm though seems like the likely general heir, and will have many different offerings for how to do that (Deno being one!). I was recently blown away by some ideas that StackBlitz [0] apply based on WebContainers. The idea of a "server in the browser", they allow you to run Node-based environment like that via Wasm. [0] https://stackblitz.com/ https://stackblitz.com/ [1] https://webcontainers.io/ https://webcontainers.io/
- laurentlb 3y agoFor many purposes, Starlark[1] could be used as an alternative to Lua. It's also designed to be embedded, it's a very simple language, and has 3 implementations (in Java, in Go and in Rust). [1] https://github.com/bazelbuild/starlark https://github.com/bazelbuild/starlark