1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#include <ruby.h> #include <ruby/encoding.h> static VALUE enc_raise(VALUE exc, VALUE encoding, VALUE mesg) { rb_enc_raise(rb_to_encoding(encoding), exc, "%s", StringValueCStr(mesg)); UNREACHABLE; } void Init_enc_raise(VALUE klass) { rb_define_module_function(klass, "enc_raise", enc_raise, 2); }