RubyCLR now inlines C#:
class InliningTests < TestCase
def test_class_inline
Inline::compile :csharp, <<-EOF
namespace Scratch {
public class Fibonnaci {
public static long Calc(long n) {
long x1 = 1, x2 = 2, tmp;
for (long i = 1; i < n; ++i) {
x1 += x2;
tmp = x2; x2 = x1; x1 = tmp;
}
return x1;
}
}
}
EOF
assert_equal 8, Scratch::Fibonnaci.calc(5)
end
end
I shell out to the C# compiler to compile the embedded C# source code. I’ll be adding some code to inline C# methods as well so that you can define a Ruby method signature that has a C# implementation.
Update: Please disregard this grotesque hack. See the new and improved version.
2 archived reader comments
Eric Hodel (2006-03-30)
You don’t seem to be using RubyInline…
It should be easy to plug right into it…
John Lam (2006-03-30)
When I hacked out this code I was in the library, and couldn’t download RubyInline.
The C# compiler has a set of managed wrappers that let me pass a string, and it generates the temp file, compiles to a temp assembly and loads it all in one fell swoop. I suspect that RubyInline tries to do most of that stuff for me which I don’t really need …