Skip to content

gnerkus/LuaPredicates

Repository files navigation

LuaPredicates

NuGet Version

LuaPredicates is a .NET Core library to parse collections in .NET with functions written in Lua.

Installing LuaPredicates

You can use NuGet to install LuaPredicates. Run the following command in the Package Manager Console.

PM> Install-Package LuaPredicates

Usage

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
    }
}

License

The library is released under terms of the MIT License:

About

Parse C# collections using Lua scripts

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages