Ejemplo n.º 1
0
static pic_value
pic_error_error_object_message(pic_state *pic)
{
  struct pic_error *e;

  pic_get_args(pic, "e", &e);

  return pic_obj_value(pic_str_new_cstr(pic, e->msg));
}
Ejemplo n.º 2
0
Archivo: symbol.c Proyecto: krig/picrin
static pic_value
pic_symbol_symbol_to_string(pic_state *pic)
{
  pic_value v;

  pic_get_args(pic, "o", &v);

  if (! pic_sym_p(v)) {
    pic_error(pic, "symbol->string: expected symbol");
  }

  return pic_obj_value(pic_str_new_cstr(pic, pic_symbol_name(pic, pic_sym(v))));
}
Ejemplo n.º 3
0
Archivo: regexp.c Proyecto: krig/picrin
static pic_value
pic_regexp_regexp_split(pic_state *pic)
{
  pic_value reg;
  const char *input;
  regmatch_t match;
  pic_value output = pic_nil_value();

  pic_get_args(pic, "oz", &reg, &input);

  pic_assert_type(pic, reg, regexp);

  while (regexec(&pic_regexp_data_ptr(reg)->reg, input, 1, &match, 0) != REG_NOMATCH) {
    pic_push(pic, pic_obj_value(pic_str_new(pic, input, match.rm_so)), output);

    input += match.rm_eo;
  }

  pic_push(pic, pic_obj_value(pic_str_new_cstr(pic, input)), output);

  return pic_reverse(pic, output);
}