
What's New in Lua 5.4 - benhoyt
https://lwn.net/SubscriberLink/826134/b1b87e4187435cec/
======
gautamcgoel
Lua is a language I really want to love. I like the emphasis on simplicity and
minimalism, and the Scheme-like semantics, which mix imperative and functional
styles, really hits a sweet spot IMO. LuaJIT is a crazy impressive feat of
software engineering. However, there are some specific issues which hold Lua
back IMO. First, as LuaJIT author Mike Pall famously noted, the Lua authors
constantly break compatibility between releases. Lua is really several
different, incompatible languages (Lua 5.1, 5.2, etc). LuaJIT is still at Lua
5.1, IIRC. Second, there are a bunch of minor nitpicks (1-based-indexing,
anyone?) which turn off a bunch of people. Lastly, because Lua is so minimal
and focused on portability, people end up reimplementing their own
abstractions (such as object systems) from scratch, further fracturing the
ecosystem. I think there's a space for a new project, which takes LuaJIT as a
starting point and addresses some of the issues I described. It would also be
great if this hypothetical new language had better support for Unicode and
concurrency.

~~~
pansa2
> I think there's a space for a new project, which takes LuaJIT as a starting
> point

Unfortunately, LuaJIT is tightly-coupled to the Lua language and its code is
very complex. I'd be surprised if anyone other than Mike Pall was able to
retarget it to support a different language.

Also, is JIT compilation really necessary for a scripting language? Projects
like the PyPy JIT for Python have seen little adoption, and many platforms
(e.g. iOS and game consoles) don't support JIT at all.

~~~
saagarjha
PyPy JIT is unsuccessful because CPython makes it hard for PyPy, not because
people don't want it. When there's a need and support for it, we have
extremely good JITs spring into existence–JavaScript has at least three, for
example.

~~~
sitkack
CPython needs to grow up and not hoard the ecosystem. A successful PyPy is a
successful Python.

~~~
setr
I don't think they're doing anything in particular to hinder PyPy -- the
damage was done long back, when things like the C-API exposed _too much_
detail on CPython internals that severely limit PyPy's potential to replace it
with more optimal systems/datastructures

~~~
sitkack
The issue with crowding out alternative Pythons is a socio-political one. The
C-API issue is as well, as you said Python extensions are over coupled to the
runtime. ctypes and subsequently cffi fixed this 10+ years ago.

1\. Decouple the extension mechanism. Use cffi

2\. Modularize the batteries

Each alternative Python has to re-implement large swaths of the stdlib. The
code is the spec in Python.

Stackless got the PyPy treatment before PyPy even existed. Besides PyPy, we
now have graalpython, rustpython and ...

