Re: [Rpm-maint] [rpm-software-management/rpm] RFE: pass parametric macro options and arguments to Lua natively (#1092)

2020-10-12 Thread Panu Matilainen
@nim-nim : 

One shouldn't expect `nil == false` any more than one would expect `"yes" == 
true`, although both sides *evaluate to* true, ie `("yes" and true)` *is* true. 
The language documentation is quite explicit about this, and this has 
wonderfully little to do with rpm or the interface it provides.

Now, there are no clear concise examples provided, so I can only assume some of 
this confusion comes from expecting rpm.expand() on conditionals to evaluate 
somehow specially, but such evaluation *is not possible*. Rpm macro expansion 
is a *string processor* which simply produces a string of zero or more 
characters according to its own rules (think printf() on steroids), any 
interpretation of the returned string is solely up to the user. If you expect 
something else and additionally have misunderstandings about Lua language 
fundamentals, I'm sure it's going to be a painful experience.  I could've 
clarified this anytime if you had just asked. Also, adding separate API to 
return a nice little boolean whether a macro is defined or not was a matter of 
like 15min of work. All these years and nobody thought to ask for such a simple 
thing!

I was hoping for some constructive feedback on the newly added things that are 
intended to help that very case, including discussion about usage scenarios 
with the specific Lua semantics in mind, but instead I get the same old whining 
about how everything is awful (which sure gets tiresome after all these years), 
quite clearly without so much as a glance to look at what's being done to 
improve things. 

I'm not particularly proud of the blown fuse on Friday, but not everything is 
rpm's fault.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/rpm-software-management/rpm/issues/1092#issuecomment-707076354___
Rpm-maint mailing list
Rpm-maint@lists.rpm.org
http://lists.rpm.org/mailman/listinfo/rpm-maint


Re: [Rpm-maint] [rpm-software-management/rpm] RFE: pass parametric macro options and arguments to Lua natively (#1092)

2020-10-12 Thread Panu Matilainen
> What I objected here is exposing false instead of nil when something is unset.

But there's no such thing in the PR linked to this item at all! That's what's 
so frustrating to me here and why I've been urging you to look at what was 
actually implemented for this ticket: 
https://github.com/rpm-software-management/rpm/commit/67abf72ef57e58251271f5b218f867357d78a4e0

"opts" table always exists so you don't need to test *that* against nil each 
and every time, and beyond that you get nil's for undefined options, and 
strings for defined (empty vs non-empty depending on whether it takes an 
argument or not). The other part is "arg" table (also always existing) where 
you get leftover arguments as a native Lua sequence, accessible with arg[n] and 
count with #arg. 

Other improvements in this area are in the works and some already done, but 
that's beyond the scope here.


-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/rpm-software-management/rpm/issues/1092#issuecomment-707141799___
Rpm-maint mailing list
Rpm-maint@lists.rpm.org
http://lists.rpm.org/mailman/listinfo/rpm-maint


Re: [Rpm-maint] [rpm-software-management/rpm] RFE: pass parametric macro options and arguments to Lua natively (#1092)

2020-10-12 Thread nim-nim
BTW, the whole state of things is painful and frustrating to me too. If things 
can not work out today let’s just forget about it for now. I’m not looking for 
a fight and I have no energy left for arguing in circles.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/rpm-software-management/rpm/issues/1092#issuecomment-707126641___
Rpm-maint mailing list
Rpm-maint@lists.rpm.org
http://lists.rpm.org/mailman/listinfo/rpm-maint


Re: [Rpm-maint] [rpm-software-management/rpm] RFE: pass parametric macro options and arguments to Lua natively (#1092)

2020-10-12 Thread nim-nim
@pmatilai Look, the only thing I care about lua side is being able to access 
spec state easily and reliably. state = state of macros/variables, state of 
flags and option passed to a macro, etc. The best macro logic in the world will 
produce erroneous results if it is mistaken about spec state.

Right now a lot of this accessing is done via expands. While expand is only a 
string processor that’s the only tool provided in the documented rpm lua API to 
read state lua-side. And you often need to compare several slightly different 
expand calls to guess the real data state.

Good replacements to this expand mess should expose real state lua side. Real 
means nil if unset, false if set to false, true if set to true (or just set 
without value), empty string if set to empty string, array of values if a macro 
evaluates to several lines of values (à la sourcelist).

While nil and false behave the same in bare conditionals, and nil and empty 
string behave the same when expanding to string, they are not the same 
semantically. Typically, nil means you are free to use default values instead, 
while an explicit false or empty string is an explicit packager request. When a 
macro can accept both quiet and verbose flags, or a general default state 
variable, you really really want to know which one of those was actually set to 
something (including false) and which one of those is currently unset..

What I objected here is exposing false instead of nil when something is unset. 
Requiring a separate call to check if it’s false or unset is no better than 
comparing several expand calls (with our without leading ?) to get the actual 
result.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/rpm-software-management/rpm/issues/1092#issuecomment-707105106___
Rpm-maint mailing list
Rpm-maint@lists.rpm.org
http://lists.rpm.org/mailman/listinfo/rpm-maint


Re: [Rpm-maint] [rpm-software-management/rpm] RFE: pass parametric macro options and arguments to Lua natively (#1092)

2020-10-09 Thread Panu Matilainen
Closed #1092 via 67abf72ef57e58251271f5b218f867357d78a4e0.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/rpm-software-management/rpm/issues/1092#event-3859368773___
Rpm-maint mailing list
Rpm-maint@lists.rpm.org
http://lists.rpm.org/mailman/listinfo/rpm-maint


Re: [Rpm-maint] [rpm-software-management/rpm] RFE: pass parametric macro options and arguments to Lua natively (#1092)

2020-10-09 Thread Panu Matilainen
Sigh. *Obviously* nil is not *equal to* false, any more than, say, None and 
False in Python. It would be one bizarre language if they were!

Point out concrete problems in the pull-request, or shut up.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/rpm-software-management/rpm/issues/1092#issuecomment-706078696___
Rpm-maint mailing list
Rpm-maint@lists.rpm.org
http://lists.rpm.org/mailman/listinfo/rpm-maint


Re: [Rpm-maint] [rpm-software-management/rpm] RFE: pass parametric macro options and arguments to Lua natively (#1092)

2020-10-09 Thread nim-nim
> Oh, looking closer:
> 
> > @nim-nim wrote
> > [...]
> > exist because nil is not the same as false or empty
> 
> Yes, nil is not same as empty. It however very explicitly is same as false, 
> quoting https://www.lua.org/manual/5.4/manual.html#2.1:

(lua)
> if (nil == false) then print("nil is the same thing as false") else 
> print("nil and false are different") end
nil and false are different


As this trivial example shows they are most definitely not the same at the 
language level, and if you expect them to you **will** get unexpected 
comparison and conditional behaviors. (other things that will fail unexpectedly 
is transformation to string values, which is where the empty string comes into 
play).

nil means unset. false means explicitly set to a specific false value. empty 
string means empty string. Clean programming languages like lua are very 
careful to distinguish between those. rpm macro language is not careful, that’s 
why the first google hits on rpm conditionals/comparisons is "it does not work 
as you expect to", why no one writes complex logic rpm macro language, and why 
redhat-rpm-config maintainers suspect any new macro submission to contain 
dangerous quirks.

So get down your high horse and please implement things cleanly. And if you 
insist, please do implement clean true and false keywords in the rpm macro 
language to clean up the legacy mess there too.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/rpm-software-management/rpm/issues/1092#issuecomment-706048624___
Rpm-maint mailing list
Rpm-maint@lists.rpm.org
http://lists.rpm.org/mailman/listinfo/rpm-maint


Re: [Rpm-maint] [rpm-software-management/rpm] RFE: pass parametric macro options and arguments to Lua natively (#1092)

2020-10-08 Thread Panu Matilainen
Oh, looking closer:

> @nim-nim wrote
> [...]
> exist because nil is not the same as false or empty

Yes, nil is not same as empty. It however very explicitly is same as false, 
quoting https://www.lua.org/manual/5.4/manual.html#2.1:
> Both nil and false make a condition false; they are collectively called false 
> values. Any other value makes a condition true. 

It doesn't get much more clearer than that. If you've assumed otherwise then 
that's your headache. If you look closer, this PR specifically *relies* on the 
fundamental language behavior of empty meaning true and nil being false. I'm 
not aware of anything in rpm assuming otherwise, but if there was that'd simply 
be a bug that needs fixing.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/rpm-software-management/rpm/issues/1092#issuecomment-705566832___
Rpm-maint mailing list
Rpm-maint@lists.rpm.org
http://lists.rpm.org/mailman/listinfo/rpm-maint


Re: [Rpm-maint] [rpm-software-management/rpm] RFE: pass parametric macro options and arguments to Lua natively (#1092)

2020-10-08 Thread Panu Matilainen
And none of us here would have the slightest clue as to what those fragments 
are supposed to be doing and in what context. As I'm sure you know perfectly 
well, the devil is in the details.

If you're not interested in testing and reviewing *this* implementation that's 
fine, just don't come complaining about it later then.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/rpm-software-management/rpm/issues/1092#issuecomment-705524090___
Rpm-maint mailing list
Rpm-maint@lists.rpm.org
http://lists.rpm.org/mailman/listinfo/rpm-maint


Re: [Rpm-maint] [rpm-software-management/rpm] RFE: pass parametric macro options and arguments to Lua natively (#1092)

2020-10-08 Thread Miro Hrončok
I assume option without argument would be true while option with argument would 
be string with its value? 

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/rpm-software-management/rpm/issues/1092#issuecomment-705395114___
Rpm-maint mailing list
Rpm-maint@lists.rpm.org
http://lists.rpm.org/mailman/listinfo/rpm-maint


Re: [Rpm-maint] [rpm-software-management/rpm] RFE: pass parametric macro options and arguments to Lua natively (#1092)

2020-10-08 Thread nim-nim
https://src.fedoraproject.org/rpms/redhat-rpm-config/blob/master/f/common.lua#_30
 exists because nil is not the same as false lua-side.

And no I don’t remember out of hand all the problems it fixed. I definitely 
*do* *not* want to remember them. Debugging the corner cases induced by the 
approximations in existing rpm lua APIs were eating all my time macro dev 
before I took care to wrap it all in something solid and correct by default.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/rpm-software-management/rpm/issues/1092#issuecomment-705493670___
Rpm-maint mailing list
Rpm-maint@lists.rpm.org
http://lists.rpm.org/mailman/listinfo/rpm-maint


Re: [Rpm-maint] [rpm-software-management/rpm] RFE: pass parametric macro options and arguments to Lua natively (#1092)

2020-10-08 Thread Panu Matilainen
@nim-nim, if there's a concrete problem with how testing for option presence is 
handled here, lets hear it out. To me it seems to work exactly like one would 
expect it to, but sorry ponies not included.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/rpm-software-management/rpm/issues/1092#issuecomment-705485732___
Rpm-maint mailing list
Rpm-maint@lists.rpm.org
http://lists.rpm.org/mailman/listinfo/rpm-maint


Re: [Rpm-maint] [rpm-software-management/rpm] RFE: pass parametric macro options and arguments to Lua natively (#1092)

2020-10-08 Thread nim-nim
@pmatilai given lua was added as a macro language because the built-in 
constructs were driving everyone crazy as soon as you needed some non-trivial 
processing I don’t find this argument too convincing :)

Anyway lua has built-in conventions for booleans and nil values, you can’t dump 
blindly things as they exist non-lua side and expect things to work well 
lua-side.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/rpm-software-management/rpm/issues/1092#issuecomment-705482062___
Rpm-maint mailing list
Rpm-maint@lists.rpm.org
http://lists.rpm.org/mailman/listinfo/rpm-maint


Re: [Rpm-maint] [rpm-software-management/rpm] RFE: pass parametric macro options and arguments to Lua natively (#1092)

2020-10-08 Thread Panu Matilainen
The Lua native arguments have to match those of non-Lua macros, otherwise 
everybody goes crazy.

For more advanced use there will be that option to let the macro do its own 
processing.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/rpm-software-management/rpm/issues/1092#issuecomment-705460333___
Rpm-maint mailing list
Rpm-maint@lists.rpm.org
http://lists.rpm.org/mailman/listinfo/rpm-maint


Re: [Rpm-maint] [rpm-software-management/rpm] RFE: pass parametric macro options and arguments to Lua natively (#1092)

2020-10-08 Thread nim-nim
@hroncok from the lua language POW you need a tristate for flags: nil (not 
passed), true (passed as true), false (passed as false). Otherwise it’s real 
easy to be confused when handling things that have a default state absent any 
flag, or an antonym (with/without, quiet/verbose, etc), or 

One may argue that that does not matter given the primitive state of the 
current rpm argument parser, but what that actually tells me building a new 
API, that bakes existing parsing problems even deeper, is quite unwise.

@pmatilai has the right general idea but it would probably be safer to expose 
arguments using an existing cli parsing API (such as lua argparse) and not 
embark in a journey to rediscover problems others mastered a long time ago. 

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/rpm-software-management/rpm/issues/1092#issuecomment-705452828___
Rpm-maint mailing list
Rpm-maint@lists.rpm.org
http://lists.rpm.org/mailman/listinfo/rpm-maint


Re: [Rpm-maint] [rpm-software-management/rpm] RFE: pass parametric macro options and arguments to Lua natively (#1092)

2020-10-08 Thread Panu Matilainen
...and done, now including actual documentation:
https://github.com/rpm-software-management/rpm/pull/1383/commits/a3c336434f0abcfb5c17ef4718429f86873f7f4d

@hroncok - basically yes, options without value are saved as empty strings in 
the Lua table so both boolean and value access work as you'd expect.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/rpm-software-management/rpm/issues/1092#issuecomment-705411963___
Rpm-maint mailing list
Rpm-maint@lists.rpm.org
http://lists.rpm.org/mailman/listinfo/rpm-maint


Re: [Rpm-maint] [rpm-software-management/rpm] RFE: pass parametric macro options and arguments to Lua natively (#1092)

2020-10-07 Thread Panu Matilainen
(This all is making me think if we couldn't actually arrange parametric macros 
to appear as native callable functions in Lua...)

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/rpm-software-management/rpm/issues/1092#issuecomment-705310315___
Rpm-maint mailing list
Rpm-maint@lists.rpm.org
http://lists.rpm.org/mailman/listinfo/rpm-maint


Re: [Rpm-maint] [rpm-software-management/rpm] RFE: pass parametric macro options and arguments to Lua natively (#1092)

2020-10-07 Thread Panu Matilainen
We can't pass NULL's in middle of ARGV_t, but that gave me an idea...

What we could do is pass pass options and a table and the arguments as another, 
and prepend this to the anonymous Lua chunk from C side:
```
opt = select(1, ...)
arg = select(2, ...)
```

Which I think makes it all really nice on the Lua side:
```
%foo(a:b) %{lua
if opt.b
print('do b')
if opt.a
print('a value: '...opt.a)
for i in ipairs(i, arg) do
print(i, arg)
end

--- also these would work
if opt['b']:
print('do b')
print('first arg'..argv[1])
}
```

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/rpm-software-management/rpm/issues/1092#issuecomment-705309465___
Rpm-maint mailing list
Rpm-maint@lists.rpm.org
http://lists.rpm.org/mailman/listinfo/rpm-maint


Re: [Rpm-maint] [rpm-software-management/rpm] RFE: pass parametric macro options and arguments to Lua natively (#1092)

2020-10-07 Thread Michael Schroeder
I'd love to write:
```
%{lua: opt_z, arg = ...;   }
```
i.e pass an argument for every option in the macro definition (using the order 
specified in the definition). Use nil if the option was not used, 0/1 for 
options with no argument.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/rpm-software-management/rpm/issues/1092#issuecomment-704832591___
Rpm-maint mailing list
Rpm-maint@lists.rpm.org
http://lists.rpm.org/mailman/listinfo/rpm-maint


Re: [Rpm-maint] [rpm-software-management/rpm] RFE: pass parametric macro options and arguments to Lua natively (#1092)

2020-10-06 Thread Panu Matilainen
https://lua.programmingpedia.net/en/tutorial/4475/variadic-arguments applies, 
eg to walk through arguments:

> $ ./rpm --define "foo(..) %{lua: t = {...}; print('nargs '..rpm.expand('%{#}: 
> ')); for i, v in ipairs(t) do print(i..':'..v..' '); end}" --eval "%foo 5 4 3 
> 2 -z"
nargs 5: 1:5 2:4 3:3 4:2 5:-z 

The question mark(s) revolve around what to do with options when present in 
normal parametric macros. The current behavior is to pass them to Lua as 
arguments, and %{#} macro carries the number of non-option arguments so you can 
calculate how many option arguments there are.

> $ ./rpm --define "foo(z:) %{lua: t = {...}; print('nargs '..rpm.expand('%{#}: 
> ')); for i, v in ipairs(t) do print(i..':'..v..' '); end}" --eval "%foo 5 4 3 
> 2 -z7"
nargs 4: 1:-z7 2:5 3:4 4:3 5:2

Another possibility would be not passing options as arguments to Lua except 
when custom option processing is selected, which would *kinda* make sense, but 
also seems limiting.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/rpm-software-management/rpm/issues/1092#issuecomment-704290557___
Rpm-maint mailing list
Rpm-maint@lists.rpm.org
http://lists.rpm.org/mailman/listinfo/rpm-maint


Re: [Rpm-maint] [rpm-software-management/rpm] RFE: pass parametric macro options and arguments to Lua natively (#1092)

2020-10-06 Thread Miro Hrončok
Do you have an example of usage? It's hard to find for me in the tests.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/rpm-software-management/rpm/issues/1092#issuecomment-704199944___
Rpm-maint mailing list
Rpm-maint@lists.rpm.org
http://lists.rpm.org/mailman/listinfo/rpm-maint


Re: [Rpm-maint] [rpm-software-management/rpm] RFE: pass parametric macro options and arguments to Lua natively (#1092)

2020-10-06 Thread Panu Matilainen
Implemented now as a part of #1383. 

There are various ways this could be done, what's implemented now is that %{**} 
macro, ie the unprocessed arguments to the macro, are passed to Lua as 
arguments. The processed per-option macros are still accessible via 
rpm.expand() of course. Feedback welcome.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/rpm-software-management/rpm/issues/1092#issuecomment-704171945___
Rpm-maint mailing list
Rpm-maint@lists.rpm.org
http://lists.rpm.org/mailman/listinfo/rpm-maint


Re: [Rpm-maint] [rpm-software-management/rpm] RFE: pass parametric macro options and arguments to Lua natively (#1092)

2020-05-14 Thread Miro Hrončok
I was about to explore this as well, thanks for filing this.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/rpm-software-management/rpm/issues/1092#issuecomment-628473072___
Rpm-maint mailing list
Rpm-maint@lists.rpm.org
http://lists.rpm.org/mailman/listinfo/rpm-maint


Re: [Rpm-maint] [rpm-software-management/rpm] RFE: pass parametric macro options and arguments to Lua natively (#1092)

2020-03-20 Thread Panu Matilainen
#546 and #547 need to be considered when doing this.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/rpm-software-management/rpm/issues/1092#issuecomment-601710019___
Rpm-maint mailing list
Rpm-maint@lists.rpm.org
http://lists.rpm.org/mailman/listinfo/rpm-maint


[Rpm-maint] [rpm-software-management/rpm] RFE: pass parametric macro options and arguments to Lua natively (#1092)

2020-03-02 Thread Panu Matilainen
Accessing macro arguments via rpm.expand("%1") etc is tedious, non-intuitive 
and subject to all sorts of expansion issues. Make macro options and arguments 
available to Lua via native data structures (tables in practise), as if they 
were just function arguments. Which they largely are.

PR #1063 was an experiment at doing this but relies on global structures which 
is not a feasible approach, parametric macros can nest so we need to handle the 
arguments via Lua stack. This requires enhancing the internal rpmlua wrapper 
API around Lua.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/rpm-software-management/rpm/issues/1092___
Rpm-maint mailing list
Rpm-maint@lists.rpm.org
http://lists.rpm.org/mailman/listinfo/rpm-maint