<commit_before># clr Library (gateway to .net)

## Getting started

`clr` is a package to access .net framework types and namespaces. The package is 
implemented in dynamic class `LuaType`, binds the calls to the host application 
or the .net framework classes.

NeoLua supports static methods, instance methods, overloaded methods, constructors, properties, 
types, sub types or events.

```Lua
local sys = clr.System;
```
Creates a dynamic type instance for the namespance system and assigns this new type 
to the local variable sys. So the both following calls are equalent.

```Lua
local StringBuilder = sys.Text.StringBuilder;
local StringBuilder1 = clr.System.Text.StringBuilder; -- same result
```

Use this variable like the using in .net to access the type StringBuilder.

To create a new object from the type call the type like a function. This 
will invoke the constructor.

```Lua
local sb = StringBuilder('text');
local sb1 = clr.System.Text.StringBuilder('test'); -- same result
```

If the type is generic use the index access to create a non generic class first.

```Lua
local lstObject = clr.System.Collections.Generic.List[clr.System.Object]();
local ListGeneric = clr.System.Collections.Generic.List;
local lstString = ListGeneric[clr.System.String]();
local ListStringType = ListGeneric[clr.System.String];
local lstString2 = ListStringType();
```

But the best way to short cut types is to use the `const` keyword. Because it creates no runtime overhead, it is only known during compile time. Becareful, no clr is needed.

```Lua
const ListOfObjects typeof System.Collections.Generic.List[System.Object];
```

The clr package is a "build in" package, so it is useable in Lua-Lambda's.

```C#
using (Lua l = new Lua())
{
  var f = l.CreateLambda<Func<double, double>>("f", "return clr.System.Math:Abs(x) * 2", "x");
  Console.WriteLine("f({0}) = {1}", 2, f(2));
  Console.WriteLine("f({0}) = {1}", 2, f(-2));

  var f2 = l.CreateLambda("f2", "local Math = clr.System.Math; return Math:Abs(x) * 2;", 
     null, typeof(double), new KeyValuePair<string, Type>("x", typeof(double)));
  Console.WriteLine("f2({0}) = {1}", 2, f2.DynamicInvoke(2));
  Console.WriteLine("f2({0}) = {1}", 2, f2.DynamicInvoke(-2));
```<commit_msg>fix typos in code examples<commit_after># clr Library (gateway to .net)

## Getting started

`clr` is a package to access .net framework types and namespaces. The package is 
implemented in dynamic class `LuaType`, binds the calls to the host application 
or the .net framework classes.

NeoLua supports static methods, instance methods, overloaded methods, constructors, properties, 
types, sub types or events.

```Lua
local sys = clr.System;
```
Creates a dynamic type instance for the namespance system and assigns this new type 
to the local variable sys. So the both following calls are equalent.

```Lua
local StringBuilder = sys.Text.StringBuilder;
local StringBuilder1 = clr.System.Text.StringBuilder; -- same result
```

Use this variable like the using in .net to access the type StringBuilder.

To create a new object from the type call the type like a function. This 
will invoke the constructor.

```Lua
local sb = StringBuilder('text');
local sb1 = clr.System.Text.StringBuilder('test'); -- same result
```

If the type is generic use the index access to create a non generic class first.

```Lua
local lstObject = clr.System.Collections.Generic.List[clr.System.Object]();
local ListGeneric = clr.System.Collections.Generic.List;
local lstString = ListGeneric[clr.System.String]();
local ListStringType = ListGeneric[clr.System.String];
local lstString2 = ListStringType();
```

But the best way to short cut types is to use the `const` keyword. Because it creates no runtime overhead, it is only known during compile time. Becareful, no clr is needed.

```Lua
const ListOfObjects typeof System.Collections.Generic.List[System.Object];
```

The clr package is a "build in" package, so it is useable in Lua-Lambda's.

```C#
using (Lua l = new Lua())
{
  var f = l.CreateLambda<Func<double, double>>("f", "return clr.System.Math:Abs(x) * 2", "x");
  Console.WriteLine("f({0}) = {1}", 2, f(2));
  Console.WriteLine("f({0}) = {1}", -2, f(-2));

  var f2 = l.CreateLambda("f2", "local Math = clr.System.Math; return Math:Abs(x) * 2;", 
     null, typeof(double), new KeyValuePair<string, Type>("x", typeof(double)));
  Console.WriteLine("f2({0}) = {1}", 2, f2.DynamicInvoke(2));
  Console.WriteLine("f2({0}) = {1}", -2, f2.DynamicInvoke(-2));
```
{'fraction_non_alphanumeric': 0.13030909495219034, 'fraction_numerical': 0.01200800533689126, 'mean_word_length': 4.686472819216182, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4354155', 'n_tokens_mistral': 1418, 'n_tokens_neox': 1371, 'n_words': 528}