RPi-Distro / raspi-config

Configuration tool for the Raspberry Pi
Other
569 stars 209 forks source link

Add support for newer Lua versions #253

Open mimi89999 opened 2 months ago

mimi89999 commented 2 months ago

Hello, Currently raspi-config depends on lua5.1 (https://github.com/RPi-Distro/raspi-config/blob/bookworm/debian/control#L12). Would it be possible to add support for newer versions of Lua and not depend on that very old Lua?

XECDesign commented 2 months ago

I haven't used lua in many many years, so I don't know if we can just switch over to 5.4 without any changes to the snippets of lua in raspi-config itself. It doesn't look like there's anything tricky going on and 5.4 should just work, but I don't have time to check that right now.

local key=assert(arg[1])
local fn=assert(arg[2])
local file=assert(io.open(fn))
for line in file:lines() do
  if line:match("^%s*"..key.."=.*$") then
    line="#"..line
  end
  print(line)
end
local key=assert(arg[1])
local fn=assert(arg[2])
local file=assert(io.open(fn))
local found=false
for line in file:lines() do
  local val = line:match("^%s*"..key.."=(.*)$")
  if (val ~= nil) then
    print(val)
    found=true
    break
  end
end
if not found then
   print(0)
end

It looks like these could just be rewritten to use sed and the lua dependency could be dropped entirely.

mimi89999 commented 2 months ago

I tested the code with Lua3.4 and it seems to be working fine. I fear that switching to sed might potentially introduce new bugs and make the code less readable.

mimi89999 commented 2 months ago

Anyway, the lua command is called and it's handled by the Debian alternatives system:

michel@kokomi:~ $ which lua
/usr/bin/lua
michel@kokomi:~ $ ls -l /usr/bin/lua
lrwxrwxrwx 1 root root 33 Feb 21  2023 /usr/bin/lua -> /etc/alternatives/lua-interpreter
michel@kokomi:~ $ ls -l /etc/alternatives/lua-interpreter
lrwxrwxrwx 1 root root 15 Aug 28 21:09 /etc/alternatives/lua-interpreter -> /usr/bin/lua5.4
michel@kokomi:~ $ sudo update-alternatives --list lua-interpreter
/usr/bin/lua5.1
/usr/bin/lua5.4

So even though the package depends on lua5.1, the lua command could be any version of lua :man_shrugging:

XECDesign commented 2 months ago

Thanks for checking and that's a good point about the lua symlink. But I still think the lua snippets are a bit out of place in a shell script. I don't think it will be any less readable. It would be using the same regular expressions, which is usually the least readable part.