Skip to content

fengweijp/DynLan

 
 

Repository files navigation

DYNLAN | Dynamic Scripting Language | in .NET

Features

  • evaluate code in C# at runtime (see examples below):
    • expressions
    • complex scripts (with objects and classes)
  • interoperability:
  • entirely written in plain C# (without DLR / Reflection.Emit)
  • pausing script execution

Compatibility

  • .net >= 2.0
  • .net core
  • .net standard
  • .net CE
  • PCL (including silverlight)

Examples

  • Simple expressions:
// result = 4
Object result = new Compiler().
  Compile(" 1 + 3 ").
  Eval();
  • Multiline scripts:
// result = 100
Object result = new Compiler().
  Compile(@"
    i = 0
    while i < 100 {
      i = i + 1
    }
    return i
").Eval();
  • C# interoperability:
// result = "11 string"
var variables = new Dictionary<String, Object>();
variables["A"] = "Test string";

Object result = new Compiler().
  Compile(@"
    A.Length + ' ' + A.Substring(5,6)
").Eval(variables);
  • Objects + classes:
// result = 70
Object result = new Compiler().
  Compile(@"

class TestClass() {
  a = 1
  b = 2
  def Sum(c) {
    return this.a + this.b + c
  }
}

def multiply(a, b) {
  c = a * b 
  return c
}

obj = TestClass()
return multiply( obj.Sum(3) + obj.a, 10)

").Eval();

Sample performance

22808 lines/second on single core (Intel Core i5-3210M@2.50Ghz)

More examples

Explore

About

Dynamic Scripting Language | .NET

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 100.0%