fix! method invocation if no arguments are supplied.

This commit is contained in:
redxef 2024-11-07 22:26:33 +01:00
parent 0a5aed38eb
commit 8257acbfbb
Signed by: redxef
GPG key ID: 7DAC3AA211CBD921

View file

@ -182,13 +182,21 @@ namespace Jellyfin.Plugin.SmartPlaylist.Lisp {
private static Expression _invoke(IEnumerable<Expression> args) { private static Expression _invoke(IEnumerable<Expression> args) {
Object o = (Object) args.First(); Object o = (Object) args.First();
String s = (String) args.Skip(1).First(); String s = (String) args.Skip(1).First();
Cons l = (Cons) args.Skip(2).First(); IEnumerable<Expression> l;
if (args.Skip(2).First() is Boolean lb && lb == Boolean.FALSE) {
l = new List<Expression>();
} else if (args.Skip(2).First() is Cons lc) {
l = lc.ToList();
} else {
throw new ApplicationException($"Expected a list of arguments, got {args.Skip(2).First()}");
}
IList<Expression> r = new List<Expression>(); IList<Expression> r = new List<Expression>();
MethodInfo? mi = o.Value().GetType().GetMethod(s.Value()); MethodInfo? mi = o.Value().GetType().GetMethod(s.Value());
if (mi == null) { if (mi == null) {
throw new ApplicationException($"{o.Value()} has not method {s.Value()}"); throw new ApplicationException($"{o.Value()} has not method {s.Value()}");
} }
object?[]? l_ = l.ToList().Select<Expression, object?>(x => { object?[]? l_ = l.Select<Expression, object?>(x => {
switch (x) { switch (x) {
case Integer s: case Integer s:
return s.Value(); return s.Value();