From e634ca18ede7671b61f8b365b47fb1ba30e52855 Mon Sep 17 00:00:00 2001 From: Paolo Bosetti Date: Tue, 22 May 2012 22:34:16 -0700 Subject: Created Xcode 4 project, using the make target to build the tools, and with a native Xcode target to build a hello world example. --- xcode/HelloMRuby/hello_mruby.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 xcode/HelloMRuby/hello_mruby.c (limited to 'xcode/HelloMRuby') diff --git a/xcode/HelloMRuby/hello_mruby.c b/xcode/HelloMRuby/hello_mruby.c new file mode 100644 index 000000000..2cfa38143 --- /dev/null +++ b/xcode/HelloMRuby/hello_mruby.c @@ -0,0 +1,39 @@ +// +// hello_mruby.c +// mruby +// +// Created by Paolo Bosetti on 5/22/12. +// Copyright (c) 2012 University of Trento. All rights reserved. +// + +#include +#include + +/* Include the mruby header */ +#include +#include +#include +#include + + + +int main(int argc, const char * argv[]) +{ + struct mrb_parser_state *parse; + mrb_state *mrb = mrb_open(); + char code[] = "p 'hello world!'"; + int n; + + printf("Executing Ruby code from C!\n"); + parse = mrb_parse_string(mrb, code); + n = mrb_generate_code(mrb, parse->tree); + + mrb_run(mrb, mrb_proc_new(mrb, mrb->irep[n]), mrb_top_self(mrb)); + + if (mrb->exc) { + mrb_p(mrb, mrb_obj_value(mrb->exc)); + } + + mrb_close(mrb); + return 0; +} \ No newline at end of file -- cgit v1.2.3