Example #1
0
static mrb_value
mrb_mod_method_defined(mrb_state *mrb, mrb_value mod)
{
  mrb_value id;
  mrb_bool method_defined_p;

  id = get_sym_or_str_arg(mrb);
  if (mrb_symbol_p(id)) {
    method_defined_p = mrb_obj_respond_to(mrb_class_ptr(mod), mrb_symbol(id));
  } else {
    mrb_value sym = mrb_check_intern_str(mrb, id);
    if (mrb_nil_p(sym)) {
      method_defined_p = FALSE;
    }
    else {
      method_defined_p = mrb_obj_respond_to(mrb_class_ptr(mod), mrb_symbol(sym));
    }
  }
  return mrb_bool_value(method_defined_p);
}
Example #2
0
mrb_sym
mrb_class_sym(mrb_state *mrb, struct RClass *c, struct RClass *outer)
{
  mrb_value name;

  name = mrb_obj_iv_get(mrb, (struct RObject*)c, mrb_intern2(mrb, "__classid__", 11));
  if (mrb_nil_p(name)) {

    if (!outer) return 0;
    else {
      struct csym_arg arg;

      arg.c = c;
      arg.sym = 0;
      iv_foreach(mrb, outer->iv, csym_i, &arg);
      return arg.sym;
    }
  }
  return mrb_symbol(name);
}
Example #3
0
static mrb_value
mrb_http_request_port(mrb_state *mrb, mrb_value self)
{
    mrb_value value_context;
    mrb_http_parser_context* context;

    value_context = mrb_iv_get(mrb, self, mrb_intern(mrb, "parser_context"));
    Data_Get_Struct(mrb, value_context, &http_parser_context_type, context);
    if (!context) {
        mrb_raise(mrb, E_ARGUMENT_ERROR, "invalid argument");
    }
    if (context->handle.field_set & (1<<UF_PORT)) {
        return mrb_fixnum_value(context->handle.port);
    }
    mrb_value schema = mrb_http_request_schema(mrb, self);
    if (!mrb_nil_p(schema) && !strncmp("https", (char*) RSTRING_PTR(schema), RSTRING_LEN(schema))) {
        return mrb_fixnum_value(443);
    }
    return mrb_fixnum_value(80);
}
Example #4
0
/*
 *  call-seq:
 *     obj.inspect   -> string
 *
 *  Returns a string containing a human-readable representation of
 *  <i>obj</i>. If not overridden and no instance variables, uses the
 *  <code>to_s</code> method to generate the string.
 *  <i>obj</i>.  If not overridden, uses the <code>to_s</code> method to
 *  generate the string.
 *
 *     [ 1, 2, 3..4, 'five' ].inspect   #=> "[1, 2, 3..4, \"five\"]"
 *     Time.new.inspect                 #=> "2008-03-08 19:43:39 +0900"
 */
