Skip to content

Commit b93dbb4

Browse files
author
Andrew Havens
committed
Initial commit
0 parents  commit b93dbb4

File tree

6 files changed

+50
-0
lines changed

6 files changed

+50
-0
lines changed

01_ruby_in_a_string/example.c

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include <stdlib.h>
2+
#include <stdio.h>
3+
#include <mruby.h>
4+
5+
int main(void)
6+
{
7+
mrb_state *mrb = mrb_open();
8+
char code[] = "p 'hello world!'";
9+
mrb_load_string(mrb, code);
10+
return 0;
11+
}

02_ruby_in_an_external_file/example.c

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include <stdlib.h>
2+
#include <stdio.h>
3+
#include <mruby.h>
4+
5+
int main(void)
6+
{
7+
mrb_state *mrb = mrb_open();
8+
FILE *f = fopen("example.rb", "r");
9+
mrb_load_file(mrb, f);
10+
return 0;
11+
}
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
p 'Hello World!'

03_calling_c_from_ruby/example.c

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include <stdlib.h>
2+
#include <stdio.h>
3+
4+
#include <mruby.h>
5+
#include <mruby/compile.h>
6+
7+
static mrb_value my_c_method(mrb_state *mrb, mrb_value value)
8+
{
9+
puts("Called my C method");
10+
return value;
11+
}
12+
13+
int main(void)
14+
{
15+
mrb_state *mrb = mrb_open();
16+
17+
struct RClass *mymodule = mrb_define_module(mrb, "MyModule");
18+
mrb_define_class_method(mrb, mymodule, "my_c_method", my_c_method, MRB_ARGS_NONE());
19+
20+
FILE *f = fopen("example.rb", "r");
21+
mrb_load_file(mrb, f);
22+
23+
return 0;
24+
}

03_calling_c_from_ruby/example.rb

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
puts 'Running some code in mruby!'
2+
MyModule.my_c_method

04_calling_ruby_from_c/TODO

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
TODO

0 commit comments

Comments
 (0)