13 ms·
Lua: The Little Language That Could
- jmclnx 3y agoLua was on my very short list of languages to learn. Will need to revisit that. Also worth noting, NetBSD has had lua hooks into their kernel for about 10 years I think.
- ok_dad 3y agoYou can learn Lua in a weekend, easy. The language is ridiculously small, but also ridiculously powerful. You can learn how to use C libraries in Lua in another weekend, easy. Using Lua from C is also easy, one weekend or less.
- stefanos82 3y agoHow about in 15 minutes lol ? https://tylerneylon.com/a/learn-lua/ https://tylerneylon.com/a/learn-lua/
- celaleddin 3y agoJust curious: Can you share your list of languages to learn?
- rektide 3y agoLua'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.
- 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
- pyjarrett 3y agoWow, I just integrated Lua into a C++ project for the first time last night. Took <15 minutes to integrate it with the build system (FASTBuild), watched a tutorial video[1], and then in another 15 minutes I had it hooked up to configure my application. [1]: https://www.youtube.com/watch?v=4l5HdmPoynw https://www.youtube.com/watch?v=4l5HdmPoynw
- akkartik 3y agoFor the past year I exclusively use Lua for my side projects. And I use it with certain self-imposed restrictions: * no Luarocks * no native libraries More details: http://akkartik.name/freewheeling http://akkartik.name/freewheeling
- iamcreasy 3y agoCan you kindly provide a one line explanation as to why no Luarocks?
- akkartik 3y agohttps://xkcd.com/2347 https://xkcd.com/2347 That way lies npm and left-pad. Tools encourage behaviors. I avoid tools that encourage behaviors I want to avoid.
- AHTERIX5000 3y agoLuarocks works quite well if the lib is pure Lua. For native libs it's a wild west and success depends a lot on your environment. Sometimes the lib is being built with -Werror and fails if you're using more recent compiler, sometimes include paths are not resolved correctly using pkgconfig or similar and so on.
- harryvederci 3y agoGreat talk!
- carapace 3y agoThat essay/software/discipline is awesome!
- nmz 3y agoProblem is, which version of love to use? I do know someone had a multiversion love program but it didn't work for me.
- akkartik 3y agoCould you point me at it? Just for my own understanding.
- taylorius 3y agoArrays start at 1. Just... no.
- josephcsible 3y agoYeah that's a wart, but it's basically the only wart in an otherwise amazing language.
- fbdab103 3y agoEhh, local being a keyword (instead of local default, global only if required) was a significantly bigger gaff. The other would be no nulls in tables. 0/1 based indexing is familiarity only.
- josephcsible 3y agoRequiring a keyword to declare a variable is a good thing. Otherwise, it'd be easily to accidentally declare new variables when you meant to assign to an existing one. Since global is the default, starting a program with something like this effectively keeps that from happening: local gindex = {} setmetatable(_G, {__index = function(t,k) local v = gindex[k] if v == nil then error("Bad read of global variable " .. tostring(k), 2) else return v end end, __newindex = function(t,k,v) error("Bad write of global variable " .. tostring(k), 2) end}) for k,v in pairs(_G) do gindex[k] = v rawset(_G, k, nil) end
- ok_dad 3y agoWhy? 0 based indexing came from a time where you used memory addresses directly to index into arrays. Today, we don’t do that, so 1 based indexing seems extremely reasonable. Besides, with Lua you can still do 0 based indexing with a small personal extension function.
- imbnwa 3y agoOne of the first things requested by users of an internal media sequencing tool where time is measured by frames was 1-based indexing, they absolutely hated starting from 0
- ok_dad 3y agoOne of my favorite projects that uses Lua is https://redbean.dev/ https://redbean.dev/ It’s a single file web application engine, and more, in an executable you can run on several OSes and I think even bare metal, but it’s been a while since I looked at it so it’s probably even more awesome today.
- rlawson 3y agoYes! I'm currently learning Lua now just because of redbean. I also recommend the excellent ZeroBrane IDE - https://studio.zerobrane.com/ https://studio.zerobrane.com/ As a Java/Python dev there is something about using such light weight and fast tools like redbean, lua and ZeroBrane that brings a smile to my face.
- ezst 3y agoThere's also the http://prosody.im/ http://prosody.im/ XMPP server that's written in Lua, and it's very successful there. The other major XMPP server implementation is in Erlang and they are equally praised, so that should tell something about Lua's versatility.
- squarefoot 3y agoLua was born in 1993. That's 30 years, not bad for a language that some still consider new. For those looking for a GUI library for Lua, check out TekUI. http://tekui.neoscientists.org/index.html http://tekui.neoscientists.org/index.html I tested it on various distros without hassle, both on x86 and ARM. It would probably be worth of porting to other languages too.
- doctor_eval 3y agoThat’s got real Tk vibes right there!
- ValtteriL 3y agoLua is also the language of choice for the nmap scripting engine. While cute, easy to learn and all, I feel like it has kept back the development of nmap scripts. Only a few people are dedicated enough to take the time to learn it. Then again, I think this has kept the quality of the available scripts high.
- anony23 3y agoWhat are some of the nmap scripts that you use regularly?
- nottorp 3y agoWell who knew nmap has a scripting engine? :) Before reading your post, if i were in a situation where I needed to do complex stuff with nmap, i'd just integrate it in a script that would run it multiple times, parse the output etc. I never imagined it had a scripting language inside itself. Guessing the only people who know about that are admins in large networks and black or white hat crackers...
- JdeBP 3y agoOr just people who read manuals. (-: * https://manpages.debian.org/sid/nmap/nmap.1.en.html#NMAP_SCRIPTING_ENGINE_(NSE) https://manpages.debian.org/sid/nmap/nmap.1.en.html#NMAP_SCR...
- nottorp 3y agoOh yeah, if i were in a position to use nmap every day... Fortunately or unfortunately nmap --help has been good enough for me so far :) > if i were in a situation where I needed to do complex stuff with nmap Note: I've never been in such a situation. My network admin duties are like 0.5% of my time.
- PicassoCTs 3y agoA whole gamer generation has learned to make mods/games with this. (Roblox). Not javascript. Not python. This. That which educates the young, shapes the future, may the elders like it or not.
- nanidin 3y agoWorld of Warcraft addons as well.
- kitsunesoba 3y agoThat’s where I first encountered Lua.
- epivosism 3y agoyep. Roblox Lua/Luau tutorials on youtube - millions of views https://www.youtube.com/results?search_query=luau+roblox&sp=CAM%253D https://www.youtube.com/results?search_query=luau+roblox&sp=... Luau https://github.com/Roblox/luau https://github.com/Roblox/luau Roblox wrote a superset of Roblox Lua which is way faster https://luau-lang.org/ https://luau-lang.org/
- kzrdude 3y agonice pointers, that sounds interesting. Have they kept it near-compatible with lua when it comes to how to embed it in a host app? Wondering if they are "competitive" in that aspect.
- ChristopherDrum 3y agoPico-8 fantasy console uses Lua (a subset of; with Pico-8-specific console APIs). I keep going back to it in my personal projects time and again. I always think, "OK, I'm going to build the next thing in C" and wind up falling back to Pico-8 and Lua. The in-the-works Picotron will grow from Pico-8's roots and present a full fantasy computer, with an OS, windowing system, etc. and expands Lua support to the full v5.4 language.
- Daeraxa 3y ago
- krapp 3y agoI've started to view Lua as an extension to C rather than a language in its own right, which isn't really accurate, but reflects how well the two languages complement each other.
- thangalin 3y agoThe ConTeXt typesetting system tightly integrates Lua. One aspect of Lua I dislike is that it isn't object-oriented. What's impressive is that the language can be extended to be so in astonishingly little code: * https://github.com/kikito/middleclass/blob/master/middleclass.lua https://github.com/kikito/middleclass/blob/master/middleclas... Using OOP, typesetting a hexagonal grid and a symbolic representation of a neural network on top is easier develop, IMO. A vertex defines a point in 2D space: * https://github.com/DaveJarvis/keenwrite-themes/blob/main/boschet/Vertex.lua https://github.com/DaveJarvis/keenwrite-themes/blob/main/bos... An edge connects two vertices: * https://github.com/DaveJarvis/keenwrite-themes/blob/main/boschet/Edge.lua https://github.com/DaveJarvis/keenwrite-themes/blob/main/bos... A graph connects edges: * https://github.com/DaveJarvis/keenwrite-themes/blob/main/boschet/Graph.lua https://github.com/DaveJarvis/keenwrite-themes/blob/main/bos... A priority queue serves for ordering edges by weight of adjoining vertices: * https://github.com/DaveJarvis/keenwrite-themes/blob/main/boschet/PriorityQueue.lua https://github.com/DaveJarvis/keenwrite-themes/blob/main/bos... With these concepts in hand, we can typeset a grid and a "neural network" on top: * https://github.com/DaveJarvis/keenwrite-themes/blob/main/boschet/perceptron.tex https://github.com/DaveJarvis/keenwrite-themes/blob/main/bos... Here's an example of the output from the first chapter: * https://i.ibb.co/19DCDZy/ch-1.png https://i.ibb.co/19DCDZy/ch-1.png And a later chapter, where the "network" has grown in complexity: * https://i.ibb.co/ncf16vg/ch-2.png https://i.ibb.co/ncf16vg/ch-2.png This is for my near future hard sci-fi book on AGI. I'm looking for alpha readers to give me feedback. See profile for contact details. P.S. There's a subtle bug in the code that can result in one or two disconnected vertices. If you spot it, let me know!
- Rochus 3y agoIt's actually not ConTeXt which integrates Lua, but LuaTeX; ConTeXt is based on the features of LuaTeX. Lua includes all features required for OOP (see e.g. https://www.lua.org/pil/16.html https://www.lua.org/pil/16.html).
- WillAdams 3y agoYes, I was able to take advantage of this via lualatex to access METAPOST so as to do a parametric design for a CNC using OpenSCAD as a front-end: https://tug.org/TUGboat/tb40-2/tb125adams-3d.pdf https://tug.org/TUGboat/tb40-2/tb125adams-3d.pdf
- andrewmcwatters 3y agoIt is inevitable that people complain about Lua's 1-based "tables" which serve as both arrays and hash maps. I usually encourage people to remember the practical origins of 0-based arrays when thinking in terms of pointers, where 0-based counting is useful in terms of talking about offsets from a point in memory, as contrasted to 1-based counting where you are primarily talking about quantities of collections. Lua is a great language. My only wish is that it was easier to do multithreaded work in it. Unfortunately, this is not the case without some significant architectural forethought.
- saurik 3y agoThe reason why 0 makes sense for pointers isn't due to some arcane implementation detail of programming but because of how one conceptualizes ranges and distance and pointers just so happen to be a place where that comes up very directly in programming. Any time you attempt to develop an algorithm that needs to think about multiple ranges of a collection at the same time or needs to scale ranges through a collection, 1-based indexing causes you to have to throw in a bunch of +/-1 compensation factors to prevent you from double-counting or scaling past an edge. Life is just too short to have to constantly debug the issues that come from 1-based indexing when developing complex algorithms, even if it means beginners feel a bit confused by "counting from 0".
- andrewmcwatters 3y agoNo, it actually does originate from 1960's era programming practices. Not to say there weren't also 1-based or N-based numbering, but you're historically misled here. You could also say the same about counting collections. No regular person counts 0... 1... 2... 3... and ends counting N-1. It, too, is a workaround.
- kzrdude 3y agoI don't think saurik is talking about history, so you're talking past each other in that sense.
- imbnwa 3y agoLua metatable > JavaScript prototype
- SeanLuke 3y agoLet's put aside the god-awful 1-based tables, in 1993, which alone should have killed the language. My big problem with Lua is that it tries very hard to make possible all styles of language to all people, and as a result it is a language with a lot of boilerplate to do any one of them. For example, consider Lua's OO. The most obvious inspiration for Lua here was Newtonscript, via Self. They're quite open about it. Newtonscript and Self are prototype-style OO languages done well, as opposed to Javascript, which is a prototype-style OO abomination. Lua advertises itself as being able to do prototype-style OO, all you have to do is make some tweaks to its metatables. But while this stuff is baked into Newtonscript and Self, it is an amazing amount of boilerplate to do it in Lua, to the point of parody. https://www.lua.org/pil/16.1.html https://www.lua.org/pil/16.1.html
- tayistay 3y agoOn the page you linked, I see four lines of boilerplate in a constructor: function Account:new (o) o = o or {} -- create object if user does not provide one setmetatable(o, self) self.__index = self return o end Doesn't seem so bad. Are you referring to something else?
- daneel_w 3y agoWhy would you wish the death of a language only because its default index for arrays is 1? You're not forced to index from 1 and onwards. You can use any range you want to: https://www.lua.org/pil/11.1.html https://www.lua.org/pil/11.1.html
- krapp 3y agoYou're way too triggered by a programming language, dude. Move past it.
- zephraph 3y agoAnytime Lua comes up I'm reminded of John Earnest's Lil scripting language[1]. It's inspired by Lua and Q, built for Decker[2] which is a re-imagined version of HyperCard. Generally though, I love lua for its embeddability and am extremely happy anytime I see someone chatting about integrating it. Modding and scripting in games was a tremendous motivation for me to dig more into programming and these approachable languages are a core aspect of that. [1] https://beyondloom.com/decker/lil.html https://beyondloom.com/decker/lil.html [2] https://beyondloom.com/decker/ https://beyondloom.com/decker/
- tayistay 3y agoI'm currently using Lua as an extension language in my app [1]. Users can write their own custom UIs and DSP code. It's great how the Lua interpreter (and LuaJIT) allow you to provide your own memory allocator, so I can preallocate a region and do realtime-safe allocation within it. [1] https://audulus.com https://audulus.com
- iamcreasy 3y agoLooks cool. Is there any 5 min intro video introducing the app to the world?
- tayistay 3y agoThanks! There are a couple preview videos on the App Store and lots of stuff on YT: https://www.youtube.com/audulus https://www.youtube.com/audulus
- Fudgel 3y agoHey just an fyi, but the screenshot on the homepage is 1.2mb in size. Might wanna optimize it a bit.
- MarkusWandel 3y agoI once read through the entire Stroustrup C++ book and figured in one case, there is absolutely no way to make this work except for a secret, hidden variable in the class. Did a test compile and: There it was! OK, I get C++, done. Then I saw actual C++ programs. Whoa, how do you index into an array using a string? You don't of course, you overload the [ ] operator. Reading about Lua when it was newer I could foresee the same thing happening on steroids. Yes, the language itself is simple but what you can do with it - emulate almost any construct in any language - promises confusion. When it comes to readable code, sometimes "less is more" in terms of langauge features.
- notacoward 3y ago> OK, I get C++, done. > ... > When it comes to readable code, sometimes "less is more" in terms of langauge features. Please tell me that is meant as satire. There is no sane way to look at C++ and Lua and decide "less is more" would favor C++.
- PhilipRoman 3y agoI'm surprised people dislike 1-based indexing. I use both types of indexing commonly and never had an issue with it. The only issue I've come across in practice is lack of immutable tuples that could be used as table keys. I found myself either emulating this with nested tables or creating string identifiers for my multi-valued keys.
- fanf2 3y agoYou can also use light userdata for that kind of thing.
- ardit33 3y ago1 - based indexing is superior when thinking about actual collections, and not memory pointers. Most regular folks think of '1' index based. Eg. Most elevators (at least in NYC) start at floor 1, not 0. Once they start CS/programing classes they adjust to 0 thinking 0 - based indexing is better when dealing with pointers. But, none of us do today, (at least directly), and it seems that 0 based indexing is just an artifact of time. When I used Lua for professional programming, I thought that 1 - based index is just better. I saw my self doing a lot less (-1) calculations.
- ivirshup 3y ago> Most elevators (at least in NYC) start at floor 1, not 0. European buildings are generally 0-indexed: https://en.wikipedia.org/wiki/Storey#Numbering https://en.wikipedia.org/wiki/Storey#Numbering
- SoftTalker 3y agoExcept people call it the "ground" floor which makes sense, not the "zero" floor which does not.
- plugin-baby 3y ago0 makes sense when you consider -1 to be the first basement level.
- dbg31415 3y agoLua is a great little starter language. I love that so many games use it.
- Luafan21 3y ago[flagged]
- newobj 3y agoAll the <3 for Lua. Great language and great runtime(s) Want to also raise awareness of TypeScriptToLua, a fantastic TypeScript transpiler for Lua: https://typescripttolua.github.io/ https://typescripttolua.github.io/
- LelouBil 3y agoLua is great, I just wish it had typing
- michaelbuckbee 3y agoThis is timely - we've been gearing up on Lua as we're building an open-source web app firewall [1] on top of Redis and whatever framework, and it's been a great experience. Lua really unlocks some superpowers with Redis with respect to being able to chain multiple requests into a single call, handle some application logic, etc. 1 - https://wafris.org https://wafris.org
- luasux 3y ago[flagged]
- keyle 3y agoAnother option for your weekend plan to learn Lua is to do it with Love2D [0]. Really easy, well documented and fun framework that uses Lua. [0]: https://love2d.org/ https://love2d.org/
- shadowgovt 3y agoLove Lua. They even added a compile time feature to address the fact that c++ exceptions and setjmp / longjmp are undefined behavior when used together.
- xedrac 3y agoOnce neovim choose lua, I had a reason to pick up the language. I don't love it (mostly the 1-based indexing), but it's a lot better than vimscript.
- gsinclair 3y agoSame here. And I picked up LuaLatex at the same time, by coincidence.
- tomaspollak 3y agoIf you're looking for something like a "typed Lua" I suggest checking out Nelua (nelua.io). It's almost 100% regular Lua syntax and compiles to C, so you get the nice syntax plus speed, similar to Crystal/Ruby. It's not perfect but is interesting nonetheless.
- toastercat 3y agoJust gonna add to the Lua love. I was also introduced to it by LOVE2D and revisted it with Redbean. In terms of ergonomics, it is still my favorite programming language; I find it very easy to read and reason about, and I credit that to its minimalism. [1] https://love2d.org/ https://love2d.org/ [2] https://redbean.dev/ https://redbean.dev/
- wsc981 3y agoI also got into Lua mostly through LÖVE 2D (there’s also LÖVR for 3D with a similar API, but different devs). I’ve made a few small games using these frameworks in the past and as a hobby plan to continue making games with these frameworks, it’s fun! Harvard also has a nice course on game dev with LÖVE 2D and Unity, CS50. Can be followed online for free [0]. ——— [0]: https://www.edx.org/course/cs50s-introduction-to-game-development https://www.edx.org/course/cs50s-introduction-to-game-develo...
- Llamamoe 3y agoLua is a language in which I implemented a class system at a point at which I'd still be scratching my head over another language's syntax sugar. I love it.
- bdeshi 3y agoI find moonscript indispensable whenever I'm working with lua. https://moonscript.org/ https://moonscript.org/
- slmjkdbtl 3y agoWhen people talk about Lua's embeddability I hope they can just include a simple 20 line C snippet show how easy it is to actually embed Lua.
- fsloth 3y ago1. Download lua sources https://www.lua.org/download.html https://www.lua.org/download.html 2. Define your build for the sources (just compile them! No dependencies! Brilliant!) (don't compile lua.c and luac.c if you provide your own main) 3. Integrate with e.g. this main.cpp (if using c++ is your thing, just plain main.c or whatever is binary compatible): #include <stdio.h> extern "C" { #include <lua.h> #include <lauxlib.h> #include <lualib.h> } // Native function to be called in Lua static int add_numbers(lua_State* L) double a = luaL_checknumber(L, 1); double b = luaL_checknumber(L, 2); lua_pushnumber(L, a + b); return 1; } int main() { // Instantiate a Lua interpreter lua_State L = luaL_newstate(); // Load Lua libraries luaL_openlibs(L); // Register native function in Lua lua_register(L, "add_numbers", add_numbers); // Call native function in Lua luaL_dostring(L, "result = add_numbers(10, 20)"); // Read out the result of the function application lua_getglobal(L, "result"); const char* result = lua_tostring(L, -1); printf("The result is: %s\n", result); // Define a function in Lua luaL_dostring(L, "function concatenate_strings(s1, s2) return s1 .. s2 end"); // Call Lua function in native side luaL_dostring(L, "result = concatenate_strings('Hello, ', 'world!')"); // Read out the result of the function application lua_getglobal(L, "result"); const char* result2 = lua_tostring(L, -1); printf("The result is: %s\n", result2); // Close Lua interpreter lua_close(L); return 0; }
- xvilka 3y agoThere's Lua implementation [1] in pure Rust, by the way. [1] https://github.com/triplehex/piccolo https://github.com/triplehex/piccolo
- gishbunker 3y agoI've been in game dev for decades, and I've never understood the desire for lua. That's not totally true, it's easy to integrate and fast. But the language semantics and tooling leave a lot to be desired. I'm hopeful we get an embedded version of another language. Something as easy to embed as lua, but without the lua. I'd much rather write JavaScript or Rust or anything else.
- npteljes 3y agoI agree with you, I don't like Lua either. I especially don't understand why it's so good for embedding, and how people haven't implemented a subset of the project's original language as a scripting language, so that they don't have to write two very different syntaxes (and programming paradigms).
- Taywee 3y agoImplementing a subset of C or C++ as a scripting language is actually a lot of work, and is not fun to actually script in.
- npteljes 3y agoI have a hard time imagining that. PHP for example is fun to script in, and resembles a C/C++ more than Lua does. Of course fun is subjective, and I have no idea about the issues of embedding (why Lua works for that, and why other languages haven't got more traction).
- Taywee 3y agoWebAssembly is pretty good at filling the same niche, but it takes a lot more work to interface between the guest and host than Lua.
- sincarne 3y agoMy first real exposure to Lua was as the configuration language of imapfilter. Absolutely loved both. https://github.com/lefcha/imapfilter https://github.com/lefcha/imapfilter
- brabel 3y agoFor anyone looking for a HTTP server, or a Lua runtime with batteries included, have a look at the Mako Server[1]. It's really wonderful to work with. I've automated my house based on it. It includes everything you may need , from JSON to TLS, email to websockets... all in a tiny 3MB binary, including the Lua interpreter!! I run it on a Raspberry Pi and the process takes around 3MB of RAM. Just unbelievable comparing to anything like Node.JS or Java which would require a few 100's MB. [1] https://makoserver.net https://makoserver.net
- tetris11 3y agoDo you have a template of your configuration you could share somewhere?
- brabel 3y agoYou don't really need a template, I would say. See the tutorials for what it looks like writing a server: https://makoserver.net/tutorials/ https://makoserver.net/tutorials/ Start with this: https://makoserver.net/articles/HTML-Forms-and-LSP-for-Beginners https://makoserver.net/articles/HTML-Forms-and-LSP-for-Begin... The docs you should read are mostly from the Barracuda Application server, which Mako is built on: https://realtimelogic.com/ba/doc/?url=lua.html https://realtimelogic.com/ba/doc/?url=lua.html You can even try this online: https://tutorial.realtimelogic.com/Lua-Types.lsp https://tutorial.realtimelogic.com/Lua-Types.lsp Click on "Okay, Got it" big button and you can follow along the tutorials, edit code on a demo server, which is how I actually developed my stuff... I actually used a mix of the online editor and editing the Lua files via SSH in emacs, via TRAMP. I highly recommmend either approach.
- rcarmo 3y agoThis is pretty amazing. I have a lot of Lua resources over at https://taoofmac.com/space/dev/lua https://taoofmac.com/space/dev/lua, adding it there.
- brabel 3y agoI think you accidentally added it to a new category, "Runtimes", instead of using the existing "Runtime" which had several entries? EDIT: the Lua Lanes link is broken... the new location seems to be this: https://lualanes.github.io/lanes/ https://lualanes.github.io/lanes/
- humility 3y agoThe author fails to mention a super use case for lua which is celebrated by productivity nerds like myself - configuration. I use neovim, hammerspoon which can be configured using lua richly. In a world of ever complicated software, I think lua is coming out as a gold standard for configuration files.
- mble_ 3y agoHey, I wrote this! Thanks for all the additional warm feelings about Lua on its 30th birthday year. I have a "second part" in the works on this about implementing something a little more advanced in Lua, and some more exploration of Lua's warts.
- account-5 3y agoAs a complete lua noob, can you run lua without C or C++? I've always thought of it as an embedded scripting language. I intend to learn it because of that but what can it do on its own?
- frankohn 3y agoLua can be run without using C or C++ just by running the interpreter. The shortcoming is that the standard library is intentionally very limited so there is very little you can do using Lua alone. The main path is to implement with C or C++ bindings to the libraries you want to use and expose them as Lua module. This is the way Lua is supposed to be used.
- account-5 3y agoMight be a little beyond me then since I've not experience with either C, or C++. Wouldn't know where to start.
- Falkon1313 3y agoYes, there's a command line. Check LuaBinaries for that. Also, if you want a fun way to play with it, see the LÖVE game engine. You can be making your own simple 2D games in next to no time. And I think that's a nice playground for trying out a language. - https://love2d.org/ https://love2d.org/ - https://love2d.org/wiki/Getting_Started https://love2d.org/wiki/Getting_Started
- bodge5000 3y agoI'm not all that familiar with Lua so happy to be corrected here, but from what I know it's really small, really fast and really simple (to use), which makes me wonder why it's not used more often. Like I get it's not gonna be as fast as C, but apparently it's about as fast as C++. And it's not as simple as Python, but from what I've seen it's not far off. What's the catch?
- toastal 3y agoLack of types hurts. Then there's the 1-base indexing that bothers many. The whole "tables" concept is kinda weird—and this makes more complex kinds of programming difficult/unergonomic. Luckily like JavaScript, there are a wealth of languages that compile to Lua to smooth over missing language features. One outlier feature is that Lua supports tail call optimization.
- jshmrsn 3y agoThere’s a lot of surface area to cover. In my opinion, the main thing that holds Lua back from wider adoption is the thing that makes it useful for its niche case. That is, the runtime and standard library are extremely small, making it easy and lightweight to embed in programs across a variety of platforms. However, that minimalist runtime and standard library also mean that it’s hard to deliver Lua libraries and frameworks without requiring native code extensions (e.g. any kind of networking and serious file system interactions) would require platform-specific extensions. Additionally, because Lua is so simple (for example there is no built-in concept of classes), the way to write code in Lua is quite open-ended. Many Lua users use their own or one of many prebuilt class systems. Using code from someone’s library might mean pulling in its custom class system and interacting with it as well. Custom class systems can be somewhat magical and involve metatable and suddenly things aren’t very simple anymore. Lua is also just a bit odd to use with one based indices, tables being kinda-sorta arrays if you use them in just the right way, needing to use pairs vs. ipairs in loops, variables being global by default if you forget to type “local” (unless you use Lua strict, and also all the libraries you want to use are compatible).
- diego_moita 3y ago> What's the catch? It doesn't have big sponsors. Java had Sun and Google. Python, Kotlyn and Go have Google. C had AT&T. Basic and C# had Microsoft. Objective-C and Swift had Apple. FORTRAN and Cobol had IBM. Javascript and Rust had Mozilla, ... Lua has a lot of small sponsors but no big one. Very few languages succeed just on their merits, without big sponsors.
- fasteo 3y agoMentioning Openresty[1] (nginx + Lua + LuaJIT) is a must. I have been running production code with Openresty for the last 15 years. Smooth sail. [1] https://openresty.org/en/ https://openresty.org/en/
- qalmakka 3y agoI hate how people are desperately trying to embed (C)Python in their programs just to hop on the hype-driven Python bandwagon instead of doing the sane choice and just relying on Lua, which was designed to begin with to do so. Lua is simple enough it can be thought efficiently in a few hours, and it's just so trivial to embed. In comparison, CPython often requires to implement most of your code logic as a library and then load it into the interpreter, which is less than ideal.
- UncleEntity 3y agoI used to poke at the python API in blender and most of the wrapper work was done with magic. Very rarely would you have to implement any custom C code aside from what you’d have to do with any other embedded scripting language to deal with the differences between the two languages and/or blender wonkyness. I’ve also played around with lua embedding a bit — I just like python more so didn’t do anything with it. I do remember that I got it to work as an experiment but I would have had to start writing some serious C code (the kind you claim is unnecessary) to do anything useful with it and I’m pretty sure the maintainer of the game would have been opposed to being able to script things. But, I’m one of those people who actually enjoys wrapping C libraries to use in python so…
- PicassoCTs 3y agoThe problem with lua - in my opinion is, the lackluster infrastructure for shared code.Lua rocks are version crippled and hard to integrate, bloat the code pretty fast (every instance has a full copy of all library code). Its also problematic that there are no default implementation for a API-Library layer. Which creates funny little re-implementations from v[1] to v.x and what have you not.