[Rpm-maint] [rpm-software-management/rpm] Add substring macro to expose lua's string.sub function (PR #2179)
Panu Matilainen
notifications at github.com
Mon Sep 12 05:54:00 UTC 2022
Besides using arg[n] instead of rpm.expand() on the args, checking for the arguments is counter-productive: the Lua-level function checks this by itself, does a better job of it and the third argument is actually optional (see https://www.lua.org/manual/5.4/manual.html#pdf-string.sub)
So it all comes down to just this, which (AFAICS) can do everything the Lua version can, including handle negative numbers and two-argument form:
```
%sub(-) %{lua:return string.sub(arg[1], arg[2], arg[3])}
```
````
$ rpm --define "commit 2bc745f2fde028e09f663c7967353e8b6aacdbf1" --eval "%sub %{commit} 1 7"
2bc745f
$ rpm --define "commit 2bc745f2fde028e09f663c7967353e8b6aacdbf1" --eval "%sub %{commit} -5"
cdbf1
$ rpm --define "commit 2bc745f2fde028e09f663c7967353e8b6aacdbf1" --eval "%sub %{commit} 1 -7"
2bc745f2fde028e09f663c7967353e8b6a
```
And like in #1764, it's not a question of whether this is useful or not (it quite obviously is), but whether we shouldn't just wrap the entire Lua string library this way and be done with it.
--
Reply to this email directly or view it on GitHub:
https://github.com/rpm-software-management/rpm/pull/2179#issuecomment-1243253643
You are receiving this because you are subscribed to this thread.
Message ID: <rpm-software-management/rpm/pull/2179/c1243253643 at github.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rpm.org/pipermail/rpm-maint/attachments/20220911/6f94f489/attachment-0001.html>
More information about the Rpm-maint
mailing list