Created
April 23, 2019 13:24
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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