Last active
July 26, 2018 20:57
-
-
Save amirrajan/6d5fc4e11ce5676fb574734405bc9759 to your computer and use it in GitHub Desktop.
mruby hello world.
This file contains 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
# put all your ruby code in ./app | |
# this assumes you have cloned mruby as a sibling directory (hense the relative -lm switch) | |
cat ./app/* > ./index.rb | |
mrbc -Bindex ./index.rb | |
gcc -std=c99 -I../mruby/include main.c -o main ../mruby/build/host/lib/libmruby.a -lm | |
echo "done" | |
./main |
This file contains 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
#include <mruby.h> | |
#include <mruby/variable.h> | |
#include <mruby/string.h> | |
#include <mruby/irep.h> | |
#include "index.c" | |
#include <stdio.h> | |
int | |
main(void) | |
{ | |
mrb_state *mrb = mrb_open(); | |
mrb_load_irep(mrb, index); | |
struct RClass *testClass = mrb_class_get(mrb, "Tests"); | |
mrb_value tests = | |
mrb_funcall(mrb, | |
mrb_obj_value(testClass), | |
"new", | |
0); | |
mrb_funcall(mrb, | |
tests, | |
"run", | |
0); | |
if (mrb->exc) { | |
mrb_value obj = mrb_funcall(mrb, mrb_obj_value(mrb->exc), "inspect", 0); | |
fwrite(RSTRING_PTR(obj), RSTRING_LEN(obj), 1, stdout); | |
putc('\n', stdout); | |
} | |
mrb_close(mrb); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment