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

define(name, body) documentation does not align with implementation #2962

Open
voxik opened this issue Mar 12, 2024 · 4 comments
Open

define(name, body) documentation does not align with implementation #2962

voxik opened this issue Mar 12, 2024 · 4 comments
Labels
API API related bug documentation lua Lua bindings/interface

Comments

@voxik
Copy link
Contributor

voxik commented Mar 12, 2024

This line is incorrect IMHO:

#### define(name, body)

It should actually be something like define(name_body). This example actually seems to be correct:

rpm.define('foo 1')

But in any case, it would make more sense if the heading was correct and the define method supported the name and body arguments. Why it does not work like this?

@voxik
Copy link
Contributor Author

voxik commented Mar 12, 2024

IOW this is what the heading says:

$ rpm -E "%{lua:rpm.define('foo', '1')}" -E "%foo"
error: Macro %foo has empty body
error: lua script failed: [string "<lua>"]:1: error defining macro

but this is how it actually works:

$ rpm -E "%{lua:rpm.define('foo 1')}" -E "%foo"

1

@voxik voxik changed the title define(name, body) documentation is incorrect define(name, body) documentation does not align with implementation Mar 12, 2024
@mlschroe
Copy link
Contributor

It's kinda sad that this strips the leading spaces:

 rpm -E "%{lua:macros.define({'foo', ' 1 '})}" -E "x%{foo}x"

>1 <

@pmatilai pmatilai added the lua Lua bindings/interface label Mar 20, 2024
@pmatilai
Copy link
Member

pmatilai commented Mar 20, 2024

Indeed, rpm.define() calls rpmDefineMacro() which is takes the macro name and the body as a single line - as you would get in a macro file. It doesn't make much sense as an API.

IIRC Lua's rpm.define() used that API because the other alternative lacked all the error checking back in the day, but things are quite different now, rpm.define() should just reroute to macros.define or something.

Note that this also works: macros['foo'] = 1

@voxik
Copy link
Contributor Author

voxik commented Mar 20, 2024

For the context, I have stumbled upon this issue playing with #2969 and my initial idea was to assign the whole macro body including the new lines to some macro with some specifically crafted name. But I was not able to achieve that no matter what and resorted to use variables (which is probably good enough variant).

It is my feeling that for whatever reason defining macro in Lua is limited comparing to plain .spec file, not being able to insert new line there. But maybe I have just not figured out the right amount of backslashes or what not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API API related bug documentation lua Lua bindings/interface
Projects
Status: Backlog
Development

No branches or pull requests

4 participants