-
Notifications
You must be signed in to change notification settings - Fork 9
Home
Andrew edited this page Mar 17, 2015
·
4 revisions
Welcome to the LENS documentation page!
LENS is an embedded scripting language for .NET applications. It provides interconnection between the script and your host application.
Just a few simple steps:
- Reference LENS.dll in your solution
- Create an instance of the
LensCompiler
class and set some properties. - Compile the string into a runnable object using
Compile
method. - Run it!
try
{
var x = 21;
var y = 2;
var result = 0;
var cp = new LensCompiler();
cp.RegisterProperty("x", () => x);
cp.RegisterProperty("y", () => y);
cp.RegisterProperty("res", () => result, r => result = r);
var source = "res = x * y";
var compiled = cp.Compile(source);
compiled.Run();
Console.WriteLine("The result is {0}", result);
}
catch(LensCompilerException e)
{
Console.WriteLine("An error has occured: {0}", e.FullMessage);
}
The language itself is influenced by functional languages, such as F#. Its syntax is designed to be lightweight and conscise, while allowing you to interact with any existing .NET types and entities.
Here are a few examples:
// Factorial function definition
fun fact:long (x:long) ->
if x == 0 then
1
else
let prev = fact (x - 1)
x * prev
fact 5 // 120
// LINQ support
let squareSum = range 1 100
|> Where (x -> x.even())
|> Select (x -> x ** 2)
|> Sum ()
// Pattern matching
fun desribe:string (arr:object[]) ->
match arr with
case [] then "empty array"
case [x:int] when x < 10 then fmt "array with 1 small int ({0})" x
case [x] then "array with 1 item"
case [x; y] then "array with 2 items"
case [x; y; ...z] then fmt "array with {0}, {1} and {2} more items" x y z.Length
For more information about the syntax, refer to specific Wiki pages (shown on the right).