Skip to content

Banane9/IronWren

Repository files navigation

IronWren Build status

.NET integration for the scripting language Wren.

Available on NuGet here!

###Features###

  • C# style wrapper around Wren's C-API.
  • No IntPtrs get exposed, making the value- and function-handles typesafe.
  • Ability to automatically generate Wren integration code for classes defined in C#.

###Usage###

Basic usage (more extensively shown in IronWren.ConsoleTesting/Program.cs):

private static void Main(string[] args)
{
    var config = new WrenConfig();
    config.Write += (v, text) => Console.Write(text);
    
    using (var vm = new WrenVM(config))
    {
        var result = vm.Interpret("System.print(\"Hi from Wren!\")");
    }
    
    Console.ReadLine();
}

#####AutoMapper#####

The AutoMapper provides the ability to easily create a Wren class from a C# type, only requiring it to be decorated with the right Attributes.

An example can be found in IronWren.ConsoleTesting/WrenVector.cs.

The Attributes are:

  • [WrenClass] - For optionally specifying an alternative name.
  • [WrenCode] - For dropping a string field's content into the class source.
  • [WrenConstructor] - For marking the constructor that should be used by Wren and which overloads should exist there.
  • [WrenFinalizer] - For marking a method that should be called when the object is GCed by the Wren VM.
  • [WrenIndexer] - For marking methods that are get/set methods of an indexer.
  • [WrenMethod] - For marking a method that should be present in Wren and its arguments.
  • [WrenProperty] - For marking methods that are get/set methods of a property.

The AutoMapper will automatically handle the binding between the methods and Wren.


Iron Wrens