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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement a table-like shortcut to rpm macros in Lua #1419

Merged
merged 2 commits into from Jan 27, 2021

Conversation

pmatilai
Copy link
Member

Add rpm macro context as a global table-like entity named 'macros' for
a more Lua-native experience with rpm macros.

Support basic indexing syntaxes (macros[k] and macros.k) for access, define
and undefine operations. Undefined macros return nil here and assigning
to nil will undefine (pop) the macro.

As a specialty, parametric macros are returned as native callable
variadic Lua functions. A string argument is passed to expand as is,
but if arguments are passed as a table, eg r = macros.foo({1, 2, 3}),
they are passed entirely as-is.

The macro context pointer in the userdata is not consistently used for
all operations here, but then all the macro operations in Lua are hardwired
to the global context anyway so it doesn't matter in practise. Properly
passing the context around in all cases is left for later commits.

GH is not letting me reopen #1398 馃槖 so opening a new one to pick up where we left off there, now that @mlschroe did all the heavy lifting 馃槃

doDefine() wants macro file-style "name body" string as an argument, but
when called through rpmExpandThisMacro() you'd expect to put the name
and body in separate arguments. Properly handling this in the macro engine
guts is more than I'm prepared to do at the moment, but we can detect
the multiple arguments case and turn the arguments into something that
doDefine groks.

This will matter when we add support for calling macros as native Lua
elements.
@pmatilai
Copy link
Member Author

Dusted this off and made macros.define() and macros.global() work.

I think it's time to get this in. There are some quirks and inconsistencies present largely due to how convoluted this all is in the macro engine itself, but fixing all that is hard while there are no users for the code - ie this thing here. So unless there are some glaring bugs left, lets just get this merged so we can move forward with other stuff.

Add rpm macro context as a global table-like entity named 'macros' for
a more Lua-native experience with rpm macros.

Support basic indexing syntaxes (macros[k] and macros.k) for access, define
and undefine operations. Undefined macros return nil here and assigning
to nil will undefine (pop) the macro.

As a specialty, parametric macros are returned as native callable
variadic Lua functions. A string argument is passed to expand as is,
but if arguments are passed as a table, eg `r = macros.foo({1, 2, 3})`,
they are passed entirely as-is.

The macro context pointer in the userdata is not consistently used for
all operations here, but then all the macro operations in Lua are hardwired
to the global context anyway so it doesn't matter in practise. Properly
passing the context around in all cases is left for later commits.
@pmatilai
Copy link
Member Author

pmatilai commented Jan 25, 2021

Realized that documentation is missing (added now), this has gone on so long now that a whole documentation project was started in the meanwhile...

@pmatilai
Copy link
Member Author

Since there are no further comments...

@pmatilai pmatilai merged commit 986be66 into rpm-software-management:master Jan 27, 2021
@pmatilai pmatilai deleted the luamt-pr branch February 3, 2021 13:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lua Lua bindings/interface RFE
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants