Skip to content

Instantly share code, notes, and snippets.

@alphaKAI
Created April 23, 2019 13:24
Show Gist options
  • Save alphaKAI/26614466ada084a9b3c4668b1f90ec00 to your computer and use it in GitHub Desktop.
Save alphaKAI/26614466ada084a9b3c4668b1f90ec00 to your computer and use it in GitHub Desktop.
Ruby embedded into D. compile: dmd rbd.d -L-L/path/to/ruby/lib -L-lruby.2.6
/*
Ruby embedded into D.
compile: dmd rbd.d -L-L/path/to/ruby/lib -L-lruby.2.6
Example... dmd rbd.d -L-L/usr/local/opt/ruby/lib -L-lruby.2.6
*/
import std.stdio,
std.string;
extern (C) {
void ruby_init();
int ruby_cleanup(int);
int rb_eval_string_protect(const char*, int*);
}
static this() {
ruby_init();
}
static ~this() {
ruby_cleanup(0);
}
void ruby(string rb_code)() {
int state;
rb_eval_string_protect(rb_code.toStringz, &state);
if (state) {
throw new Exception("Some Error");
}
}
void main() {
ruby!q{
puts "Hello, Ruby world! This is invoked by D"
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment