LuaPredicates is a .NET Core library to parse collections in .NET with functions written in Lua.
You can use NuGet to install LuaPredicates. Run the following command in the Package Manager Console.
PM> Install-Package LuaPredicates
Given a record in the system:
private record Dimensions
{
public int Width { set; }
public int Height { set; }
}
We can transform a collection of Dimensions
objects into a collection of long
expressing
the area of each Dimensions
object:
using LuaPredicates;
namespace Test;
public class Program
{
public static void Main(string[] args)
{
var luaPredicate = new LuaPredicate<Dimensions, long>();
var func = luaPredicate.ReadFromString(
"""
function Calculate (dim)
return dim.Width * dim.Height
end
"""
);
var records = new List<Dimensions>
{
new ()
{
Width = 10,
Height = 10
}
};
var areas = records.Select(func).ToList();
Console.WriteLine(areas[0]); // 100
}
}
The library is released under terms of the MIT License: