Skip to content

Lua 5.1 incompatibility #71

@sewbacca

Description

@sewbacca

We found a bug when running LuaRocks 3.12.2 using Lua 5.1 via compat53 (see luarocks/luarocks#1831).

They rely on file:write() behavior from Lua >= 5.2 to return the fd if no error occurs:

local fd, err = io.open(path, 'w')
if not fd then return nil, err end
fd, err = f:write(data)
if not fd then return nil, err end
fd:close()
return true

There is already a patch in this repo, however it's not applied if we use native Lua 5.1 with no LuaJIT:

if not is_luajit52 then
local file_write = file_meta.__index.write
file_meta.__index.write = function(self, ...)
local ret, err = file_write(self, ...)
if ret then
return self
end
return ret, err
end
end

A dirty workarround we found is to just call this function on the metatable, if Lua version is 5.1:

diff --git a/src/compat53/module.lua b/src/compat53/module.lua
index 52b1dd63..b6a69af3 100644
--- a/src/compat53/module.lua
+++ b/src/compat53/module.lua
@@ -824,6 +824,7 @@ if lua_version < "5.3" then
             end
             return lines_iterator, st
          end
+         require'compat53.file_mt'.update_file_meta(debug.getmetatable(io.stdin), false)
       end -- not luajit

       if is_luajit then

This only seems to affect module.lua, as init.lua always calls the update function.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions