News for hackers. Stuff that matters.
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.