[https://github.com/beeware/ouroboros/issues/21](https://github.com/beeware/ouroboros/issues/21)
points to a python stdlib I had never heard of,
[https://github.com/pfalcon/pycopy-lib](https://github.com/pfalcon/pycopy-lib)

The point is, the core CPython devs need stop being so selfish with their
toys. The greater Python ecosystem is diverse in spite of their actions not
because of it.

------
didip
I always thought Lua would be great for config files. Better than YAML even,
since it's an actual language.

Imagine if Kubernetes config files are actually Lua files.

~~~
xud
I don't think it's a good idea to make config files complicate. I don't want
to run a debugger to know how my configuration file works.

~~~
krapp
Using Lua tables alone would be anything but complicated. The syntax is almost
the same as JSON.

You just have to practice self-discipline and not let Turing creep take over.

------
blibble
I used to quite like Lua, but got quite consistently wound by up several
things

    
    
        - global variables by defauilt
        - weird choice of certain operators (~= for not equal)
        - arrays start at 1
    

(fixed yet?)

~~~
ebg13
~= and 1-indexing are only weird if you haven't seen them before. MATLAB uses
them as well.

~~~
sk0g
Isn't "weird == not seen it before" anyway? I get what you're trying to say,
but MATLAB is not really a programming language SWEs would use, so if that's
the best example you can think of, Lua's bound to confuse most people in the
industry.

May work better for mathematicians, non-SW engineers etc, but I wouldn't know.

~~~
ebg13
> _I get what you 're trying to say, but MATLAB is not really a programming
> language SWEs would use_

It may not be a language that website jockeys use, but "I don't use it
therefore probably no one does" is almost never correct. MATLAB is huge in
state machine and dynamic systems programming as well as being the original
commercial powerhouse for linear algebra algorithms.

~~~
sk0g
I meant to say most SWEs, which you seemed to have inferred anyway.

Why do you think that's wrong? I simply claimed MATLAB is much more commonly
used by scientists and non-SW engineers. Most SWE jobs are in B2B, web
development, embedded, etc fields. Which one of these sees a lot of MATLAB
usage?

Maybe don't resort to insults straight away too.

~~~
ebg13
> _Most SWE jobs are in B2B, web development_

Citation?

> _embedded, etc fields. Which one of these sees a lot of MATLAB usage?_

Both embedded and etc. MATLAB is used widely in signal processing and controls
software.

> _Maybe don 't resort to insults straight away too._

Sorry. I get annoyed when someone pretends that Software==Websites as if any
of our trusted electronics are designed or programmed in javascript.

------
Analemma_
I've heard that a major use case for Lua is to enable scripting in game
engines - for something like that, it sounds perfect, because the entire
runtime is just a couple thousand lines of C with few dependencies, that can
be literally copy-pasted into your codebase if need be.

But honestly, I can't recommend Lua for any other use case. You'll be chugging
along and then run into a brick wall when you need e.g. real regexes instead
of Lua's comparatively crippled pattern matching, or a networking library that
isn't hosted on one professor's personal web page that hasn't been updated in
years. Take it from someone who had to throw out and port a bunch of Lua
scripts when they just couldn't keep up with new business requirements: Python
or Perl or Ruby is almost always a better choice.

~~~
sago
> I've heard that a major use case

It was. At peak perhaps 10 years ago. It is telling that the game engine
citation in that article is from 2009.

Now the ecosystem of game engines is very different. Very few games are
written in raw C/++ and have to have their own tiny scripting language
packaged. They are mostly based on more established engines. 'Small studios'
have gone, niched out of end-to-end dev, or re-invented as the 'indie game'
world, and pretty much none have their own multi-game engine.

In fact, I've only come across Lua used in Pico-8 gamejam games in the last 2
yrs, personally. (Though I'm retired now.)

It was a phenomenal language for gamedev. I commissioned a Lua consultant to
extend the language in a small way for a game, I ended up paying for about
half the hours I expected.

~~~
pansa2
> It was. At peak perhaps 10 years ago.

Yeah, I wondered if that was still the case. Most of the examples I can find
of “games that use Lua” are indeed around 10 years old.

Are more recent games using different scripting languages, or are they
designed to not use a scripting language at all?

~~~
anonymoushn
Some more recent titles I know of are Pocket Rumble and Blue Revolver.

A lot of game devs use frameworks or engines that strongly encourage or
require the user to use C#, javascript, gdscript, or gml. Solar2d and love2d
use Lua but don't seem very popular. Fewer people are throwing together their
own thing in C++ and putting Lua inside.

------
edsiper2
Lua is just great. In Fluent Bit[0] we expose Lua filter capabilities. So end-
users can write their own scripts to manipulate record logs and accommodate
keys/values easily with a simple programming logic:

\-
[https://docs.fluentbit.io/manual/pipeline/filters/lua](https://docs.fluentbit.io/manual/pipeline/filters/lua)

I am happy to see performance is being improved, as of now we stick to LuaJIT,
since our use case is pretty simple we have not found a good reason to move
away from it.

[0] [https://fluentbit.io](https://fluentbit.io)

------
Pxtl
I love Lua for its architecture and goals, but not for its linguistics... and
this is more of the same. The platform is getting even better, but I feel like
the language is getting worse. <const> and <close> are kinda hideous, aren't
they?

~~~
aquova
I had heard that Lua was adding const support, which I was excited for, but I
hadn't seen the syntax until now. I don't care for it. I'm guessing this is
due to ambiguity as to whether variables declared as const would be local or
global, but I would rather have something like

const x = 1

local const y = 2

over what they're adding.

~~~
ufo
The problem with putting the "const" first is that it is ambiguous when there
is more than one variable. For example, suppose that you want to open a file
and test for errors:

    
    
        local f <close>, err = io.open("foo.txt")
        if not f then error(err) end
    

vs

    
    
        local <close> f, err = io.open("foo.txt")
        if not f then error(err) end
    

In the first version it is clearer that only the "f" variable is marked as a
to-be-closed variable. The second version looks nicer when there is a single
variable but is more confusing when there are multiple variables.

~~~
Pxtl
Either way, why are the <> necessary?

    
    
        local f close = io.open("foo.txt")
    

seems fine.

~~~
ufo
That wouldn't work because it is already valid Lua code with a different
meaning. Lua parses it as a declaration of a local variable called f followed
by an assignment to a variable named close:

    
    
        local f
        close = io.open("foo.txt")
    

Despite the lack of semicolons, Lua is a free-form language and newlines are
treated the same as any other whitespace character.

------
rjeli
Very nice, congrats to the Liz team :)

The new `const` and RAII/resource scope language features remind me of the
golang discussion yesterday, someone linked Pike saying JS/TS, C++, Hack, etc
keep borrowing features from each other. Of course we won’t fully converge on
some perfect syntax any time soon, or ever, but we seem to be settling into a
general consensus on syntax in general, and semantics of dynamic languages.

------
tedd-the-tiger
A link to subscriber-only content on a public news site?

