Skip to content

Backport Lua 5.5 global keyword, named varargs tables and other various patches/functions #2361

@Duck375

Description

@Duck375

Changes since 5.4: https://www.lua.org/manual/5.5/readme.html#changes

  • global variables declaration
    Provides more control over global access inside scope (allows to restrict to which global variables scope has access to, without copying _G)
    Allows to permanently lock certain variables using <const> attribute (unlike declaration via _G, global keyword enables variable to have attributes)
    Explanations and examples: https://lua.org/manual/5.5/manual.html#2.2

  • named vararg tables
    "A vararg table in a variadic function can have an optional name, given after the three dots. When present, that name denotes a read-only local variable that refers to the vararg table. If the vararg table does not have a name, it can only be accessed through a vararg expression."

local function test(... myargs) --notice that there is no comma
print("... is", ...)
print("aka", myargs)
end

test(1,2,3,4,5,6)
-->... is 1 2 3 4 5 6
-->aka table: 0x55e97e6eee30
  • table.create(nseq [, nrec]) function
    Parameter 'nseq' is a hint for how many elements the table will have as a sequence. Optional parameter 'nrec' is a hint for how many other elements the table will have; its default is zero.

  • utf8.offset patch
    Now it also should return final position of character.

And little notice regarding <close> stack overflow issue in #2228.
It was asked in official mailing list and response is:
https://groups.google.com/g/lua-l/c/8Ro9A5MZbt8

This is expected. From the manual:

A call of the form return functioncall not in the scope of a
to-be-closed variable is called a tail call.

and

The loop starts by evaluating explist to produce four values: an
iterator function, a state, an initial value for the control variable,
and a closing value.
[...]
The closing value behaves like a to-be-closed variable (see §3.3.8),
which can be used to release resources when the loop ends. Otherwise, it
does not interfere with the loop.

So, the loop has a to-be-closed value and so the return f(n - 1) is
not a tail call.
This changed with the introduction of to-be-closed values.

I won't mind if for loop variables will still be writable (they are RO since 5.5) or they won't be a to-be-closed variable as longs as the variable attribute system is implemented and attributes <const> and <close> are implemented, so we can use them with local and global keywords.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-CoreThis affects CC's core (the Lua runtime, APIs, computer internals).enhancementAn extension of a feature or a new feature.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions