Embers 3.0.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package Embers --version 3.0.2                
NuGet\Install-Package Embers -Version 3.0.2                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Embers" Version="3.0.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Embers --version 3.0.2                
#r "nuget: Embers, 3.0.2"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Embers as a Cake Addin
#addin nuget:?package=Embers&version=3.0.2

// Install Embers as a Cake Tool
#tool nuget:?package=Embers&version=3.0.2                

Noko

Embers

An embeddable Ruby interpreter written entirely in C#.

Its powerful, lightweight design is intended for use in game engines, game mods, and C# applications.

Features

  • Run Ruby code in C# .NET
  • Adapter to convert between .NET objects and Ruby instances
  • Multithreading and thread safety option
  • Simplified standard library
  • No external dependencies

Usage

Basic Example

using Embers;

Scope Scope = new();
Scope.Evaluate("puts 'Ruby!'"); // Ruby!

Adapter

Embers has an adapter which converts between .NET objects and Ruby instances. If an object is not built-in, its methods, fields and properties will be adapted. Methods such as SetVariable implicitly use the adapter for you.

class Pizza {
    public int Portions = 2;
    public string Topping = "Pepperoni";
}
Scope.SetVariable("pizza", typeof(Pizza));
string Topping = Scope.Evaluate("pizza.new.topping").CastString;
Console.WriteLine(Topping); // Pepperoni

Parsing

Expressions can be pre-parsed and interpreted much more quickly.

Expression[] Expressions = Scope.Parse("puts 'pre-parsed!'");
Expressions.Interpret(new Context(Scope.Location, Scope)); // pre-parsed!

Sandboxing

You can see which methods can still be accessed in StandardLibrary.cs.

Scope Scope = new(new AxisOptions() { Sandbox = true });
Scope.Evaluate("File.write('test.txt', 'text')"); // undefined method 'write' for File:Module

Game engine support

Embers is fully compatible with Godot, Unity, and other C# game engines.

Here's a counter example in Godot:

public partial class CounterScript : Node {
    [Export] RichTextLabel CounterLabel;

    Scope Scope;

    public override void _Ready() {
        Scope = new Scope();
        Scope.Axis.Object.SetInstanceVariable("@counter_label", CounterLabel);
        Scope.Evaluate(@"
@counter = 0
def _process
  @counter += 1
  @counter_label.text = @counter.to_s
end
        ");
    }
    public override void _Process(double Delta) {
        Scope.Axis.Main.CallMethod("_process");
    }
}

Note that methods such as puts reference Console, which is hidden in Godot and Unity by default. They can be changed or overridden:

// In StandardLibrary.cs
Console.WriteLine(Message.ToS()); // -> Godot.GD.Print(Message.ToS());

About Noko

Noko is Embers' mascot who you can see at the top.

She comes from a society in the Earth's core, 3000km below the surface. She has fiery powers but finds the surface a bit cold.

Noko is short for "Nokoribi" meaning "Embers" in Japanese.

Made with Embers

Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net7.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
3.1.4 149 2/23/2024
3.1.3 116 2/17/2024
3.1.2 146 2/14/2024
3.1.1 102 2/12/2024
3.1.0 126 2/7/2024
3.0.4 111 2/4/2024
3.0.3 96 2/4/2024
3.0.2 106 2/2/2024
3.0.1 99 1/30/2024
3.0.0 100 1/29/2024
2.0.1 190 11/22/2023
2.0.0 136 11/16/2023