Skip to content

Instantly share code, notes, and snippets.

@amirrajan
Last active July 26, 2018 20:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amirrajan/6d5fc4e11ce5676fb574734405bc9759 to your computer and use it in GitHub Desktop.
Save amirrajan/6d5fc4e11ce5676fb574734405bc9759 to your computer and use it in GitHub Desktop.
mruby hello world.
# 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
#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