This is a port of the mruby/c tutorial Chapter 03 to the mbed environment.
For details, refer to the following.
http://www.s-itoc.jp/activity/research/mrubyc/mrubyc_tutorial/436
Note:There is a change in rtt0.h from the original source in the mruby/c. It was necessary for inclusion in C ++ source.
mrubyc/c_range.c
- Committer:
- tk_takateku
- Date:
- 2017-02-15
- Revision:
- 0:33feccbba3ff
File content as of revision 0:33feccbba3ff:
#include <stddef.h> #include "c_range.h" #include "alloc.h" #include "class.h" #include "static.h" #include "value.h" #include "vm.h" mrb_value mrbc_range_new(mrb_vm *vm, mrb_value *v_st, mrb_value *v_ed, int exclude) { mrb_value value; value.tt = MRB_TT_RANGE; mrb_value *ptr = (mrb_value*)mrbc_alloc(vm, sizeof(mrb_value)*3); if( ptr == NULL ) return value; // ENOMEM if( exclude ){ ptr[0].tt = MRB_TT_TRUE; } else { ptr[0].tt = MRB_TT_FALSE; } ptr[1] = *v_st; ptr[2] = *v_ed; value.value.range = ptr; return value; } // init class void mrbc_init_class_range(mrb_vm *vm) { mrbc_class_range = mrbc_class_alloc(vm, "Range", mrbc_class_object); }