mrb_value
mrb_obj_inspect(mrb_state *mrb, mrb_value obj)
{
  if ((mrb_type(obj) == MRB_TT_OBJECT) && mrb_obj_basic_to_s_p(mrb, obj)) {
    long len = ROBJECT_NUMIV(obj);

    if (len > 0) {
      mrb_value str;
      const char *c = mrb_obj_classname(mrb, obj);

      str = mrb_sprintf(mrb, "-<%s:%p", c, (void*)&obj);
      return inspect_obj(mrb, obj, str, 0);
    }
    return mrb_any_to_s(mrb, obj);
  }
  else if (mrb_nil_p(obj)) {
    return mrb_str_new_cstr(mrb, "nil");
  }
  return mrb_funcall(mrb, obj, "to_s", 0, 0);
}
Example #5
0
static int
parser_settings_on_header_field(http_parser* parser, const char* at, size_t len)
{
  mrb_http_parser_context *context = (mrb_http_parser_context*) parser->data;
  mrb_state* mrb = context->mrb;

  int ai = mrb_gc_arena_save(mrb);
  if (context->was_header_value) {
    if (!mrb_nil_p(OBJECT_GET(mrb, context->instance, "last_header_field"))) {
      mrb_str_concat(mrb, OBJECT_GET(mrb, context->instance, "last_header_field"), OBJECT_GET(mrb, context->instance, "last_header_value"));
      OBJECT_SET(mrb, context->instance, "last_header_value", mrb_nil_value());
    }
    OBJECT_SET(mrb, context->instance, "last_header_field", mrb_str_new(mrb, at, len));
    context->was_header_value = FALSE;
  } else {
    mrb_str_concat(mrb, OBJECT_GET(mrb, context->instance, "last_header_field"), mrb_str_new(mrb, at, len));
  }
  mrb_gc_arena_restore(mrb, ai);
  return 0;
}
Example #6
0
MRB_API mrb_value
mrb_Float(mrb_state *mrb, mrb_value val)
{
  if (mrb_nil_p(val)) {
    mrb_raise(mrb, E_TYPE_ERROR, "can't convert nil into Float");
  }
  switch (mrb_type(val)) {
    case MRB_TT_FIXNUM:
      return mrb_float_value(mrb, (mrb_float)mrb_fixnum(val));

    case MRB_TT_FLOAT:
      return val;

    case MRB_TT_STRING:
      return mrb_float_value(mrb, mrb_str_to_dbl(mrb, val, TRUE));

    default:
      return mrb_convert_type(mrb, val, MRB_TT_FLOAT, "Float", "to_f");
  }
}
Example #7
0
File: array.c Project: iij/mruby
MRB_API mrb_value
mrb_ary_splat(mrb_state *mrb, mrb_value v)
{
  mrb_value a;

  if (mrb_array_p(v)) {
    return v;
  }

  if (!mrb_respond_to(mrb, v, mrb_intern_lit(mrb, "to_a"))) {
    return mrb_ary_new_from_values(mrb, 1, &v);
  }

  a = mrb_funcall(mrb, v, "to_a", 0);
  if (mrb_nil_p(a)) {
    return mrb_ary_new_from_values(mrb, 1, &v);
  }
  mrb_ensure_array_type(mrb, a);
  return a;
}
Example #8
0
File: range.c Project: jjue/mruby
static void
range_check(mrb_state *mrb, mrb_value a, mrb_value b)
{
  mrb_value ans;
  int ta;
  int tb;

  ta = mrb_type(a);
  tb = mrb_type(b);
  if ((ta == MRB_TT_FIXNUM || ta == MRB_TT_FLOAT) &&
      (tb == MRB_TT_FIXNUM || tb == MRB_TT_FLOAT)) {
    return;
  }

  ans =  mrb_funcall(mrb, a, "<=>", 1, b);
  if (mrb_nil_p(ans)) {
    /* can not be compared */
    mrb_raise(mrb, E_ARGUMENT_ERROR, "bad value for range");
  }
}
Example #9
0
static mrb_value
mrb_str_aref(mrb_state *mrb, mrb_value str, mrb_value indx)
{
  mrb_int idx;

  regexp_check(mrb, indx);
  switch (mrb_type(indx)) {
    case MRB_TT_FIXNUM:
      idx = mrb_fixnum(indx);

num_index:
      str = str_substr(mrb, str, idx, 1);
      if (!mrb_nil_p(str) && RSTRING_LEN(str) == 0) return mrb_nil_value();
      return str;

    case MRB_TT_STRING:
      if (str_index(mrb, str, indx, 0) != -1)
        return mrb_str_dup(mrb, indx);
      return mrb_nil_value();

    case MRB_TT_RANGE:
      /* check if indx is Range */
      {
        mrb_int beg, len;
        mrb_value tmp;

        len = RSTRING_LEN_UTF8(str);
        if (mrb_range_beg_len(mrb, indx, &beg, &len, len)) {
          tmp = str_subseq(mrb, str, beg, len);
          return tmp;
        }
        else {
          return mrb_nil_value();
        }
      }
    default:
      idx = mrb_fixnum(indx);
      goto num_index;
    }
    return mrb_nil_value();    /* not reached */
}
Example #10
0
static int
parser_settings_on_message_complete(http_parser* parser)
{
  mrb_http_parser_context *context = (mrb_http_parser_context*) parser->data;
  mrb_state* mrb = context->mrb;
  mrb_value c = context->instance;

  if (context->handle.field_set & (1<<UF_SCHEMA)) {
    OBJECT_SET(mrb, c, "schema", mrb_str_substr(mrb, OBJECT_GET(mrb, c, "buf"), context->handle.field_data[UF_SCHEMA].off, context->handle.field_data[UF_SCHEMA].len));
  }
  if (context->handle.field_set & (1<<UF_HOST)) {
    OBJECT_SET(mrb, c, "host", mrb_str_substr(mrb, OBJECT_GET(mrb, c, "buf"), context->handle.field_data[UF_HOST].off, context->handle.field_data[UF_HOST].len));
  }
  if (context->handle.field_set & (1<<UF_HOST)) {
    OBJECT_SET(mrb, c, "host", mrb_str_substr(mrb, OBJECT_GET(mrb, c, "buf"), context->handle.field_data[UF_HOST].off, context->handle.field_data[UF_HOST].len));
  }
  if (context->handle.field_set & (1<<UF_PORT)) {
    OBJECT_SET(mrb, c, "port", mrb_fixnum_value(context->handle.port));
  } else {
    if (context->handle.field_set & (1<<UF_SCHEMA)) {
      mrb_value schema = mrb_str_substr(mrb, OBJECT_GET(mrb, c, "buf"), context->handle.field_data[UF_SCHEMA].off, context->handle.field_data[UF_SCHEMA].len);
      if (!mrb_nil_p(schema) && !strcmp("https", (char*) RSTRING_PTR(schema))) {
        OBJECT_SET(mrb, c, "port", mrb_fixnum_value(443));
      }
    }
  }
  if (context->handle.field_set & (1<<UF_PATH)) {
    OBJECT_SET(mrb, c, "path", mrb_str_substr(mrb, OBJECT_GET(mrb, c, "buf"), context->handle.field_data[UF_PATH].off, context->handle.field_data[UF_PATH].len));
  }
  if (context->handle.field_set & (1<<UF_QUERY)) {
    OBJECT_SET(mrb, c, "query", mrb_str_substr(mrb, OBJECT_GET(mrb, c, "buf"), context->handle.field_data[UF_QUERY].off, context->handle.field_data[UF_QUERY].len));
  }
  OBJECT_SET(mrb, c, "method", mrb_str_new_cstr(mrb, http_method_str(context->parser.method)));
  OBJECT_SET(mrb, c, "status_code", mrb_fixnum_value(context->parser.status_code));
  OBJECT_SET(mrb, c, "content_length", mrb_fixnum_value(context->parser.content_length));
  OBJECT_REMOVE(mrb, c, "last_header_field");
  OBJECT_REMOVE(mrb, c, "last_header_value");
  OBJECT_REMOVE(mrb, c, "buf");

  return 0;
}
static mrb_value
bs_locate_handle_buffer(mrb_state *mrb, mrb_value self)
{
    mrb_value guid;
    mrb_value ret;
    UINTN size;
    EFI_HANDLE *phandles;

    mrb_get_args(mrb, "o", &guid);
    if (mrb_nil_p(guid)){
        /* AllHandles */
        EFI_STATUS status;
        status = gBS->LocateHandleBuffer(AllHandles, NULL, NULL, &size, &phandles);
        if (EFI_ERROR(status)){
            return mrb_nil_value();
        }
    }else{
        /* ByProtocol */
        EFI_STATUS status;
        EFI_GUID efi_guid;

        mrb_uefi_guid_get_guid(mrb, guid, &efi_guid);
        status = gBS->LocateHandleBuffer(ByProtocol, &efi_guid, NULL, &size, &phandles);
        if (EFI_ERROR(status)){
            return mrb_nil_value();
        }
    }

    ret = mrb_ary_new_capa(mrb, (int)size);
    {
        UINTN i;
        for (i=0; i<size; i++){
            int arena = mrb_gc_arena_save(mrb);
            mrb_ary_push(mrb, ret, mrb_uefi_handle_make(mrb, phandles[i]));
            mrb_gc_arena_restore(mrb, arena);
        }
    }
    gBS->FreePool(phandles);

    return ret;
}
Example #12
0
static mrb_value
method_parameters(mrb_state *mrb, mrb_value self)
{
  mrb_value proc = mrb_iv_get(mrb, self, mrb_intern_lit(mrb, "proc"));
  struct RProc *rproc;
  struct RClass *orig;
  mrb_value ret;

  if (mrb_nil_p(proc)) {
    mrb_value rest = mrb_symbol_value(mrb_intern_lit(mrb, "rest"));
    mrb_value arest = mrb_ary_new_from_values(mrb, 1, &rest);
    return mrb_ary_new_from_values(mrb, 1, &arest);
  }

  rproc = mrb_proc_ptr(proc);
  orig = rproc->c;
  rproc->c = mrb->proc_class;
  ret = mrb_funcall(mrb, proc, "parameters", 0);
  rproc->c = orig;
  return ret;
}
// FLTK::NativeFileChooser#filename(index=nil)
// Return the filename the user choose. If index is given, return one of the filenames the user selected.
mrb_value mrb_fltk_native_file_chooser_filename_instance_method( mrb_state *mrb, mrb_value self ) {
  // TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO
  // Segfaults! Wowza
  // TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO
  GET_DATA( fl_native_file_chooser, Fl_Native_File_Chooser, self );

  mrb_value mrb_index;
  mrb_get_args( mrb, "|i", &mrb_index );

  mrb_value mrb_filename;

  if( mrb_nil_p( mrb_index ) ) {
    mrb_filename = mrb_str_new_cstr( mrb, fl_native_file_chooser->filename() );
  } else {
    mrb_filename = mrb_str_new_cstr( mrb, fl_native_file_chooser->filename( mrb_fixnum( mrb_index ) ) );
  }
  printf( "-==--==--==-=-=-=-=-=-=-=-=--=-=-=----------\n" );
  mrb_p( mrb, mrb_filename );
  printf( "-==--==--==-=-=-=-=-=-=-=-=--=-=-=----------\n" );
  return mrb_filename;
}
Example #14
0
File: random.c Project: ASnow/mruby
static mrb_value
mrb_random_srand(mrb_state *mrb, mrb_value self)
{
  mrb_value seed;
  mrb_value old_seed;
  mt_state *t = DATA_GET_PTR(mrb, self, &mt_state_type, mt_state);

  seed = get_opt(mrb);
  seed = mrb_random_mt_srand(mrb, t, seed);
  old_seed = t->has_seed? mrb_fixnum_value(t->seed) : mrb_nil_value();
  if (mrb_nil_p(seed)) {
    t->has_seed = FALSE;
  }
  else {
    mrb_assert(mrb_fixnum_p(seed));
    t->has_seed = TRUE;
    t->seed = mrb_fixnum(seed);
  }

  return old_seed;
}
mrb_value
mrb_UV_Shutdown_set_handle(mrb_state* mrb, mrb_value self) {
  uv_shutdown_t * native_self = mruby_unbox_uv_shutdown_t(self);
  mrb_value handle;

  mrb_get_args(mrb, "o", &handle);

  /* type checking */
  if (!mrb_obj_is_kind_of(mrb, handle, Stream_class(mrb))) {
    mrb_raise(mrb, E_TYPE_ERROR, "Stream expected");
    return mrb_nil_value();
  }

  uv_stream_t * native_handle = (mrb_nil_p(handle) ? NULL : mruby_unbox_uv_stream_t(handle));

  native_self->handle = native_handle;
  
  mrb_value value_as_mrb_value;
  mrb_get_args(mrb, "o", &value_as_mrb_value);
  return value_as_mrb_value;
}
mrb_value
mrb_UV_Getnameinfo_set_loop(mrb_state* mrb, mrb_value self) {
  uv_getnameinfo_t * native_self = mruby_unbox_uv_getnameinfo_t(self);
  mrb_value loop;

  mrb_get_args(mrb, "o", &loop);

  /* type checking */
  if (!mrb_obj_is_kind_of(mrb, loop, Loop_class(mrb))) {
    mrb_raise(mrb, E_TYPE_ERROR, "Loop expected");
    return mrb_nil_value();
  }

  uv_loop_t * native_loop = (mrb_nil_p(loop) ? NULL : mruby_unbox_uv_loop_t(loop));

  native_self->loop = native_loop;
  
  mrb_value value_as_mrb_value;
  mrb_get_args(mrb, "o", &value_as_mrb_value);
  return value_as_mrb_value;
}
Example #17
0
static mrb_value
mrb_http_parser_parse(mrb_state *mrb, mrb_value self)
{
    mrb_value arg_data;
    mrb_value value_context;
    mrb_http_parser_context* context;
    struct RProc *b = NULL;

    value_context = mrb_iv_get(mrb, self, mrb_intern(mrb, "parser_context"));
    Data_Get_Struct(mrb, value_context, &http_parser_context_type, context);
    if (!context) {
        mrb_raise(mrb, E_ARGUMENT_ERROR, "invalid argument");
    }

    mrb_get_args(mrb, "bo", &b, &arg_data);
    if (mrb_nil_p(arg_data)) {
        mrb_raise(mrb, E_ARGUMENT_ERROR, "invalid argument");
    }
    mrb_iv_set(mrb, self, mrb_intern(mrb, "complete_cb"), b ? mrb_obj_value(b) : mrb_nil_value());

    context->parser.data = context;
    context->was_header_value = TRUE;
    CTXV_SET(context, "headers", mrb_hash_new(mrb, 32));

    http_parser_init(&context->parser, HTTP_REQUEST);

    context->settings.on_url = parser_settings_on_url;
    context->settings.on_header_field = parser_settings_on_header_field;
    context->settings.on_header_value = parser_settings_on_header_value;
    context->settings.on_headers_complete = parser_settings_on_headers_complete;
    if (b) {
        context->settings.on_message_complete = parser_settings_on_message_complete;
    }

    if (RSTRING_LEN(arg_data) > 0) {
        http_parser_execute(&context->parser, &context->settings, (char*) RSTRING_PTR(arg_data), RSTRING_CAPA(arg_data));
    }

    return mrb_nil_value();
}
Example #18
0
/* mrb_gc_unregister() removes the object from GC root. */
MRB_API void
mrb_gc_unregister(mrb_state *mrb, mrb_value obj)
{
  mrb_sym root = mrb_intern_lit(mrb, GC_ROOT_NAME);
  mrb_value table = mrb_gv_get(mrb, root);
  struct RArray *a;
  mrb_int i, j;

  if (mrb_nil_p(table)) return;
  if (mrb_type(table) != MRB_TT_ARRAY) {
    mrb_gv_set(mrb, root, mrb_nil_value());
    return;
  }
  a = mrb_ary_ptr(table);
  mrb_ary_modify(mrb, a);
  for (i=j=0; i<a->len; i++) {
    if (!mrb_obj_eq(mrb, a->ptr[i], obj)) {
      a->ptr[j++] = a->ptr[i];
    }
  }
  a->len = j;
}
Example #19
0
// FLTK::Widget#callback
// Gets or sets the current callback function for the widget.
mrb_value mrb_fltk_widget_callback_instance_method( mrb_state *mrb, mrb_value self ) {
  GET_DATA( fl_widget, Fl_Widget, self );

  mrb_value block = mrb_nil_value();

  mrb_get_args( mrb, "&", &block );

  if( !mrb_nil_p( block ) ) {
    // TODO: Free the existing context struct if it already exists?
    mrb_iv_set( mrb, self, mrb_intern_cstr( mrb, "callback" ), block );

    mrb_fltk_widget_callback_context *context = (mrb_fltk_widget_callback_context *)malloc( sizeof( mrb_fltk_widget_callback_context ) );
    context->mrb = mrb;
    context->self = self;

    fl_widget->callback( mrb_fltk_widget_callback_function, context );
  } else {
    block = mrb_iv_get( mrb, self, mrb_intern_cstr( mrb, "callback" ) );
  }

  return block;
}
Example #20
0
File: error.c Project: deweerdt/h2o
static mrb_value
exc_get_backtrace(mrb_state *mrb, mrb_value exc)
{
  mrb_sym attr_name;
  mrb_value backtrace;

  attr_name = mrb_intern_lit(mrb, "backtrace");
  backtrace = mrb_iv_get(mrb, exc, attr_name);
  if (mrb_nil_p(backtrace)) {
    if (mrb_obj_ptr(exc) == mrb->backtrace.exc && mrb->backtrace.n > 0) {
      backtrace = mrb_restore_backtrace(mrb);
      mrb->backtrace.n = 0;
      mrb->backtrace.exc = 0;
    }
    else {
      backtrace = mrb_exc_backtrace(mrb, exc);
    }
    mrb_iv_set(mrb, exc, attr_name, backtrace);
  }

  return backtrace;
}
/* set_author
 *
 * Parameters:
 * - value: const git_signature *
 */
mrb_value
mrb_Git_DiffFormatEmailOptions_set_author(mrb_state* mrb, mrb_value self) {
  git_diff_format_email_options * native_self = mruby_unbox_git_diff_format_email_options(self);
  mrb_value author;

  mrb_get_args(mrb, "o", &author);

  /* type checking */
  if (!mrb_obj_is_kind_of(mrb, author, Signature_class(mrb))) {
    mrb_raise(mrb, E_TYPE_ERROR, "Signature expected");
    return mrb_nil_value();
  }

  const git_signature * native_author = (mrb_nil_p(author) ? NULL : mruby_unbox_git_signature(author));

  native_self->author = native_author;
  
  /* Hacky way to return whatever was passed in. Mirrors typical assignment semantics. */
  mrb_value value_as_mrb_value;
  mrb_get_args(mrb, "o", &value_as_mrb_value);
  return value_as_mrb_value;
}
/* set_id
 *
 * Parameters:
 * - value: const git_oid *
 */
mrb_value
mrb_Git_DiffFormatEmailOptions_set_id(mrb_state* mrb, mrb_value self) {
  git_diff_format_email_options * native_self = mruby_unbox_git_diff_format_email_options(self);
  mrb_value id;

  mrb_get_args(mrb, "o", &id);

  /* type checking */
  if (!mrb_obj_is_kind_of(mrb, id, Oid_class(mrb))) {
    mrb_raise(mrb, E_TYPE_ERROR, "Oid expected");
    return mrb_nil_value();
  }

  const git_oid * native_id = (mrb_nil_p(id) ? NULL : mruby_unbox_git_oid(id));

  native_self->id = native_id;
  
  /* Hacky way to return whatever was passed in. Mirrors typical assignment semantics. */
  mrb_value value_as_mrb_value;
  mrb_get_args(mrb, "o", &value_as_mrb_value);
  return value_as_mrb_value;
}
Example #23
0
mrb_value
convert_type(mrb_state *mrb, mrb_value val, const char *tname, const char *method, int raise)
{
  mrb_sym m = 0;

  m = mrb_intern(mrb, method);
  if (!mrb_respond_to(mrb, val, m)) {
    if (raise) {
      mrb_raise(mrb, E_TYPE_ERROR, "can't convert %s into %s",
         mrb_nil_p(val) ? "nil" :
         (mrb_type(val) == MRB_TT_TRUE) ? "true" :
         (mrb_type(val) == MRB_TT_FALSE) ? "false" :
         mrb_obj_classname(mrb, val),
         tname);
      return mrb_nil_value();
    }
    else {
      return mrb_nil_value();
    }
  }
  return mrb_funcall(mrb, val, method, 0);
}
Example #24
0
static mrb_value
mrb_http_parser_execute(mrb_state *mrb, mrb_value self)
{
  mrb_value arg_data;
  mrb_value value_context;
  mrb_http_parser_context* context;

  value_context = mrb_iv_get(mrb, self, mrb_intern(mrb, "context"));
  Data_Get_Struct(mrb, value_context, &http_parser_context_type, context);
  if (!context) {
    mrb_raise(mrb, E_ARGUMENT_ERROR, "invalid argument");
  }

  mrb_get_args(mrb, "o", &arg_data);
  if (mrb_nil_p(arg_data)) {
    mrb_raise(mrb, E_ARGUMENT_ERROR, "invalid argument");
  }

  http_parser_execute(&context->parser, &context->settings, (char*) RSTRING_PTR(arg_data), RSTRING_CAPA(arg_data));

  return mrb_nil_value();
}
Example #25
0
// FLTK::Group#begin
static mrb_value
mrb_fltk_group_begin_method( mrb_state *mrb, mrb_value self ) {
  CONTEXT_SETUP( widget );

  mrb_value block = mrb_nil_value();

  mrb_get_args( mrb, "&", &block );

  if( !mrb_nil_p( block ) ) {
    mrb_value args[1];

    args[0] = self;

    ( (Fl_Group *)context->fl_instance )->begin();
    mrb_yield_argv( mrb, block, 1, args );
    ( (Fl_Group *)context->fl_instance )->end();
  } else {
    ( (Fl_Group *)context->fl_instance )->begin();
  }

  return mrb_nil_value();
}
Example #26
0
/* set_backend
 *
 * Parameters:
 * - value: git_odb_backend *
 */
mrb_value
mrb_Git_OdbStream_set_backend(mrb_state* mrb, mrb_value self) {
    git_odb_stream * native_self = mruby_unbox_git_odb_stream(self);
    mrb_value backend;

    mrb_get_args(mrb, "o", &backend);

    /* type checking */
    if (!mrb_obj_is_kind_of(mrb, backend, OdbBackend_class(mrb))) {
        mrb_raise(mrb, E_TYPE_ERROR, "OdbBackend expected");
        return mrb_nil_value();
    }

    git_odb_backend * native_backend = (mrb_nil_p(backend) ? NULL : mruby_unbox_git_odb_backend(backend));

    native_self->backend = native_backend;

    /* Hacky way to return whatever was passed in. Mirrors typical assignment semantics. */
    mrb_value value_as_mrb_value;
    mrb_get_args(mrb, "o", &value_as_mrb_value);
    return value_as_mrb_value;
}
Example #27
0
static mrb_value
mrb_grn_table_sort_key_set_key(mrb_state *mrb, mrb_value self)
{
  grn_ctx *ctx = (grn_ctx *)mrb->ud;
  grn_table_sort_key *sort_key;
  mrb_value mrb_key;

  sort_key = DATA_PTR(self);
  mrb_get_args(mrb, "o", &mrb_key);

  if (sort_key->key) {
    grn_obj_unlink(ctx, sort_key->key);
  }

  if (mrb_nil_p(mrb_key)) {
    sort_key->key = NULL;
  } else {
    sort_key->key = DATA_PTR(mrb_key);
  }

  return mrb_nil_value();
}
Example #28
0
/*
 * call-seq:
 *   lambda { |...| block }  -> a_proc
 *
 * Equivalent to <code>Proc.new</code>, except the resulting Proc objects
 * check the number of parameters passed when called.
 */
