Guest User

Untitled

a guest
Jan 5th, 2024
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. #include <ruby.h>
  2.  
  3. void t_free(Image *m)
  4. {
  5. myown_free(*m);
  6. free(m);
  7. }
  8.  
  9. static VALUE t_allocate(VALUE obj)
  10. {
  11. struct my *m = malloc(sizeof(struct my));
  12. if( m == NULL )
  13. rb_raise(rb_eNoMemError, "Brakuje pamięci na obiekt Obraz (%zu bajty)", sizeof(struct my));
  14.  
  15. return Data_Wrap_Struct(obj, NULL, t_free, m);
  16. }
  17.  
  18. how creating ???
  19.  
  20. VALUE t_neww(VALUE obiekt)
  21. {
  22. VALUE obj;
  23.  
  24. obj = t_allocate(obiekt);
  25. rb_obj_call_init(obj, 1, NULL);
  26.  
  27. return obj;
  28. }
  29.  
  30.  
  31. void Init_My()
  32. {
  33. ca = rb_define_class("MyOwn", rb_cObject);
  34. rb_define_alloc_func(ca,t_allocate);
  35.  
  36. rb_define_method(ca, "initialize", t_init, 2); //it working
  37. rb_define_method(ca, "neww", t_neww, 0); // it no working
  38.  
Advertisement
Add Comment
Please, Sign In to add comment