Implement Tox#name, Tox#name=
This commit is contained in:
parent
eff4232af2
commit
38fdbf3974
2 changed files with 43 additions and 0 deletions
|
@ -33,5 +33,8 @@ have_library LIBTOXCORE, 'tox_group_message_send' and
|
||||||
have_library LIBTOXCORE, 'tox_callback_group_invite' and
|
have_library LIBTOXCORE, 'tox_callback_group_invite' and
|
||||||
have_library LIBTOXCORE, 'tox_callback_group_message' and
|
have_library LIBTOXCORE, 'tox_callback_group_message' and
|
||||||
have_library LIBTOXCORE, 'tox_group_peernumber_is_ours' and
|
have_library LIBTOXCORE, 'tox_group_peernumber_is_ours' and
|
||||||
|
have_library LIBTOXCORE, 'tox_self_get_name_size' and
|
||||||
|
have_library LIBTOXCORE, 'tox_self_get_name' and
|
||||||
|
have_library LIBTOXCORE, 'tox_self_set_name' and
|
||||||
|
|
||||||
create_makefile "#{NAME}/#{NAME}" or exit(1)
|
create_makefile "#{NAME}/#{NAME}" or exit(1)
|
||||||
|
|
|
@ -43,6 +43,8 @@ static VALUE cTox_friend_send_message(VALUE self, VALUE friend_number, VALUE tex
|
||||||
static VALUE cTox_join_groupchat(VALUE self, VALUE friend_number, VALUE data);
|
static VALUE cTox_join_groupchat(VALUE self, VALUE friend_number, VALUE data);
|
||||||
static VALUE cTox_group_message_send(VALUE self, VALUE group_number, VALUE text);
|
static VALUE cTox_group_message_send(VALUE self, VALUE group_number, VALUE text);
|
||||||
static VALUE cTox_group_peernumber_is_ours(VALUE self, VALUE group_number, VALUE peer_number);
|
static VALUE cTox_group_peernumber_is_ours(VALUE self, VALUE group_number, VALUE peer_number);
|
||||||
|
static VALUE cTox_name(VALUE self);
|
||||||
|
static VALUE cTox_name_ASSIGN(VALUE self, VALUE name);
|
||||||
|
|
||||||
static void on_friend_request(
|
static void on_friend_request(
|
||||||
Tox *tox,
|
Tox *tox,
|
||||||
|
@ -104,6 +106,8 @@ void Init_tox()
|
||||||
rb_define_method(cTox, "join_groupchat", cTox_join_groupchat, 2);
|
rb_define_method(cTox, "join_groupchat", cTox_join_groupchat, 2);
|
||||||
rb_define_method(cTox, "group_message_send", cTox_group_message_send, 2);
|
rb_define_method(cTox, "group_message_send", cTox_group_message_send, 2);
|
||||||
rb_define_method(cTox, "group_peernumber_is_ours", cTox_group_peernumber_is_ours, 2);
|
rb_define_method(cTox, "group_peernumber_is_ours", cTox_group_peernumber_is_ours, 2);
|
||||||
|
rb_define_method(cTox, "name", cTox_name, 0);
|
||||||
|
rb_define_method(cTox, "name=", cTox_name_ASSIGN, 1);
|
||||||
|
|
||||||
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);
|
||||||
|
@ -372,6 +376,42 @@ VALUE cTox_group_peernumber_is_ours(
|
||||||
return Qfalse;
|
return Qfalse;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VALUE cTox_name(const VALUE self)
|
||||||
|
{
|
||||||
|
cTox_ *tox;
|
||||||
|
|
||||||
|
char name[TOX_MAX_NAME_LENGTH];
|
||||||
|
size_t name_size;
|
||||||
|
|
||||||
|
Data_Get_Struct(self, cTox_, tox);
|
||||||
|
|
||||||
|
name_size = tox_self_get_name_size(tox->tox);
|
||||||
|
|
||||||
|
if (name_size > 0)
|
||||||
|
tox_self_get_name(tox->tox, (uint8_t*)name);
|
||||||
|
|
||||||
|
return rb_str_new(name, name_size);
|
||||||
|
}
|
||||||
|
|
||||||
|
VALUE cTox_name_ASSIGN(const VALUE self, const VALUE name)
|
||||||
|
{
|
||||||
|
cTox_ *tox;
|
||||||
|
|
||||||
|
bool result;
|
||||||
|
TOX_ERR_SET_INFO error;
|
||||||
|
|
||||||
|
Check_Type(name, T_STRING);
|
||||||
|
|
||||||
|
Data_Get_Struct(self, cTox_, tox);
|
||||||
|
|
||||||
|
result = tox_self_set_name(tox->tox, (uint8_t*)RSTRING_PTR(name), RSTRING_LEN(name), &error);
|
||||||
|
|
||||||
|
if (error != TOX_ERR_SET_INFO_OK || !result)
|
||||||
|
return Qfalse;
|
||||||
|
else
|
||||||
|
return Qtrue;
|
||||||
|
}
|
||||||
|
|
||||||
void on_friend_request(
|
void on_friend_request(
|
||||||
Tox *const tox,
|
Tox *const tox,
|
||||||
const uint8_t *const key,
|
const uint8_t *const key,
|
||||||
|
|
Reference in a new issue