diff options
| author | tobil4sk <tobil4sk@outlook.com> | 2026-02-03 22:47:50 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-02-03 19:47:50 -0300 |
| commit | 47301d83aba58925e1b9594023621ebb27070cdb (patch) | |
| tree | 73021b5366687ec1683b9e66505e74f22f71d31b /vendor/compat53/file_mt.lua | |
| parent | acf1f47e7f1b1ecbc147e41cae51ddfd06ad898d (diff) | |
| download | luarocks-main.tar.gz luarocks-main.tar.bz2 luarocks-main.zip | |
Improve flexibility around vendored librariesmain
compat53 is vendored since #1757 as it is required to run luarocks with lua 5.1 or 5.2.
However, this introduced some issues as the GNUmakefile install rule places these in the same place where `luarocks install compat53` would install them. This means you get conflicts if you install the actual package:
```
Warning: /.../prefix/share/lua/5.1/compat53/init.lua is not tracked by this installation of LuaRocks. Moving it to /.../prefix/share/lua/5.1/compat53/init.lua~
Warning: /.../prefix/share/lua/5.1/compat53/module.lua is not tracked by this installation of LuaRocks. Moving it to /.../prefix/share/lua/5.1/compat53/module.lua~
Warning: /.../prefix/share/lua/5.1/compat53/file_mt.lua is not tracked by this installation of LuaRocks. Moving it to /.../prefix/share/lua/5.1/compat53/file_mt.lua~
```
It is also not ideal for linux package maintainers to include a vendored package, see: https://github.com/luarocks/luarocks/pull/1757#issuecomment-3409873412.
To solve these issues, this patchset makes the following changes:
- GNUmakefile now places the compat53 files under `luarocks/vendor/compat53` (which is added internally to the luarocks script's `package.path`). This way a user's installation of compat53 does not interfere at all with luarocks one.
- Added `--with-system-compat53` option to configure script for external packaging systems.
- Fixed install.bat's logic for deciding whether to vendor compat53, as the current script includes it for every version.
install.bat already places luarocks sources outside of LUAPATH, so that part can stay as is.
I've also inverted the version check to avoid the need for future patches like: #1850.
Diffstat (limited to 'vendor/compat53/file_mt.lua')
| -rw-r--r-- | vendor/compat53/file_mt.lua | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/vendor/compat53/file_mt.lua b/vendor/compat53/file_mt.lua new file mode 100644 index 00000000..6433619d --- /dev/null +++ b/vendor/compat53/file_mt.lua | |||
| @@ -0,0 +1,71 @@ | |||
| 1 | local lua_version = _VERSION:sub(-3) | ||
| 2 | |||
| 3 | local M = {} | ||
| 4 | |||
| 5 | local unpack = lua_version == "5.1" and unpack or table.unpack | ||
| 6 | |||
| 7 | local function addasterisk(fmt) | ||
| 8 | if type(fmt) == "string" and fmt:sub(1, 1) ~= "*" then | ||
| 9 | return "*"..fmt | ||
| 10 | else | ||
| 11 | return fmt | ||
| 12 | end | ||
| 13 | end | ||
| 14 | |||
| 15 | function M.update_file_meta(file_meta, is_luajit52) | ||
| 16 | |||
| 17 | -- make '*' optional for file:read and file:lines | ||
| 18 | |||
| 19 | local file_lines = file_meta.__index.lines | ||
| 20 | file_meta.__index.lines = function(self, ...) | ||
| 21 | local n = select('#', ...) | ||
| 22 | for i = 1, n do | ||
| 23 | local a = select(i, ...) | ||
| 24 | local b = addasterisk(a) | ||
| 25 | -- as an optimization we only allocate a table for the | ||
| 26 | -- modified format arguments when we have a '*' somewhere | ||
| 27 | if a ~= b then | ||
| 28 | local args = { ... } | ||
| 29 | args[i] = b | ||
| 30 | for j = i+1, n do | ||
| 31 | args[j] = addasterisk(args[j]) | ||
| 32 | end | ||
| 33 | return file_lines(self, unpack(args, 1, n)) | ||
| 34 | end | ||
| 35 | end | ||
| 36 | return file_lines(self, ...) | ||
| 37 | end | ||
| 38 | |||
| 39 | local file_read = file_meta.__index.read | ||
| 40 | file_meta.__index.read = function(self, ...) | ||
| 41 | local n = select('#', ...) | ||
| 42 | for i = 1, n do | ||
| 43 | local a = select(i, ...) | ||
| 44 | local b = addasterisk(a) | ||
| 45 | -- as an optimization we only allocate a table for the | ||
| 46 | -- modified format arguments when we have a '*' somewhere | ||
| 47 | if a ~= b then | ||
| 48 | local args = { ... } | ||
| 49 | args[i] = b | ||
| 50 | for j = i+1, n do | ||
| 51 | args[j] = addasterisk(args[j]) | ||
| 52 | end | ||
| 53 | return file_read(self, unpack(args, 1, n)) | ||
| 54 | end | ||
| 55 | end | ||
| 56 | return file_read(self, ...) | ||
| 57 | end | ||
| 58 | |||
| 59 | if not is_luajit52 then | ||
| 60 | local file_write = file_meta.__index.write | ||
| 61 | file_meta.__index.write = function(self, ...) | ||
| 62 | local ret, err = file_write(self, ...) | ||
| 63 | if ret then | ||
| 64 | return self | ||
| 65 | end | ||
| 66 | return ret, err | ||
| 67 | end | ||
| 68 | end | ||
| 69 | end | ||
| 70 | |||
| 71 | return M | ||
