10 ms·
The evolution of Lua, continued [pdf]
- SchwKatze 1y agoLua is the SQLite of program languages, absolutely blast
- mkovach 1y agoWhile I enjoy Lua, clean, elegant, and entirely too reasonable, Tcl is undoubtedly the SQLite of programming languages. https://www.tcl-lang.org/community/tcl2017/assets/talk93/Paper.html https://www.tcl-lang.org/community/tcl2017/assets/talk93/Pap... It's because Tcl, like SQLite, operates on a peculiar metaphysical principle: everything is a string until proven otherwise, and even then, it's probably still a string. Also, D. Richard Happ, who we owe thanks for SQLite, was and perhaps still sits on the TCL Board (I may be wrong about that, but Happ holds significance in the TCL community). In my mind: Tcl is the quietly supportive roommate who keeps making coffee and feeding LISP-like functionality until the world finally notices its genius. Lua sits across the table, sipping espresso with a faintly amused expression, wondering how everyone got so emotionally entangled with their configuration files.
- 7thaccount 1y agoDidn't the string stuff get improved in the last few years to be a lot more performant?
- 01HNNWZ0MV43FF 1y agoI think TCL does an opaque thing, everything "is" a string, but if you don't use it as a string, it's actually stored in some optimized format. Then it converts back to a string on demand I still prefer Lua personally. Their type system is easy for me to understand
- mkovach 1y agoTCL 9 brought some welcome string improvements, and things run faster overall. But in my case, it's hard to say how well that's actually played out, partly because I haven't done the work to find out. My TCL scripts and apps work well enough to allow me to be lazy about them. Performance is up, but so is my inertia. So while TCL 9 could be transformative, for now it remains a white paper I've skimmed, not a revolution I've implemented.
- thadt 1y agoLua is one of the easiest configuration file formats I've had the pleasure of working with. Readable. Has comments. Variables. Conditionals. Everyone (including me): "oh no, no, you don't want a full Turing complete language in your configuration file format" Also Everyone: generating their configuration files with every bespoke templating language dreamed of by gods and men, with other Turing complete languages.
- mcdonje 1y agoIt's a security issue. Configs are user interfaces. Devs generating configs is irrelevant.
- thadt 1y agoIndeed - it would depend greatly one's workflow and threat model.
- ModernMech 1y agoYou could solve this with a capabilities permissions system. That way the config files can be written in the same language but have configured permissions that are different from the rest of the programming language. So you could restrict the config files from resources like threads, evaling source, making network requests and whatnot. Come to think of it you could even probably section off parts of the language behind capabilties such that the config files could be configured to be a not-Turing complete subset of the language.
- justincormack 1y agoLua started as a config language.
- kragen 1y ago*Hipp
- r2ob 1y agonice LoL
- jll29 1y agoLua is the glue when sh/bash doesn't suffice. Lua is simple and elegant, and I much prefer it to Tcl. Lua is in games and in LuaTeX, and when you have the choice of embedding a LISP, a FORTH or Lua in a larger application, it is often the most maintainable, runtime-efficient and low-memory footprint option of all.
- 1313ed01 1y agoIf you embed Lua you also get Fennel (almost LISP) support for free.
- radiator 1y ago> Lua is the glue when sh/bash doesn't suffice. I enjoy Lua and use it professionally, but when bash (and AWK) don't suffice, the glue is Perl. Because it has pipes which you can use to connect the output of one command to the input of another, or to a file.
- bmacho 1y agoPeople don't normally embed FORTH in a larger application.
- boris 1y agoWhat would be the SQLite's equivalent to indexing starting from 1, not 0? Off the top of my head I can't think of anything that would go so much against the grain.
- HackerThemAll 1y agoDuckDB is the mother of them all. It is waaaay more capable than SQLite, and embeds SQLite for those who need 100% compatibility for some workloads.
- pistolpete5 1y ago[flagged]
- welovebunnies 1y agoFirst time I've been called a bot I guess :-) But no, I'm a real person, I just post things that I (randomly) find interesting
- exographicskip 1y agoGo pokes!
- poly2it 1y agoAnd who are you, mr. Created 3 hours ago?
- dang 1y ago"Please don't post insinuations about astroturfing, shilling, bots, brigading, foreign agents and the like. It degrades discussion and is usually mistaken. If you're worried about abuse, email hn@ycombinator.com and we'll look at the data." https://news.ycombinator.com/newsguidelines.html https://news.ycombinator.com/newsguidelines.html https://hn.algolia.com/?sort=byDate&dateRange=all&type=comment&storyText=false&prefix=true&page=0&query=by:dang%20astroturf https://hn.algolia.com/?sort=byDate&dateRange=all&type=comme...
- synergy20 1y agoWish there is newer LuaJIT to leverage the new Lua features, but then maybe those new features are not really that critical.
- Touche 1y agoI feel like the existence of LuaJIT made is seemed like standard Lua was slow, but that's far from the case.
- 01HNNWZ0MV43FF 1y agoI spent a few nights trying to implement a Lua interpreter myself and it was still like 10x slower than PUC Lua, even before adding a GC. I'm not sure how they do it, it looks like regular C code
- ux266478 1y agoLuaJIT is amazing. I find it insane there are no Schemes that are able to match it as a tiny, embeddable scripting language with a JITer. GNU Guile is an absolute gargantuan monster in comparison.
- 1313ed01 1y agoBut you can use Fennel, that is a bit scheme-like if you squint a bit, and it transpiles to very nice Lua code in my experience.
- kragen 1y agoLuaJIT is in somewhat active development, with 40 commits so far this year, although these are mostly bug fixes (some for bugs introduced by LLVM). The main new feature, if you can call it that, is "suport for Apple hardened runtime."
- Rohansi 1y agoLuaJIT is also stuck at Lua 5.1 (by choice) while the latest is Lua 5.4, with 5.5 on the way.
- ecshafer 1y agoIt is interesting that so many of the largest languages were developed in a couple year time frame in the early-mid 90s. Python, Javascript, Java, Lua, R. All of these were developed 91-95 and make a bulk of development today.
- kqr 1y agoLanguages developed in that time matured just as good binary package managers started popping up, is my pet theory. Before that, getting a development environment for a new language was serious work, and people did things like stick to Perl since it happened to be installed already.
- kanbankaren 1y agoNot true. I was programming in the 90s when these languages emerged. Developments environments were emacs, vi, Brief, Borland IDE, etc. There were a few other IDEs available, but about $200 per seat. All the scripting languages mentioned didn't come as default in Unix or Windows. You had to download from their own websites. It was mostly Visual Basic, C, COBOL that were popular.
- kqr 1y agoI think that's what I mean. After the time you talk about ('90s), these languages matured, and they happened to mature around the same time binary package managers became a thing, i.e. in the early-to-mid '00s.
- DonHopkins 1y agoThere was also ELK Scheme, the Extension Language Kit, a scheme interpreter designed to be used as an extension language for other appllications. https://www.usenix.org/legacy/publications/compsystems/1994/fall_laumann.pdf https://www.usenix.org/legacy/publications/compsystems/1994/... >Elk, the Extension Language Kit, is a Scheme implementation that is intended to be used as a general, reusable extension language subsystem for integration into existing and future applications. Applications can define their own Scheme data types and primitives, providing for a tightly-knit integration of the CIC++ parts of the application with Scheme code. Library interfaces, for example to the UNIX operating system and to various X window system libraries, show the effectiveness of this approach. Several features of Elk such as dynamic loading of object files and freezing of fully customized applications into executables (implemented for those UNIX environments where it was feasible) increase its usability as the backbone of a complex application. Elk has been used in this way for seven years within a locally-developed ODA-based multimedia document editor; it has been used in numerous other projects after it could be made freely available five years ago. Also Gnu Guile: https://en.wikipedia.org/wiki/GNU_Guile https://en.wikipedia.org/wiki/GNU_Guile >GNU Ubiquitous Intelligent Language for Extensions[3] (GNU Guile) is the preferred extension language system for the GNU Project[4] and features an implementation of the programming language Scheme. Its first version was released in 1993.[1] In addition to large parts of Scheme standards, Guile Scheme includes modularized extensions for many different programming tasks.[5][6] Also Winterp, which used XLisp: https://dl.acm.org/doi/10.1145/121994.121998 https://dl.acm.org/doi/10.1145/121994.121998 >Winterp is an interactive, language-based user-interface and application-construction environment enabling rapid prototyping of applications with graphical user interfaces based on the OSF/Motif UI Toolkit. Winterp also serves as a customization environment for delivered applications by providing a real programming language as an extension language. Many existing user-interface languages only have the expressive power to describe static layout of user interface forms; by using a high-level language for extensions and prototyping, Winterp also handles the dynamic aspects of UI presentation, e.g. the use of direct manipulation, browsers, and dialog. Winterp makes rapid prototyping possible because its language is based on an interpreter, thereby enabling interactive construction of application functionality and giving immediate feedback on incremental changes.Winterp's language is based on David Betz's public domain Xlisp interpreter which features a subset of Common Lisp's functionality. The language is extensible, permitting new Lisp primitives to be added in the C language and allowing hybrid implementations constructed from interpreted Lisp and compiled C. Hybrid implementation gives Winterp-based applications the successful extension and rapid-prototyping capabilities of Lisp-based environments, while delivering the multiprocessing perfor- mance of C applications running on personal Unix workstations. And TCL/Tk of course! https://www.tcl-lang.org/ https://www.tcl-lang.org/ And on the commercial side, there was Visix Galaxy, which was extensible in PostScript, inspired by NeWS: https://www.ambiencia.com/products.php https://www.ambiencia.com/products.php https://0-hr.com/Wolfe/Programming/Visix.htm https://0-hr.com/Wolfe/Programming/Visix.htm https://groups.google.com/g/comp.lang.java.programmer/c/LPkz9Z9sUl0 https://groups.google.com/g/comp.lang.java.programmer/c/LPkz... https://donhopkins.com/home/interval/pluggers/galaxy.html https://donhopkins.com/home/interval/pluggers/galaxy.html https://wiki.c2.com/?SpringsAndStruts https://wiki.c2.com/?SpringsAndStruts >The Visix Galaxy project was a ridiculously overpriced and overfeatured portable GraphicalUserInterface. You could do things like swivel an entire panel full of their custom widgets 32 degrees clockwise, and it would render all its text at this new angle without jaggies. The company went out of business after gaining only a handful of customers. For USD$ 10,000 a seat they sure didn't see the OpenSource movement coming. Their last attempt before going under was (guess what?) a Java IDE. Galaxy competed with Neuron Data Systems in the "cross platform gui framework" space (which got steamrolled by the web permanently and for a window of time Java): https://donhopkins.com/home/interval/pluggers/neuron.html https://donhopkins.com/home/interval/pluggers/neuron.html Here is a great overview of User Interface Software and Tools by Brad Myers: https://www.cs.cmu.edu/~bam/uicourse/2001spring/lecture05toolsintro.html https://www.cs.cmu.edu/~bam/uicourse/2001spring/lecture05too... https://www.cs.cmu.edu/~bam/toolnames/ https://www.cs.cmu.edu/~bam/toolnames/ https://docs.google.com/document/d/1hQbMwK_iyjX-wpu_Xw_H-3zLIgcHxWViyMvYO7mDuFg/edit?tab=t.0 https://docs.google.com/document/d/1hQbMwK_iyjX-wpu_Xw_H-3zL...
- pansa2 1y ago> work has begun on Lua 5.5 A beta version is now available: https://www.lua.org/work/ https://www.lua.org/work/ The main change from 5.4 seems to be the (optional?) removal of global-by-default, instead requiring declarations for global variables.
- strenholme 1y agoAs it turns out, it’s possible with Lua going back to 5.1 to not allow undeclared global variables: https://www.lua.org/pil/14.2.html https://www.lua.org/pil/14.2.html That code looks like this in Lua 5.1: function set(name, val) rawset(_G, name, val or false) end function exists(name) if rawget(_G, name) then return true end return false end throwError = {__newindex = function(self,name) error("Unknown global " .. name) end, __index = function(self,name) error("Unknown global " .. name) end } setmetatable(_G,throwError) Then, to use set("a") -- set"a" also works a = 1
- ufo 1y agoNaturally, the main catch is that this only detects the violation at run-time. It also won't stop you from accidentally overwriting a global variable that already exists.
- nmz 1y ago> It also won't stop you from accidentally overwriting a global variable that already exists. That's also solvable using metatables.
- Dylan16807 1y agoDo the declarations in 5.5 prevent overwriting? That sounds tricky to define and implement.
- azemetre 1y agoMy only context in using Lua is my neovim configuration, does any know of any good books or tutorials that make something more advance using only lua? Anything of note to consider/read/watch?
- strenholme 1y agoShameless plug time: I have written a public domain book which looks at using Lua (Lua 5.1 but the code works in newer versions as well as Lua 5.1/Luau/LuaJIT) as a text parsing engine. The book assumes familiarity with other common *NIX scripting languages (such as AWK, Perl, or Python) and goes over in detail the pain points for people coming from a *NIX scripting background: https://maradns.samiam.org/lunacy/SamDiscussesLunacy.pdf https://maradns.samiam.org/lunacy/SamDiscussesLunacy.pdf Source files (.odt file, fonts used by book): https://github.com/samboy/lunacy/tree/master/doc https://github.com/samboy/lunacy/tree/master/doc Hope this helps!
- azemetre 1y agoThanks for recommendation and writing the book! I'm reading the introduction, it doesn't answer why you chose to fork lua and create lunacy. What were you trying to solve with lunacy that lua couldn't do? The TOC looks great, I will read this soon. Need to finish "Debugging CSS" first (another good book IMO).
- strenholme 1y agoThe main reason I made Lunacy was to have a standard compile of Lua 5.1, since it’s possible to make a Lua 5.1 compile with, say 32-bit floats or which only supports integers but not floats. Lunacy also has a few built in libraries which are not included with Lua 5.1, such as binary bitwise operations (and/or/xor). It also fixes some security issues with Lua 5.1 (better random number generator, hash compression algorithm which is protected from hash flooding attacks). In addition, I have made a tiny Windows32 binary of Lunacy. Don’t worry about the Lunacy changes; all of the examples in the book work with bog standard Lua 5.1 with a bit32 library (bit32 is common enough most OSes with a Lua 5.1 package also have a bit32 package for Lua 5.1).
- sgt 1y agoThat's it - I'm building my next startup in Lua!
- jll29 1y agoA useful design pattern is to write highly efficient "engine" code in C/C++ and then tie it together to highly customizable application code with an embedded scripting language. Lua is great for this, and while you could use a LISP (Emacs, AutoCad) or a FORTH (any real-life example not from the radio telescope domain?) or Tcl/Tk (https://wiki.tcl-lang.org/page/Who+Uses+Tcl https://wiki.tcl-lang.org/page/Who+Uses+Tcl), Lua is small (as in number of concepts to understand), easy to read and understand, and compact (as in tiny codebase to integrate, few dependencies). So many gaming startups have put their money on Lua.
- groovy2shoes 1y agoThe Lua-C API is also really consistent and straightforward. Bindings can be generated mechanically, of course, but it's really easy to embed by hand, and the documentation is superb.
- sgt 1y agoAnd LLM's should be proficient in Lua and the bindings by now. That will help with velocity.
- cycomachead 1y agoI believe cloudflare has quite a bit of Lua in some of their products (there's some very good Nginx lua integrations and variants like Openresty).
- alcroito 1y agoAnybody knows if there's a lua DAP (debugger) server in development by anyone? Neovim lua has https://github.com/jbyuki/one-small-step-for-vimkind https://github.com/jbyuki/one-small-step-for-vimkind but it doesn't seem there's any DAP server for regular lua.
- strenholme 1y agoHere’s my bit of public domain code for iterating through tables in Lua so that the elements are sorted. This routine works like the pairs() function included with Lua: -- Like pairs() but sorted function sPairs(inTable, sFunc) if not sFunc then sFunc = function(a, b) local ta = type(a) local tb = type(b) if(ta == tb) then return a < b end return ta < tb end end local keyList = {} local index = 1 for k,_ in pairs(inTable) do table.insert(keyList,k) end table.sort(keyList, sFunc) return function() key = keyList[index] index = index + 1 return key, inTable[key] end end Example usage of the above function: a={z=1,y=2,c=3,w=4} for k,v in sPairs(a) do print(k,v) end With a sort function: a={z=1,y=2,c=3,w=4} function revS(a,b) return a>b end for k,v in sPairs(a,revS) do print(k,v) end (Yes, this is a lot easier to do in Perl or Python, since those languages unlike Lua have built in list iterators, but it’s possible to do in Lua too)
- deleted 1y ago[deleted]
- nmz 1y agoIf you did not return a closure, you could set the metatables __pairs to use your function's. Sadly, you could not do this without keeping some sort of cache, which would be a terrible waste of memory, but then again you're already creating an iterator that iterates completely, to me, this beats the use of an iterator (to not iterate over everything and break on a single pass)
- hackthemack 1y agoI was thinking a while back, how nice it would be if lua was the scripting language in the browser instead of javascript. There are some projects to compile lua to wasm and have it run in the browser... https://pluto-lang.org/web/#env=lua%3A5.4.6&code=if%20_PVERSION%20then%0A%09--%20Pluto%0A%09print(%22Hello%20from%20%22.._PVERSION)%0Aelse%0A%09--%20Lua%0A%09print(%22Hello%20from%20%22.._VERSION)%0Aend https://pluto-lang.org/web/#env=lua%3A5.4.6&code=if%20_PVERS... But interoperability with the DOM is the missing key. Still, if lua was used instead of javascript, I could see myself saying... man, I wonder what browser development would be like if we replaced lua with x.
- strenholme 1y agoThere’s also a Javascript implementation of Lua which allows one to run Lua in a browser: https://github.com/fengari-lua/fengari-web https://github.com/fengari-lua/fengari-web I don’t know if this can access the DOM in Lua, but considering that Fengari is in Javascript, adding a _DOM global variable should not be too hard (if it hasn’t already been done).
- bawolff 1y agoFengari lets you access the DOM. Its pretty cool.
- shakna 1y agoNo need for _DOM. local js = require "js" local window = js.global local document = window.document window:addEventListener("load", function() local el = document:getElementById("main") el:addEventListener("click", function(evt) js.console:log(evt.target) end document.body:appendChild(el) end
- james2doyle 1y agoThere is also nelua (https://nelua.io/ https://nelua.io/) which can use WASM to compile allow its usage in the browser: https://github.com/edubart/nelua-game2048/ https://github.com/edubart/nelua-game2048/
- 1y ago
- rebolek 1y agoI don't understand why Python is so popular when there's Lua. It's just so much better. Not as good as Rebol but still much better than Python.
- poly2it 1y agoPython has a much larger and more mature ecosystem. Lua barely has a functioning package manager.
- ksymph 1y agoIt's still early in development, but the new package manager Lux looks promising: https://github.com/lumen-oss/lux https://github.com/lumen-oss/lux
- flykespice 1y agoDon't forget it's much more productive writing a script in Python to parse a text than Lua due to its huge feature-rich syntax
- karel-3d 1y agoLua is great when you need an embedded language. That's it. It's not great on its own, in my opinion. It becomes really gnarly if you have a bigger Lua codebase.
- nmz 1y agoRebol is the cleanest/greatest language I've read code for but the VM is the slowest VM I've ever wrote code for, mind you I only did the first 10 exercises of euler but the only thing that has it beat is writing a shellscript that forks to dc/bc on each math expression.
- sieep 1y agoI've been saying it for years: Lua needs its Ruby on Rails moment
- flykespice 1y agoHell no, keep it small as is, no influence from big corporations and no enshittification (or having a "DHH problem" in Lua community)
- sieep 1y agoI see your point. I've just craved a rails-like experience in Lua for a while and don't believe there's anything out there yet built on Lua that can match with the big boys (rails, .NET, etc.)
- chadcmulligan 1y agoThats probably why I use it - no corporates and gamers use it so it doesn't get enshittified like java/c#/c++ etc no committees either.
- rodolphoarruda 1y agoYes, with Lapis[1]. [1] https://leafo.net/lapis/ https://leafo.net/lapis/
- sieep 1y agoLooks promising. Thanks for sharing!
- cycomachead 1y agoLapis is very cool, but I really struggle with a lack of examples and pre-built solutions for some things. Leafo's itch.io is built with it and I maintain snap.berkeley.edu. A great tool, but I'm also many times more productive in Rails. (It's an unfair comparison, to be sure!) and Openresty + Lapis is quite performant and low overhead which is great.
- codebolt 1y ago
- ST33LDI9ITAL 1y agoDon't leave out Fennel! https://fennel-lang.org/ https://fennel-lang.org/
- 1vuio0pswjnm7 1y agoWhen comparing speed I use simple tests like a loop printing an incremented line number or reading from stdin and printing to stdout. These simple tests are useful for me because, when combined with pattern matching or regular expressions, simple I/O tasks like these are actually what I use a "memory safe" language for dino is slightly faster than lua (not luajit) but spitbol is actually faster than lua, dino and luajit ngn k is slightly faster than spitbol but lacks built-in pattern matching or RE FWIW, I do not use a terminal emulator. I only use textmode No graphics layer. No "desktop"
- zahlman 1y ago> These simple tests are useful for me because, when combined with pattern matching or regular expressions, small, simple I/O tasks like these are actually what I use a "memory safe" language for Are you sure you aren't being bottlenecked by your terminal?
- 1vuio0pswjnm7 1y agoFor me, statically-linked 64-bit spitbol is only 175k static-pie luajit 2.1 is 667k static-pie lua 5.1.5 is 259k static-pie ngn k is 271k
- wewewedxfgdf 1y agon entire language off by one.
- aa-jv 1y agoIf you're new to Lua, be sure to check out TurboLua: https://turbo.readthedocs.io/en/latest/ https://turbo.readthedocs.io/en/latest/ Its a very flexible way to do realtime/embedded, performance-critical services (e.g., a game server or API gateway) where Lua's speed and low overhead matter.
- deleted 1y ago[deleted]