public
Last active

Rubinius Embed Example

  • Download Gist
a.rb
Ruby
1 2 3 4 5 6 7 8
puts __FILE__
 
def salad
"caesar"
end
 
foo
puts salad
b.rb
Ruby
1 2 3
puts __FILE__
 
puts "This is file b"
main.cpp
C++
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
 
#include "embed.h"
 
int main(int argc, char** argv) {
rbx_ctx rbx = rbx_create_context();
printf("** rbx_require_file\n");
rbx_require_file(rbx, "req.rb");
printf("\n** rbx_eval_file\n");
rbx_eval_file(rbx, "a.rb");
printf("\n** rbx_eval_file\n");
rbx_eval_file(rbx, "b.rb");
printf("\n** rbx_eval\n");
rbx_eval(rbx, "puts 'Hello, World!';10.times { |i| puts \"Hello, W#{'o' * (i+2)}rld!\" }");
rbx_close_context(rbx);
return 0;
}
req.rb
Ruby
1 2 3 4 5
def foo
puts "foo method called"
end
 
puts "#{__FILE__} required"

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.