Archived
1
0
Fork 0

Implement Tox#savedata

This commit is contained in:
Braiden Vasco 2015-09-11 22:32:46 +00:00
parent beb90a36be
commit 063475b597

View file

@ -12,6 +12,7 @@ static VALUE cTox;
static VALUE cTox_alloc(VALUE klass); static VALUE cTox_alloc(VALUE klass);
static void cTox_free(void *ptr); static void cTox_free(void *ptr);
static VALUE cTox_initialize(VALUE self, VALUE options); static VALUE cTox_initialize(VALUE self, VALUE options);
static VALUE cTox_savedata(VALUE self);
typedef struct Tox_Options cTox_cOptions_; typedef struct Tox_Options cTox_cOptions_;
@ -25,6 +26,7 @@ void Init_tox()
cTox = rb_define_class("Tox", rb_cObject); cTox = rb_define_class("Tox", rb_cObject);
rb_define_alloc_func(cTox, cTox_alloc); rb_define_alloc_func(cTox, cTox_alloc);
rb_define_method(cTox, "initialize", cTox_initialize, 1); rb_define_method(cTox, "initialize", cTox_initialize, 1);
rb_define_method(cTox, "savedata", cTox_savedata, 0);
cTox_cOptions = rb_define_class_under(cTox, "Options", rb_cObject); cTox_cOptions = rb_define_class_under(cTox, "Options", rb_cObject);
rb_define_alloc_func(cTox_cOptions, cTox_cOptions_alloc); rb_define_alloc_func(cTox_cOptions, cTox_cOptions_alloc);
@ -66,6 +68,26 @@ VALUE cTox_initialize(const VALUE self, const VALUE options)
return self; return self;
} }
VALUE cTox_savedata(VALUE self)
{
cTox_ *tox;
size_t data_size;
char *data;
Data_Get_Struct(self, cTox_, tox);
data_size = tox_get_savedata_size(tox->tox);
data = ALLOC_N(char, data_size);
// if (!data)
// rb_raise();
tox_get_savedata(tox->tox, (uint8_t*)data);
return rb_str_new(data, data_size);
}
/****************************************************************************** /******************************************************************************
* Tox::Options * Tox::Options
******************************************************************************/ ******************************************************************************/