[Rpm-maint] [rpm-software-management/rpm] How to reset the Lua interpreter state (from Python) (Discussion #3357)

Miro Hrončok notifications at github.com
Thu Oct 3 19:30:19 UTC 2024


Hello. Consider this Python code:

```pycon
>>> import rpm
>>> rpm.expandMacro('%{lua:print(a)}')
'nil'
>>> rpm.expandMacro('%{lua:a = 1}')
''
>>> rpm.expandMacro('%{lua:print(a)}')
'1'
```

Between individual `rpm.expandMacro` calls, the Lua state is preserved. `a` is a global variable and it is set.

In reality, consider parsing a specfile twice from the same process. If the specfile assumes the Lua state is cleared between individual parsings, it [might not work properly](https://github.com/fedora-infra/rpmautospec/issues/185).

I know I can reload the config to achieve what I need:

```pycon
>>> rpm.reloadConfig()
True
>>> rpm.expandMacro('%{lua:print(a)}')
'nil'
```

But I suppose this is IO-bound and it performs a lot of actions that are not necessary for me.

Is there a lighter way to "restart" the Lua interpreter?

-- 
Reply to this email directly or view it on GitHub:
https://github.com/rpm-software-management/rpm/discussions/3357
You are receiving this because you are subscribed to this thread.

Message ID: <rpm-software-management/rpm/repo-discussions/3357 at github.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rpm.org/pipermail/rpm-maint/attachments/20241003/dc4da1f5/attachment.html>


More information about the Rpm-maint mailing list