Skip to content

How to get pointer to bool to pass to wrapped function? #5618

Answered by Morgayse
Morgayse asked this question in Q&A
Discussion options

You must be logged in to vote

Here is what I'm currently using for int*, float*, and bool*.

  static const mrb_data_type IntPtr_type = {"IntPtr", mrb_free};
  static const mrb_data_type FloatPtr_type = {"FloatPtr", mrb_free};
  static const mrb_data_type BoolPtr_type = {"BoolPtr", mrb_free};
  // ...
  RClass* const IntPtr_class = mrb_define_class(mrb, "IntPtr", mrb->object_class);
  MRB_SET_INSTANCE_TT(IntPtr_class, MRB_TT_DATA);
  mrb_define_method(mrb, IntPtr_class, "initialize", [](mrb_state* mrb, mrb_value self) -> mrb_value {
      mrb_int n;
      mrb_get_args(mrb, "i", &n);
      int* data = (int*)DATA_PTR(self);
      if(data) { mrb_free(mrb, data); }
      mrb_data_init(self, nullptr, &IntPtr_type);
      data 

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
4 replies
@Morgayse
Comment options

@Morgayse
Comment options

@dearblue
Comment options

@Morgayse
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by Morgayse
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants