mirror of
https://github.com/kemko/liquid.git
synced 2026-01-01 15:55:40 +03:00
If we are trying to get the struct from something other than self, then we should make sure to check the class of the object. This util functions make this easier.
22 lines
526 B
C
22 lines
526 B
C
#include <ruby.h>
|
|
|
|
void raise_type_error(VALUE expected, VALUE got)
|
|
{
|
|
rb_raise(rb_eTypeError, "wrong argument type %s (expected %s)",
|
|
rb_class2name(got), rb_class2name(expected));
|
|
}
|
|
|
|
void check_class(VALUE obj, int type, VALUE klass)
|
|
{
|
|
Check_Type(obj, type);
|
|
VALUE obj_klass = RBASIC_CLASS(obj);
|
|
if (obj_klass != klass)
|
|
raise_type_error(klass, obj_klass);
|
|
}
|
|
|
|
void *obj_get_data_ptr(VALUE obj, VALUE klass)
|
|
{
|
|
check_class(obj, T_DATA, klass);
|
|
return DATA_PTR(obj);
|
|
}
|