Font: 'exist?' allows any object (returns false if not string)

This commit is contained in:
Jonas Kulla 2014-08-09 17:18:42 +02:00
parent 6c9fbc1465
commit cc0ab35f10
3 changed files with 17 additions and 4 deletions

View File

@ -33,8 +33,13 @@ RB_METHOD(fontDoesExist)
{ {
RB_UNUSED_PARAM; RB_UNUSED_PARAM;
const char *name; const char *name = 0;
rb_get_args(argc, argv, "z", &name RB_ARG_END); VALUE nameObj;
rb_get_args(argc, argv, "o", &nameObj RB_ARG_END);
if (rb_type(nameObj) == RUBY_T_STRING)
name = rb_string_value_cstr(&nameObj);
return rb_bool_new(Font::doesExist(name)); return rb_bool_new(Font::doesExist(name));
} }

View File

@ -30,8 +30,13 @@ DEF_TYPE(Font);
MRB_FUNCTION(fontDoesExist) MRB_FUNCTION(fontDoesExist)
{ {
const char *name; const char *name = 0;
mrb_get_args(mrb, "z", &name); mrb_value nameObj;
mrb_get_args(mrb, "o", &nameObj);
if (mrb_string_p(nameObj))
name = mrb_string_value_cstr(mrb, &nameObj);
return mrb_bool_value(Font::doesExist(name)); return mrb_bool_value(Font::doesExist(name));
} }

View File

@ -247,6 +247,9 @@ Color FontPrivate::defaultColorTmp(255, 255, 255, 255);
bool Font::doesExist(const char *name) bool Font::doesExist(const char *name)
{ {
if (!name)
return false;
return shState->fontState().fontPresent(name); return shState->fontState().fontPresent(name);
} }