-
Hello. Consider this Python code: >>> import rpm
>>> rpm.expandMacro('%{lua:print(a)}')
'nil'
>>> rpm.expandMacro('%{lua:a = 1}')
''
>>> rpm.expandMacro('%{lua:print(a)}')
'1' Between individual 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. I know I can reload the config to achieve what I need: >>> 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? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
It's not just Lua state, parsing a spec can and very commonly does change things in the global macro space, and doing another parse without forcing a full reset (rpm.reloadConfig()) can and will yield different results to the point one might call it undefined behavior. So no, there's no lighter way to reset the Lua state, you really need to reset the entire state between spec parses, whether the same spec or something else. Of course that the caller needs to do such a thing is a flawed design in rpm. Isolating the entire parse context to the spec struct is something I would love to do but it's a huge job. |
Beta Was this translation helpful? Give feedback.
It's not just Lua state, parsing a spec can and very commonly does change things in the global macro space, and doing another parse without forcing a full reset (rpm.reloadConfig()) can and will yield different results to the point one might call it undefined behavior.
So no, there's no lighter way to reset the Lua state, you really need to reset the entire state between spec parses, whether the same spec or something else. Of course that the caller needs to do such a thing is a flawed design in rpm. Isolating the entire parse context to the spec struct is something I would love to do but it's a huge job.