2012-05-25 02:20:36 +00:00
|
|
|
#include <ruby.h>
|
|
|
|
#include <ruby/encoding.h>
|
|
|
|
|
|
|
|
static VALUE
|
2012-05-25 07:13:03 +00:00
|
|
|
printf_test_i(VALUE self, VALUE obj)
|
2012-05-25 02:20:36 +00:00
|
|
|
{
|
|
|
|
char buf[256];
|
|
|
|
snprintf(buf, sizeof(buf), "<%"PRIsVALUE">", obj);
|
|
|
|
return rb_usascii_str_new2(buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
2012-05-25 07:13:03 +00:00
|
|
|
printf_test_s(VALUE self, VALUE obj)
|
2012-05-25 02:20:36 +00:00
|
|
|
{
|
|
|
|
return rb_enc_sprintf(rb_usascii_encoding(), "<%"PRIsVALUE">", obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
2012-05-25 07:13:03 +00:00
|
|
|
printf_test_v(VALUE self, VALUE obj)
|
2012-05-25 02:20:36 +00:00
|
|
|
{
|
|
|
|
return rb_enc_sprintf(rb_usascii_encoding(), "{%+"PRIsVALUE"}", obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Init_printf(void)
|
|
|
|
{
|
|
|
|
VALUE m = rb_define_module_under(rb_define_module("Bug"), "Printf");
|
2012-05-25 07:13:03 +00:00
|
|
|
rb_define_singleton_method(m, "i", printf_test_i, 1);
|
|
|
|
rb_define_singleton_method(m, "s", printf_test_s, 1);
|
|
|
|
rb_define_singleton_method(m, "v", printf_test_v, 1);
|
2012-05-25 02:20:36 +00:00
|
|
|
}
|