Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add shorthand macros for some conventient Lua string operations #2181

Merged
merged 1 commit into from
Sep 15, 2022

Conversation

pmatilai
Copy link
Member

Despite all the Lua magic we already do, it's annoyingly often the case that shelling out is easier (or at least shorter) than doing the same in Lua (substrings, length etc)

Add shorthand macros %gsub, %len, %lower, %rep, %reverse, %sub and %upper which simply wrap the corresponding Lua string.* functions for convenience.

rpmio/macro.c Outdated Show resolved Hide resolved
@pmatilai
Copy link
Member Author

Of course there's the question of whether it actually makes sense to do this in C at all, when wrapping them individually in macros file would be easier in many ways.

The other question is the naming: %sub here clashes with usage in our own test-suite, and if these clash here they may as well clash elsewhere. So I wonder if we should just add "str" as a common pre- or post-fix to all these...

@pmatilai
Copy link
Member Author

Yet another question is whether it'd be saner to just do to do a native Lua call doString() directly. It'd be a few lines more probably but then we could give saner error messages, eg

$ ./rpm --eval "%sub x"
error: lua script failed: [string "sub"]:1: bad argument #2 to 'sub' (number expected, got no value)

The rest of the message is entirely reasonable but the "lua script failed" part is somewhat disorienting...

tests/rpmmacro.at Outdated Show resolved Hide resolved
@pmatilai
Copy link
Member Author

What, no bikeshedding on the names? 😆

@dmnks
Copy link
Contributor

dmnks commented Sep 14, 2022

@pmatilai, the CI should now be fixed, please force push to this branch to trigger a new job.

Despite all the Lua magic we already do, it's annoyingly often the case
that shelling out is easier (or at least shorter) than doing the same in
Lua (substrings, length etc)

Add shorthand macros %gsub, %len, %lower, %rep, %reverse, %sub and
%upper which simply wrap the corresponding Lua string.* functions for
convenience.
@pmatilai
Copy link
Member Author

pmatilai commented Sep 15, 2022

The newly setup Semaphore project only catches new PR's so this is going to remain in limbo.
Since much to my shock nobody seems to be interested in bikeshedding over the names, I'll just merge the damn thing. "make ci" passes locally anyhow.

@pmatilai pmatilai merged commit cad5aff into rpm-software-management:master Sep 15, 2022
@hroncok
Copy link
Contributor

hroncok commented Sep 15, 2022

The names are perfect BTW

@pmatilai
Copy link
Member Author

I should take a screenshot of that comment and put it on the wall 😁

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants