News for hackers. Stuff that matters.
Re:A History of Lua (2001) by amilios on Wednesday August 10, 2022 @02:30AM (#32408411)
Honestly Lua is one of those languages that seems decently nice to use, fairly performant, and just makes me wonder why it hasn't been adopted for use more broadly in domains beyond just like being embedded in game engines. Am I missing something?
Re:A History of Lua (2001) by cardanome on Wednesday August 10, 2022 @04:08AM (#32409078)
Lua just doesn't have the marketing other languages have. No big corporation behind it.

It does not have any exciting or frequent releases. It is basically done as a language since 5.1. New versions can be safely ignored, especially when you want to use LuaJit.

These days people simply expect lots of churn and frequent releases to keep the hype for a language up.

Also the current trend it towards static type checking which is especially hard to implement for Lua. There are some solutions for gradual typing but there is not exactly first-class support for that.

The small standard library might also have been a problem in the past but these days I would argue that JS has normalized that part quite a bit.

Re:A History of Lua (2001) by rahkiin on Wednesday August 10, 2022 @03:22AM (#32408731)
I’ve worked in a large Lua codebase, and its lack of any types gets very cumbersome. It is also non-trivial to get the full performance and by doing so lose some of the nicer features. For example, creating tables causes an allocation which is slow, so forget about using tables for vector types. These tables could have bad a metatype for operator overloading, but metatables cause multi-level lookups which is also slower.

I could use it for some light scripting, but definitely would not write whole projects in it.

Re:A History of Lua (2001) by otikik on Wednesday August 10, 2022 @06:25AM (#32409856)
> lack of any types gets very cumbersome

You might be interested in Teal ("the typescript for Lua") https://github.com/teal-language/tl

Re:A History of Lua (2001) by emehex on Wednesday August 10, 2022 @06:45AM (#32409969)
I find in super frustrating when a language doesn’t put a representative view of it’s syntax front and center in the README… (as a QuickStart or something)!
Re:A History of Lua (2001) by nequo on Wednesday August 10, 2022 @07:22AM (#32410189)
The tutorial they link in the intro is quite good:

https://github.com/teal-language/tl/blob/master/docs/tutoria...

Re:A History of Lua (2001) by emehex on Wednesday August 10, 2022 @07:48AM (#32410387)
Agreed! I just find it unusual that this isn’t “front and center” (as I said)
Re:A History of Lua (2001) by otikik on Wednesday August 10, 2022 @02:08PM (#32416159)
The nice thing about this particular case is that you can actually do something to fix this problem that is super frustrating for you!

You can send a PR!

Re:A History of Lua (2001) by spc476 on Wednesday August 10, 2022 @05:10AM (#32409448)
At work, I use Lua (and LPEG) to process SIP messages for the Oligarchic Cell Phone Company, processing calls in real time, and only once in the seven years it's been running did I have to tune the code. It certainly works for us.
Re:A History of Lua (2001) by rahkiin on Wednesday August 10, 2022 @05:38AM (#32409575)
That’s great :) I do think it has its place.

We ran >200k lines of Lua for a 3d game at >60fps. We could not do allocations on the hotpath, or we would run out of our frame budget (which was around 1ms). Games are very hard to auto-test when not built with that in mind from the ground up, so any change to the code might unknowingly break any caller, and we would only know for sure once the game runs. Sadly the code base is 20 years old.

Re:A History of Lua (2001) by samatman on Wednesday August 10, 2022 @10:29AM (#32412581)
You mentioned in a sibling comment that this was using LuaJIT, do you know if it was before the allocation sinking optimization was added?

At some point (2.1?) LuaJIT added a peephole interpreter optimization which can follow a simple constructed table for awhile, and if it's never stored, the values it's conveying are just put on the stack.

I'm pretty fearless with creating transient tables, and run enough profiling to be moderately confident that the allocation sink is keeping that from providing memory pressure.

There's a larger thing here about the JIT being temperamental and having to kind of learn its moods, but: it's faster as an interpreter than other choices by a matter of multiples, and when the JIT works, it positively screams.

Re:A History of Lua (2001) by rahkiin on Wednesday August 10, 2022 @03:22PM (#32417147)
Honestly I am not sure. We were using the LuaJIT interpreter because JIT is not allowed on consoles or phones.
Re:A History of Lua (2001) by kgeist on Wednesday August 10, 2022 @06:15AM (#32409796)
>For example, creating tables causes an allocation which is slow, so forget about using tables for vector types

I once added vector4 as a primitive type in my fork of Lua (to avoid allocations altogether) - it was surprisingly easy to add, took me a weekend.

Re:A History of Lua (2001) by rahkiin on Wednesday August 10, 2022 @07:39AM (#32410311)
We were using LuaJit which is a whole other beast.
Re:A History of Lua (2001) by babarock on Wednesday August 10, 2022 @08:54AM (#32411102)
Lua used to fill a niche very similar to Javascript: small lightweight OOP language that focuses on being embedded in a larger C program. Javascript won this war, mostly based on the explosion of the Web and the insane optimization work that was put on JS engines during the late 2000s.

JS ate Lua's cake, not on pure technical merits (the two languages are very similar) but because of their respective environments.

Re:A History of Lua (2001) by runevault on Wednesday August 10, 2022 @10:20AM (#32412431)
For reference JS isn't actually object oriented, it is a prototype language. You can fake it being OOP within that style, but it isn't really OOP, even if you can code in it that way.
Re:A History of Lua (2001) by babarock on Wednesday August 10, 2022 @12:21PM (#32414527)
If we want to be pedantic, prototypal inheritance is a kind of OOP[1]. What you're talking about is referred to as "classical OOP" (OOP using classes).

[1]: https://en.wikipedia.org/wiki/Prototype-based_programming

Re:A History of Lua (2001) by Atomskun on Wednesday August 10, 2022 @11:38AM (#32413797)
Just like Lua, hence their similarities.
Re:A History of Lua (2001) by runevault on Wednesday August 10, 2022 @12:05PM (#32414279)
That's fair. I didn't realize Lua was also a prototype language as I've barely looked at it. Been curious but it never fit my current set of curiosities.
Re:A History of Lua (2001) by otikik on Wednesday August 10, 2022 @06:24AM (#32409848)
> it hasn't been adopted for use more broadly in domains beyond just like being embedded in game engines

It might not be in your particular awareness bubble. Parts of the infrastructure that transmitted the request that allowed you to post your comment (the most prominent one is Nginx, but routers and switches with Lua-scripting do exist).

In my case, I work in Kong (which has a very healthy Lua plugin), I edit my code with Neovim (Lua is its main plugin-writing language). So I kind of "live and breathe" Lua. Still I am aware of other pieces of software that embed it that I don't use (Redis, Wireshark, even Wikipedia supports Lua on its templates).

One interesting characteristic of the language is that it is "barebones". It doesn't have features that are "built-in" in other languages. Things like parsing a json file or making an http request. As a result, the "host program" needs to provide those. Which ends up making "flavor Lua" - Lua with certain assumptions about the host. In this way, Lua is not "one big continuous landmass", but instead an "archipelago". This lack of central point makes it impossible to attach a "marketing/hype machine" to it. It's more like a silent revolution, the language stands on its own merits, for better or worse.

Re:A History of Lua (2001) by orthoxerox on Wednesday August 10, 2022 @04:10AM (#32409090)
No batteries included. It's designed to be embedded as a scripting language, so its stdlib is tiny. People managed to write web frameworks in Lua, but it's hard to snowball a good package collection when you've got Python and node next door.
Re:A History of Lua (2001) by leephillips on Wednesday August 10, 2022 @03:37AM (#32408832)
Lua and lualatex allow access to TeX internals and (relatively) easy programming of typeset documents: https://lwn.net/Articles/731581/.

Lua is the official language for writing Pandoc filters.

And, of course, NeoVim.

These are the contexts in which I use it; its embedding into TeX and Pandoc provides some powerful capability.

Re:A History of Lua (2001) by ggm on Wednesday August 10, 2022 @03:52AM (#32408954)
> Lua is the official language for writing Pandoc filters

Given pandoc is written in haskell.. an interesting choice. I guess investing in a DSL syntax was a cost too far.

Re:A History of Lua (2001) by lenkite on Wednesday August 10, 2022 @03:52AM (#32408957)
No static typing, No ergonomic language features like lambdas, No functional programming, magic nil behaviour, global by default, no integer type (not sure if this was addressed), index tables instead of having a proper array/list type, missing switch, No assigning operators..the list goes on and on.

It was an average PL a decade ago and it is simply mediocre now. Only superb implementations like LuaJIT prop the language up.

I would prefer writing Enterprise Java (gasp) over writing Lua code for anything >5k lines. It's OK for small scripts but rapidly breaks down for anything larger. It's a bit funny that a complicated system PL like Rust is more comfortable to code than Lua.

Only using Lua personally nowadays due to Neovim and now that https://github.com/noib3/nvim-oxi has come out, I am going to use it even less.

Re:A History of Lua (2001) by citrin_ru on Wednesday August 10, 2022 @04:59AM (#32409404)
> magic nil behaviour

What is magic in Lua nil? nil being false makes nil different from other non-boolean types, but it is both intuitive and convenient (I don't know a language where null/nil/undef are true in boolean context). What makes Lua a bit different from other script languages is that 0, "0", "", {} e. t. c. are not false in Lua. But it allows to avoid mess with truthy/falsy values we have in other script languages.

Re:A History of Lua (2001) by edflsafoiewq on Wednesday August 10, 2022 @05:12AM (#32409462)
nil is like the absence of a value, reified into a value. Reading a variable that doesn't exist produces nil, and assigning nil deletes the variable.
Re:A History of Lua (2001) by DemocracyFTW2 on Wednesday August 10, 2022 @05:59AM (#32409710)
Having a value that, when assigned to a variable or property, elides or deletes it is actually a desirable feature in MHO. Arguably, JavaScript's `undefined` should act like that, or nowadays more probably a well-known symbol. It's at any rate a nuisance that introducing one cavalier 'simplicity' (you can access `d.x` even when it does not exist, but you'll get `undefined` as value) causes so much accidental complexity (now you have to distinguish between so many fringe conditions (does `d` have a key `x`? does `d.x == undefined` mean `x` is set on `d`?). OTOH if you don't have a value that deletes a key from an object, then you'll have to special-case that operation because `delete d.x`, apart from being revolting syntactically, only exists as a syntactical construct.
Re:A History of Lua (2001) by lenkite on Wednesday August 10, 2022 @06:21AM (#32409830)
Lua tables make no distinction between a table value being nil and the corresponding key not existing in the table necessitating hacks like: http://lua-users.org/wiki/StoringNilsInTables
Re:A History of Lua (2001) by edflsafoiewq on Wednesday August 10, 2022 @06:32AM (#32409893)
Yeah, that's the point of nil. If you're trying to store it in a table, you're just fighting the language. Is there a good motivation for doing that?
Re:A History of Lua (2001) by samatman on Wednesday August 10, 2022 @10:49AM (#32412940)
I've done this on two rare occasions: round-tripping 'null' in JSON and 'NULL' in database queries.

My solution, which was perhaps overly cute, was a table canonically named No, which is callable such that No(nil), No(false), and No(No) all return true.

So I could say

   if No(value) then
When I needed to do conditional logic which excludes those reified null values, which isn't often.
Re:A History of Lua (2001) by lloeki on Wednesday August 10, 2022 @05:45AM (#32409626)
> What makes Lua a bit different from other script languages is that 0, "0", "", {} e. t. c. are not false in Lua.

In Ruby only nil and false are falsey, everything else is truthy.

Re:A History of Lua (2001) by Banana699 on Wednesday August 10, 2022 @06:27AM (#32409864)
Same as Scheme.
Re:A History of Lua (2001) by actondev on Tuesday August 16, 2022 @11:27AM (#32484078)
nil is not fasley in Scheme. There is no falsey is sense that only #f is false :)
Re:A History of Lua (2001) by Benjamin_Dobell on Wednesday August 10, 2022 @04:53AM (#32409359)
What do you mean by no lambdas exactly? Lua supports anonymous functions and they're in fact closures, since those functions capture variables from their outer scope.

I use functional programming extensively in Lua also. Could you elaborate on what it doesn't permit?

Integers were introduced in 5.3.

Assigning operators? It has metatables, you can absolutely implement your own operators.

If you want static typing you can use my IDE: https://github.com/Benjamin-Dobell/IntelliJ-Luanalysis/

Granted, my IDE is incredibly opinionated and not for everyone.

Also, Lua is not my favourite language to use, doesn't even make top 3. However, the robustness of its design, considering its simplicity, is incredibly elegant.

Re:A History of Lua (2001) by lenkite on Wednesday August 10, 2022 @06:18AM (#32409810)
Ooh, didn't know about Luanalysis, thanks for creating it! Going to check that out.

I personally found functional programming non-ergonomic in Lua considering that anonymous functions are very verbose and there is no map/filter/etc in the standard language/library unlike just about every PL these days. You need to pull stuff in for basics and everyone does it slightly differently leading to non interoperability.

Sorry, I meant shorthand assignment operators. Those are quite convenient.

Re:A History of Lua (2001) by edflsafoiewq on Wednesday August 10, 2022 @05:07AM (#32409431)
> Assigning operators

+=

Re:A History of Lua (2001) by Benjamin_Dobell on Wednesday August 10, 2022 @05:13AM (#32409469)
Ah, thanks for the clarification. It does indeed lack those. I tend to call those short-hand operators since I guess technically `=` is an assigning operator.

Personally, I don't have a strong opinion on their omission, however I know some prefer the simplicity.

Re:A History of Lua (2001) by maegul on Wednesday August 10, 2022 @04:08AM (#32409080)
> now that https://github.com/noib3/nvim-oxi has come out, I am going to use it even less.

Woah, interesting ... provided there's success and uptake with this ... I'm imagining it could lead to a really slick and responsive editing experience that those of using (at least) slightly sluggish plugins might have been missing for a while now.

Re:A History of Lua (2001) by blueflow on Wednesday August 10, 2022 @04:54AM (#32409364)
> No ergonomic language features like lambdas

x = function(a,b) return a+b end

x(4,5)

Is that not a lambda?

Re:A History of Lua (2001) by wruza on Wednesday August 10, 2022 @05:38AM (#32409577)
GP probably meant a short syntax for it, thus ergonomic. When you use lambdas a lot, this “function() end” part may become annoying.
Re:A History of Lua (2001) by nielsbot on Wednesday August 10, 2022 @05:18AM (#32409494)
There is Luau, however.

"Luau (lowercase u, /ˈlu.aʊ/) is a fast, small, safe, gradually typed embeddable scripting language derived from Lua."

https://luau-lang.org

Re:A History of Lua (2001) by fanf2 on Wednesday August 10, 2022 @04:48AM (#32409338)
Lua has had proper lexical closures and function expressions since 5.0 https://www.lua.org/manual/5.1/manual.html#2.5.9

It has had 64 bit integers since 5.3 https://www.lua.org/manual/5.3/manual.html#2.1

Re:A History of Lua (2001) by DayDollar on Wednesday August 10, 2022 @08:11AM (#32410603)
i dont know lambda was really easy to do it by onself.

filterdResult =

       lambda(Table,

        function(i)

          if i ~= 42 then return i; end

        end,
          setToFilterOut = {}
          function filterOutIfInSet(i, filterSet)


            if not filterSet[i] then return i; end

           end

        etc..
        )
Combined with properly, once defined decision sets this is really powerful. Almost of all my game decisions are lambdas mit once global defined decisionsets for unittypes. If i want to change something, for a unit, i only insert its type into the corresponding decision set and suddenly it has that property. Like dropping a smooth stone into a pond without ripples.

Its similar simple to the javascript implementations, once functions are firstclass members.

Functional programming would be harder. You need alot of meta table, result hashing for that a + b hash(a) + hash(+) + hash(b) -> Resultlookup. So its doable, by the law of look it up yourself, it has been done.

Re:A History of Lua (2001) by sam_lowry_ on Wednesday August 10, 2022 @02:36AM (#32408442)
It is heavily used in some niche domains. Openresty comes to mind next to game dev.

OTOH, it is too close to C and not really a breakthrough language like Rust or Go. As far as style and brevity goes, Lua wins hands-down, but who cares?

Re:A History of Lua (2001) by aredox on Wednesday August 10, 2022 @03:08AM (#32408647)
It's also used as the main scripting language in NeoVim.

But if you want something more "out there", it's also the main language used to program open-source radio control remote (openTX) for drones/planes/gliders: https://medium.com/rc-soaring-digest/ive-got-the-power-opent... https://github.com/jfrickmann/SoarOTX

Re:A History of Lua (2001) by shadowofneptune on Wednesday August 10, 2022 @03:47AM (#32408910)
1. Each minor version of the language is distinct enough to be incompatible with the previous version. A project embeds one specific version of Lua and never upgrades it.

2. Since it is embedded, it has a pretty small standard library that the embedder can remove or extend.

Both lead to Lua communities being more about individual projects which embed it.

Re:A History of Lua (2001) by frou_dh on Wednesday August 10, 2022 @06:48AM (#32409988)
A good example of this is the Max/MSP audiovisual environment, which, amongst other things, has both Lua 5.1 and an ancient JavaScript engine (JaegerMonkey from Firefox 4) embedded in it to this day.
Re:A History of Lua (2001) by spacechild1 on Wednesday August 10, 2022 @04:09AM (#32409089)
Lua has been designed as an embeddable scripting language and it is used as such in various domains and programs. It's not really suited for developing large applications, though.
Re:A History of Lua (2001) by citrin_ru on Wednesday August 10, 2022 @04:41AM (#32409309)
You can write largish standalone application in Lua and it is not always a poor choice - Prosody [1] first comes to mind. But qualities which make it a good embedded language make it less _attractive_ for other uses.

Lua has very simple syntax and small stdlib which allows its implementation to be very small - you can add Lua to your application and not increase its size significantly. But when the size is not a concern most programmers prefer languages with rich, powerful syntax lots of features and batteries-included stdlib (which is completely opposite of Lua).

[1] https://prosody.im/

Re:A History of Lua (2001) by intelVISA on Wednesday August 10, 2022 @03:56AM (#32408988)
Some games use it for a UI/scripting layer but it's a nightmare to work with for anything complicated.
Re:A History of Lua (2001) by jhoechtl on Wednesday August 10, 2022 @05:21AM (#32409503)
Index by 1
Re:A History of Lua (2001) by remram on Wednesday August 10, 2022 @08:56AM (#32411124)
This was such a weird decision. Lua is meant to be embedded, meaning it will have to call application code where indexes start at 0. Why make the Lua indexes not match?
Re:A History of Lua (2001) by shadowofneptune on Wednesday August 10, 2022 @10:28AM (#32412569)
Some big influences on the syntax are Modula and Fortran. The first allows you to start an array with any index you like, the second starts it with one. As the article says, it started as a data language for engineers who may have been familiar with Fortran. The C-like languages were not as overwhelmingly common back when Lua started, as well.
Re:A History of Lua (2001) by pull_my_finger on Thursday August 11, 2022 @12:11AM (#32421502)
> When we started Lua, the world was different, not everything was C-like. Java and JavaScript did not exist, Python was in an infancy and had a lower than 1.0 version. So there was not this thing when all the languages are supposed to be C-like. C was just one of many syntaxes around.

> And the arrays were exactly the same. It’s very funny that most people don’t realize that. There are good things about zero-based arrays as well as one-based arrays.

> The fact is that most popular languages today are zero-based because of C. They were kind of inspired by C. And the funny thing is that C doesn’t have indexing. So you can’t say that C indexes arrays from zero, because there is no indexing operation. C has pointer arithmetic, so zero in C is not an index, it’s an offset. And as an offset, it must be a zero — not because it has better mathematical properties or because it’s more natural, whatever.

> And all those languages that copied C, they do have indexes and don’t have pointer arithmetic. Java, JavaScript, etc., etc. — none of them have pointer arithmetic. So they just copied the zero, but it’s a completely different operation. They put zero for no reason at all — it’s like a cargo cult.

https://habr.com/en/company/vk/blog/459466/

Re:A History of Lua (2001) by renox on Wednesday August 10, 2022 @02:49PM (#32416724)
This. I was doing Ethernet packet assembly/disassembly with one part in C, the other in Lua.. Let's just say that I'm not a Lua fan to say the least.
Re:A History of Lua (2001) by hulitu on Wednesday August 10, 2022 @06:52AM (#32410018)
I was compiling a game which needed Lua. Lua used its own make system without config files which failed with an obscure error message. Since then i avoid it.