static mrb_value writer_write(mrb_state *mrb, mrb_value self) { grn_ctx *ctx = (grn_ctx *)mrb->ud; mrb_value target; mrb_get_args(mrb, "o", &target); switch (mrb_type(target)) { case MRB_TT_FALSE : GRN_OUTPUT_BOOL(GRN_FALSE); break; case MRB_TT_TRUE : GRN_OUTPUT_BOOL(GRN_TRUE); break; case MRB_TT_FIXNUM : GRN_OUTPUT_INT32(mrb_fixnum(target)); break; case MRB_TT_FLOAT : GRN_OUTPUT_FLOAT(mrb_float(target)); break; case MRB_TT_STRING : GRN_OUTPUT_STR(RSTRING_PTR(target), RSTRING_LEN(target)); break; default : mrb_raisef(mrb, E_ARGUMENT_ERROR, "must be true, false, number, float or string: %S", target); break; } return mrb_nil_value(); }
static mrb_value writer_write(mrb_state *mrb, mrb_value self) { grn_ctx *ctx = (grn_ctx *)mrb->ud; mrb_value target; mrb_get_args(mrb, "o", &target); switch (mrb_type(target)) { case MRB_TT_FALSE : if (mrb_nil_p(target)) { GRN_OUTPUT_NULL(); } else { GRN_OUTPUT_BOOL(GRN_FALSE); } break; case MRB_TT_TRUE : GRN_OUTPUT_BOOL(GRN_TRUE); break; case MRB_TT_FIXNUM : GRN_OUTPUT_INT32(mrb_fixnum(target)); break; case MRB_TT_FLOAT : GRN_OUTPUT_FLOAT(mrb_float(target)); break; case MRB_TT_SYMBOL : { const char *name; mrb_int name_length; name = mrb_sym2name_len(mrb, mrb_symbol(target), &name_length); GRN_OUTPUT_STR(name, name_length); } break; case MRB_TT_STRING : GRN_OUTPUT_STR(RSTRING_PTR(target), RSTRING_LEN(target)); break; default : mrb_raisef(mrb, E_ARGUMENT_ERROR, "must be nil, true, false, number, float, symbol or string: " "%S", target); break; } return mrb_nil_value(); }