static mrb_value
proc_lambda(mrb_state *mrb, mrb_value self)
{
  mrb_value blk;
  struct RProc *p;

  mrb_get_args(mrb, "&", &blk);
  if (mrb_nil_p(blk)) {
    mrb_raise(mrb, E_ARGUMENT_ERROR, "tried to create Proc object without a block");
  }
  if (mrb_type(blk) != MRB_TT_PROC) {
    mrb_raise(mrb, E_ARGUMENT_ERROR, "not a proc");
  }
  p = mrb_proc_ptr(blk);
  if (!MRB_PROC_STRICT_P(p)) {
    struct RProc *p2 = (struct RProc*)mrb_obj_alloc(mrb, MRB_TT_PROC, p->c);
    mrb_proc_copy(p2, p);
    p2->flags |= MRB_PROC_STRICT;
    return mrb_obj_value(p2);
  }
  return blk;
}
Example #29
0
static mrb_value
mrb_hash_dup(mrb_state *mrb, mrb_value hash)
{
  struct RHash* ret;
  khash_t(ht) *h, *ret_h;
  khiter_t k, ret_k;
  mrb_value ifnone, vret;

  h = RHASH_TBL(hash);
  ret = (struct RHash*)mrb_obj_alloc(mrb, MRB_TT_HASH, mrb->hash_class);
  ret->ht = kh_init(ht, mrb);

  if (h && kh_size(h) > 0) {
    ret_h = ret->ht;

    for (k = kh_begin(h); k != kh_end(h); k++) {
      if (kh_exist(h, k)) {
        int ai = mrb_gc_arena_save(mrb);
        ret_k = kh_put(ht, mrb, ret_h, KEY(kh_key(h, k)));
        mrb_gc_arena_restore(mrb, ai);
        kh_val(ret_h, ret_k).v = kh_val(h, k).v;
        kh_val(ret_h, ret_k).n = kh_size(ret_h)-1;
      }
    }
  }

  if (MRB_RHASH_DEFAULT_P(hash)) {
    ret->flags |= MRB_HASH_DEFAULT;
  }
  if (MRB_RHASH_PROCDEFAULT_P(hash)) {
    ret->flags |= MRB_HASH_PROC_DEFAULT;
  }
  vret = mrb_obj_value(ret);
  ifnone = RHASH_IFNONE(hash);
  if (!mrb_nil_p(ifnone)) {
      mrb_iv_set(mrb, vret, mrb_intern_lit(mrb, "ifnone"), ifnone);
  }
  return vret;
}
/* set_baseline_index
 *
 * Parameters:
 * - value: git_index *
 */
mrb_value
mrb_Git_CheckoutOptions_set_baseline_index(mrb_state* mrb, mrb_value self) {
  git_checkout_options * native_self = mruby_unbox_git_checkout_options(self);
  mrb_value baseline_index;

  mrb_get_args(mrb, "o", &baseline_index);

  /* type checking */
  if (!mrb_obj_is_kind_of(mrb, baseline_index, Index_class(mrb))) {
    mrb_raise(mrb, E_TYPE_ERROR, "Index expected");
    return mrb_nil_value();
  }

  git_index * native_baseline_index = (mrb_nil_p(baseline_index) ? NULL : mruby_unbox_git_index(baseline_index));

  native_self->baseline_index = native_baseline_index;
  
  /* Hacky way to return whatever was passed in. Mirrors typical assignment semantics. */
  mrb_value value_as_mrb_value;
  mrb_get_args(mrb, "o", &value_as_mrb_value);
  return value_as_mrb_value;
}