Skip to content

Instantly share code, notes, and snippets.

@matsumotory
Created June 5, 2012 08:12
Show Gist options
  • Select an option

  • Save matsumotory/2873539 to your computer and use it in GitHub Desktop.

Select an option

Save matsumotory/2873539 to your computer and use it in GitHub Desktop.
mruby Bug? mruby cannot output int variables by mrb_define_method.
/*
gcc -I mruby/include -I mruby/src -O3 -g -Wall -Werror-implicit-function-declaration mruby_int_bug.c -lm mruby/mrblib/mrblib.o -lm mruby/lib/libmruby.a
*/
#include <string.h>
#include "mruby.h"
#include "mruby/proc.h"
#include "mruby/compile.h"
mrb_value mrb_num_get(mrb_state *mrb, mrb_value str)
{
return mrb_fixnum_value(100);
}
mrb_value mrb_st_get(mrb_state *mrb, mrb_value str)
{
return mrb_str_new(mrb, "hoge", strlen("hoge"));
}
int main() {
int n;
mrb_state* mrb;
struct mrb_parser_state* p;
struct RClass *class;
struct RClass *class_int;
mrb = mrb_open();
class = mrb_define_module(mrb, "Bug");
class_int = mrb_define_class_under(mrb, class, "Check", mrb->object_class);
mrb_define_method(mrb, class_int, "int", mrb_num_get, ARGS_NONE());
mrb_define_method(mrb, class_int, "st", mrb_st_get, ARGS_NONE());
char* code =
"require 'Bug' \n"
"t = Bug::Check.new() \n"
"puts('-------------------') \n"
"puts('aaa ' + t.st) \n"
//"p('aaa ' + t.int) \n"
"p(t.int) \n"
"p('bbb ' + t.st) \n"
"puts('-------------------') \n";
p = mrb_parse_string(mrb, code);
n = mrb_generate_code(mrb, p->tree);
mrb_pool_close(p->pool);
mrb_run(mrb, mrb_proc_new(mrb, mrb->irep[n]), mrb_nil_value());
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment