예제 #1
0
static mrb_value
mrb_sdl2_input_to_value(mrb_state *mrb, void *data)
{
  mrb_sdl2_input_user_data_t *udata =
    (mrb_sdl2_input_user_data_t*)data;
  if (NULL == udata) {
    return mrb_nil_value();
  }
  mrb_value value;
  switch (udata->type) {
  case MRB_TT_FIXNUM:
    value = mrb_fixnum_value(udata->data.fixnum_value);
    break;
  case MRB_TT_FLOAT:
    value = mrb_float_value(mrb, udata->data.float_value);
    break;
  case MRB_TT_STRING:
    value = mrb_str_new_cstr(mrb, udata->data.string_value);
    mrb_free(mrb, udata->data.string_value);
    break;
  case MRB_TT_CPTR:
    value = mrb_cptr_value(mrb, udata->data.cptr_value);
    break;
  default:
    value = mrb_nil_value();
    break;
  }
  mrb_free(mrb, data);
  return value;
}
예제 #2
0
파일: dl.c 프로젝트: mattn/mruby-uv
static mrb_value
mrb_f_uv_dlsym(mrb_state *mrb, mrb_value self)
{
  char *z;
  mrb_get_args(mrb, "z", &z);
  return mrb_cptr_value(mrb, mrb_uv_dlsym(mrb, self, z));
}
예제 #3
0
static mrb_value
mrb_grn_expression_singleton_create(mrb_state *mrb, mrb_value klass)
{
  grn_ctx *ctx = (grn_ctx *)mrb->ud;
  mrb_value mrb_expr;
  mrb_value mrb_table;
  mrb_value mrb_new_arguments[1];
  grn_obj *expr, *variable = NULL;

  mrb_get_args(mrb, "o", &mrb_table);
  if (mrb_nil_p(mrb_table)) {
    expr = grn_expr_create(ctx, NULL, 0);
  } else {
    grn_obj *table = DATA_PTR(mrb_table);
    GRN_EXPR_CREATE_FOR_QUERY(ctx, table, expr, variable);
  }

  if (!expr) {
    grn_mrb_ctx_check(mrb);
    return mrb_nil_value();
  }

  mrb_new_arguments[0] = mrb_cptr_value(mrb, expr);
  mrb_expr = mrb_obj_new(mrb, mrb_class_ptr(klass), 1, mrb_new_arguments);
  {
    mrb_value mrb_variable = mrb_nil_value();
    if (variable) {
      mrb_variable = grn_mrb_value_from_grn_obj(mrb, variable);
    }
    mrb_iv_set(mrb, mrb_expr, mrb_intern_lit(mrb, "@variable"), mrb_variable);
  }

  return mrb_expr;
}
예제 #4
0
파일: misc.c 프로젝트: asfluido/mruby-sdl2
static mrb_value
mrb_sdl2_misc_buffer_get_cptr(mrb_state *mrb, mrb_value self)
{
  mrb_sdl2_misc_buffer_data_t *data =
    (mrb_sdl2_misc_buffer_data_t*)mrb_data_get_ptr(mrb, self, &mrb_sdl2_misc_buffer_data_type);
  return mrb_cptr_value(mrb, data->buffer);
}
예제 #5
0
/*
 *  call-seq:
 *     raise
 *     raise(string)
 *     raise(exception [, string])
 *
 *  With no arguments, raises a <code>RuntimeError</code>
 *  With a single +String+ argument, raises a
 *  +RuntimeError+ with the string as a message. Otherwise,
 *  the first parameter should be the name of an +Exception+
 *  class (or an object that returns an +Exception+ object when sent
 *  an +exception+ message). The optional second parameter sets the
 *  message associated with the exception, and the third parameter is an
 *  array of callback information. Exceptions are caught by the
 *  +rescue+ clause of <code>begin...end</code> blocks.
 *
 *     raise "Failed to create socket"
 *     raise ArgumentError, "No parameters", caller
 */
mrb_value
mrb_f_raise(mrb_state *mrb, mrb_value self)
{
  mrb_value a[2], exc;
  int argc;


  argc = mrb_get_args(mrb, "|oo", &a[0], &a[1]);
  switch (argc) {
  case 0:
    mrb_raise(mrb, E_RUNTIME_ERROR, "");
    break;
  case 1:
    a[1] = mrb_check_string_type(mrb, a[0]);
    if (!mrb_nil_p(a[1])) {
      argc = 2;
      a[0] = mrb_obj_value(E_RUNTIME_ERROR);
    }
    /* fall through */
  default:
    exc = mrb_make_exception(mrb, argc, a);
    mrb_obj_iv_set(mrb, mrb_obj_ptr(exc), mrb_intern2(mrb, "lastpc", 6), mrb_cptr_value(mrb, mrb->c->ci->pc));
    mrb_exc_raise(mrb, exc);
    break;
  }
  return mrb_nil_value();            /* not reached */
}
예제 #6
0
static mrb_value
mrb_grn_index_cursor_class_open_raw(mrb_state *mrb, mrb_value klass)
{
  grn_ctx *ctx = (grn_ctx *)mrb->ud;
  mrb_value mrb_table_cursor;
  mrb_value mrb_index;
  mrb_value mrb_options = mrb_nil_value();
  grn_obj *index_cursor;
  grn_table_cursor *table_cursor;
  grn_obj *index;
  grn_id rid_min = GRN_ID_NIL;
  grn_id rid_max = GRN_ID_MAX;
  int flags = 0;
  mrb_value mrb_index_cursor;

  mrb_get_args(mrb, "oo|H", &mrb_table_cursor, &mrb_index, &mrb_options);

  table_cursor = DATA_PTR(mrb_table_cursor);
  index = DATA_PTR(mrb_index);
  if (!mrb_nil_p(mrb_options)) {
    /* TODO */
  }
  index_cursor = grn_index_cursor_open(ctx, table_cursor, index,
                                       rid_min, rid_max, flags);
  grn_mrb_ctx_check(mrb);

  mrb_index_cursor = mrb_funcall(mrb, klass, "new", 1,
                                 mrb_cptr_value(mrb, index_cursor));
  mrb_iv_set(mrb, mrb_index_cursor, mrb_intern_lit(mrb, "@index"), mrb_index);
  return mrb_index_cursor;
}
예제 #7
0
static ssize_t
mrb_wslay_event_recv_callback(wslay_event_context_ptr ctx,
  uint8_t *buf, size_t len, int flags, void *user_data)
{
  mrb_wslay_user_data *data = (mrb_wslay_user_data *) user_data;
  mrb_state*mrb = data->mrb;
  int ai = mrb_gc_arena_save(mrb);

  struct mrb_jmpbuf *prev_jmp = mrb->jmp;
  struct mrb_jmpbuf c_jmp;

  mrb_int ret = -1;
  MRB_TRY(&c_jmp) {
    mrb->jmp = &c_jmp;

    mrb_value argv[2];
    argv[0] = mrb_cptr_value(mrb, buf);
    argv[1] = mrb_fixnum_value(len);

    errno = 0;
    mrb_assert(mrb_type(data->recv_callback) == MRB_TT_PROC);
    mrb_value buf_obj = mrb_yield_argv(mrb, data->recv_callback, NELEMS(argv), argv);

    if (mrb_fixnum_p(buf_obj)) {
      ret = mrb_fixnum(buf_obj);
    } else {
      buf_obj = mrb_str_to_str(mrb, buf_obj);
      ret = RSTRING_LEN(buf_obj);
      if (ret < 0||ret > len) {
        mrb_raise(mrb, E_RANGE_ERROR, "returned buf doesn't fit");
      }
      if (ret > 0) {
        memmove(buf, (uint8_t *) RSTRING_PTR(buf_obj), ret);
      }
    }

    mrb->jmp = prev_jmp;
  } MRB_CATCH(&c_jmp) {
    mrb->jmp = prev_jmp;
    if (mrb_obj_is_kind_of(mrb,
        mrb_obj_value(mrb->exc),
            mrb_class_get_under(mrb,
                mrb_module_get(mrb, "Errno"), "EAGAIN"))||
    mrb_obj_is_kind_of(mrb,
        mrb_obj_value(mrb->exc),
            mrb_class_get_under(mrb,
                mrb_module_get(mrb, "Errno"), "EWOULDBLOCK"))) {
      mrb->exc = NULL;
      wslay_event_set_error(ctx, WSLAY_ERR_WOULDBLOCK);
    } else {
      wslay_event_set_error(ctx, WSLAY_ERR_CALLBACK_FAILURE);
    }
  } MRB_END_EXC(&c_jmp);

  mrb_gc_arena_restore(mrb, ai);

  return ret;
}
예제 #8
0
static mrb_value
mrb_grn_expr_code_new(mrb_state *mrb, grn_expr_code *code)
{
  grn_ctx *ctx = (grn_ctx *)mrb->ud;
  struct RClass *module = ctx->impl->mrb.module;
  struct RClass *klass;
  mrb_value mrb_code;

  mrb_code = mrb_cptr_value(mrb, code);
  klass = mrb_class_get_under(mrb, module, "ExpressionCode");
  return mrb_obj_new(mrb, klass, 1, &mrb_code);
}
예제 #9
0
static mrb_value
mrb_grn_scan_info_new(mrb_state *mrb, scan_info *scan_info)
{
  grn_ctx *ctx = (grn_ctx *)mrb->ud;
  struct RClass *module = ctx->impl->mrb.module;
  struct RClass *klass;
  mrb_value mrb_scan_info;

  mrb_scan_info = mrb_cptr_value(mrb, scan_info);
  klass = mrb_class_get_under(mrb, module, "ScanInfo");
  return mrb_obj_new(mrb, klass, 1, &mrb_scan_info);
}
예제 #10
0
static mrb_value
mrb_grn_cache_class_current(mrb_state *mrb, mrb_value klass)
{
  grn_ctx *ctx = (grn_ctx *)mrb->ud;
  grn_cache *cache;
  mrb_value mrb_cache;

  cache = grn_cache_current_get(ctx);
  mrb_cache = mrb_funcall(mrb, klass, "new", 1, mrb_cptr_value(mrb, cache));

  return mrb_cache;
}
예제 #11
0
mrb_value
grn_mrb_value_from_grn_obj(mrb_state *mrb, grn_obj *object)
{
  struct RClass *mrb_class;
  mrb_value mrb_new_arguments[1];
  mrb_value mrb_object;

  if (!object) {
    return mrb_nil_value();
  }

  mrb_class = grn_mrb_class_from_grn_obj(mrb, object);
  mrb_new_arguments[0] = mrb_cptr_value(mrb, object);
  mrb_object = mrb_obj_new(mrb, mrb_class, 1, mrb_new_arguments);
  return mrb_object;
}
예제 #12
0
static mrb_value surface_lock(mrb_state *mrb, mrb_value self)
{
    IDirectFBSurface* surface = mrb_directfb_surface(mrb, self);
    if (surface != NULL) {
        void* p = NULL;
        int pitch;
        DFBResult ret;
        mrb_int flags = 0;
        mrb_get_args(mrb, "i", &flags);
        pitch = 0;
        ret = surface->Lock(surface, flags, &p, &pitch);
        if (!ret) {
            mrb_value a[2];
            a[0] = mrb_cptr_value(mrb, p);
            a[1] = mrb_fixnum_value(pitch);
            return mrb_ary_new_from_values(mrb, 2, a);
        }
    }
    return mrb_nil_value();
}
예제 #13
0
파일: lib.c 프로젝트: tanxunrong/shield
mrb_value wrap_mrb_cptr_value(mrb_state *m,void *p)
{
    return mrb_cptr_value(m,p);
}
예제 #14
0
파일: nhash.c 프로젝트: christiank/libn
void
nhash_set(nhash *hash, const char *key, const void *ptr)
{
  mrb_hash_set(__LIBN_R, hash->_hash, mrb_str_new_cstr(__LIBN_R, key),
    mrb_cptr_value(__LIBN_R, (void*)ptr));
}
예제 #15
0
파일: future.c 프로젝트: ysei/mruby-future
static mrb_value
mrb_future_init(mrb_state *oldmrb, mrb_value self)
{
  static const struct mrb_context mrb_context_zero = { 0 };
  mrb_state *mrb = mrb_open();
  mrb_future_context *context = (mrb_future_context *) malloc(sizeof(mrb_future_context));
  struct mrb_context *c;
  struct RProc *p;
  mrb_callinfo *ci;
  mrb_value blk;
  size_t slen;
  int argc;
  mrb_value* argv;

  *mrb = *oldmrb;
  mrb_get_args(mrb, "*&", &argv, &argc, &blk);

  p = mrb_proc_ptr(blk);

  c = (struct mrb_context*)mrb_malloc(mrb, sizeof(struct mrb_context));
  *c = mrb_context_zero;
  mrb->c = c;
  context->mrb = mrb;
  context->oldmrb = oldmrb;
  context->proc = mrb_proc_ptr(blk);
  context->argc = argc;
  context->argv = argv;
  context->self = self;

  /* initialize VM stack */
  slen = FIBER_STACK_INIT_SIZE;
  if (!MRB_PROC_CFUNC_P(p) && p->body.irep->nregs > slen) {
    slen += p->body.irep->nregs;
  }
  c->stbase = (mrb_value *)mrb_malloc(mrb, slen*sizeof(mrb_value));
  c->stend = c->stbase + slen;
  c->stack = c->stbase;

#ifdef MRB_NAN_BOXING
  {
    mrb_value *p = c->stbase;
    mrb_value *pend = c->stend;
    
    while (p < pend) {
      SET_NIL_VALUE(*p);
      p++;
    }
  }
#else
  memset(c->stbase, 0, slen * sizeof(mrb_value));
#endif

  /* copy future object(self) from a block */
  c->stack[0] = self;

  /* initialize callinfo stack */
  c->cibase = (mrb_callinfo *)mrb_calloc(mrb, FIBER_CI_INIT_SIZE, sizeof(mrb_callinfo));
  c->ciend = c->cibase + FIBER_CI_INIT_SIZE;
  c->ci = c->cibase;
  c->ci->stackent = c->stack;

  /* adjust return callinfo */
  ci = c->ci;
  ci->target_class = p->target_class;
  ci->proc = p;
  if (!MRB_PROC_CFUNC_P(p)) {
    ci->pc = p->body.irep->iseq;
    ci->nregs = p->body.irep->nregs;
  }
  ci[1] = ci[0];
  c->ci++;                      /* push dummy callinfo */

  mrb_iv_set(oldmrb, self, mrb_intern_cstr(oldmrb, "_context"), mrb_cptr_value(oldmrb, context));
  mrb_iv_set(oldmrb, self, mrb_intern_cstr(oldmrb, "_state"), mrb_fixnum_value(FUTURE_RUNNING));

  pthread_create(&context->thread, NULL, &mrb_future_func, (void *)context);

  return self;
}
예제 #16
0
static mrb_value
mrb_grn_table_cursor_class_open_raw(mrb_state *mrb, mrb_value klass)
{
  grn_ctx *ctx = (grn_ctx *)mrb->ud;
  mrb_value mrb_table;
  mrb_value mrb_options = mrb_nil_value();
  grn_table_cursor *table_cursor;
  grn_obj *table;
  void *min = NULL;
  unsigned int min_size = 0;
  grn_mrb_value_to_raw_data_buffer min_buffer;
  void *max = NULL;
  unsigned int max_size = 0;
  grn_mrb_value_to_raw_data_buffer max_buffer;
  int offset = 0;
  int limit = -1;
  int flags = 0;

  mrb_get_args(mrb, "o|H", &mrb_table, &mrb_options);

  table = DATA_PTR(mrb_table);
  grn_mrb_value_to_raw_data_buffer_init(mrb, &min_buffer);
  grn_mrb_value_to_raw_data_buffer_init(mrb, &max_buffer);
  if (!mrb_nil_p(mrb_options)) {
    grn_id key_domain_id;
    mrb_value mrb_min;
    mrb_value mrb_max;
    mrb_value mrb_flags;

    if (table->header.type == GRN_DB) {
      key_domain_id = GRN_DB_SHORT_TEXT;
    } else {
      key_domain_id = table->header.domain;
    }

    mrb_min = grn_mrb_options_get_lit(mrb, mrb_options, "min");
    grn_mrb_value_to_raw_data(mrb, "min", mrb_min,
                              key_domain_id, &min_buffer, &min, &min_size);

    mrb_max = grn_mrb_options_get_lit(mrb, mrb_options, "max");
    grn_mrb_value_to_raw_data(mrb, "max", mrb_max,
                              key_domain_id, &max_buffer, &max, &max_size);

    mrb_flags = grn_mrb_options_get_lit(mrb, mrb_options, "flags");
    if (!mrb_nil_p(mrb_flags)) {
      flags = mrb_fixnum(mrb_flags);
    }
  }
  table_cursor = grn_table_cursor_open(ctx, table,
                                       min, min_size,
                                       max, max_size,
                                       offset, limit, flags);
  grn_mrb_value_to_raw_data_buffer_fin(mrb, &min_buffer);
  grn_mrb_value_to_raw_data_buffer_fin(mrb, &max_buffer);
  grn_mrb_ctx_check(mrb);

  {
    mrb_value mrb_table_cursor;
    mrb_table_cursor = mrb_funcall(mrb, klass,
                                   "new", 1, mrb_cptr_value(mrb, table_cursor));
    mrb_iv_set(mrb, mrb_table_cursor, mrb_intern_lit(mrb, "@table"), mrb_table);
    return mrb_table_cursor;
  }
}
예제 #17
0
struct RClass* mrb_egl_define_constants(mrb_state* mrb, struct RClass* outer)
{
	struct RClass* constants = mrb_define_module_under(mrb, outer, "Constants");

#ifdef EGL_VERSION_1_0
		mrb_define_const(mrb, constants, "EGL_VERSION_1_0", mrb_fixnum_value(EGL_VERSION_1_0));
#endif
#ifdef EGL_VERSION_1_1
		mrb_define_const(mrb, constants, "EGL_VERSION_1_1", mrb_fixnum_value(EGL_VERSION_1_1));
#endif
#ifdef EGL_VERSION_1_2
		mrb_define_const(mrb, constants, "EGL_VERSION_1_2", mrb_fixnum_value(EGL_VERSION_1_2));
#endif
#ifdef EGL_VERSION_1_3
		mrb_define_const(mrb, constants, "EGL_VERSION_1_3", mrb_fixnum_value(EGL_VERSION_1_3));
#endif
#ifdef EGL_VERSION_1_4
		mrb_define_const(mrb, constants, "EGL_VERSION_1_4", mrb_fixnum_value(EGL_VERSION_1_4));
#endif
#ifdef EGL_FALSE
		mrb_define_const(mrb, constants, "EGL_FALSE", mrb_fixnum_value(EGL_FALSE));
#endif
#ifdef EGL_TRUE
		mrb_define_const(mrb, constants, "EGL_TRUE", mrb_fixnum_value(EGL_TRUE));
#endif
#ifdef EGL_DEFAULT_DISPLAY
		mrb_define_const(mrb, constants, "EGL_DEFAULT_DISPLAY", mrb_cptr_value(mrb, EGL_DEFAULT_DISPLAY));
#endif
#ifdef EGL_NO_CONTEXT
		mrb_define_const(mrb, constants, "EGL_NO_CONTEXT", mrb_cptr_value(mrb, EGL_NO_CONTEXT));
#endif
#ifdef EGL_NO_DISPLAY
		mrb_define_const(mrb, constants, "EGL_NO_DISPLAY", mrb_cptr_value(mrb, EGL_NO_DISPLAY));
#endif
#ifdef EGL_NO_SURFACE
		mrb_define_const(mrb, constants, "EGL_NO_SURFACE", mrb_cptr_value(mrb, EGL_NO_SURFACE));
#endif
#ifdef EGL_DONT_CARE
		mrb_define_const(mrb, constants, "EGL_DONT_CARE", mrb_fixnum_value(EGL_DONT_CARE));
#endif
#ifdef EGL_SUCCESS
		mrb_define_const(mrb, constants, "EGL_SUCCESS", mrb_fixnum_value(EGL_SUCCESS));
#endif
#ifdef EGL_NOT_INITIALIZED
		mrb_define_const(mrb, constants, "EGL_NOT_INITIALIZED", mrb_fixnum_value(EGL_NOT_INITIALIZED));
#endif
#ifdef EGL_BAD_ACCESS
		mrb_define_const(mrb, constants, "EGL_BAD_ACCESS", mrb_fixnum_value(EGL_BAD_ACCESS));
#endif
#ifdef EGL_BAD_ALLOC
		mrb_define_const(mrb, constants, "EGL_BAD_ALLOC", mrb_fixnum_value(EGL_BAD_ALLOC));
#endif
#ifdef EGL_BAD_ATTRIBUTE
		mrb_define_const(mrb, constants, "EGL_BAD_ATTRIBUTE", mrb_fixnum_value(EGL_BAD_ATTRIBUTE));
#endif
#ifdef EGL_BAD_CONFIG
		mrb_define_const(mrb, constants, "EGL_BAD_CONFIG", mrb_fixnum_value(EGL_BAD_CONFIG));
#endif
#ifdef EGL_BAD_CONTEXT
		mrb_define_const(mrb, constants, "EGL_BAD_CONTEXT", mrb_fixnum_value(EGL_BAD_CONTEXT));
#endif
#ifdef EGL_BAD_CURRENT_SURFACE
		mrb_define_const(mrb, constants, "EGL_BAD_CURRENT_SURFACE", mrb_fixnum_value(EGL_BAD_CURRENT_SURFACE));
#endif
#ifdef EGL_BAD_DISPLAY
		mrb_define_const(mrb, constants, "EGL_BAD_DISPLAY", mrb_fixnum_value(EGL_BAD_DISPLAY));
#endif
#ifdef EGL_BAD_MATCH
		mrb_define_const(mrb, constants, "EGL_BAD_MATCH", mrb_fixnum_value(EGL_BAD_MATCH));
#endif
#ifdef EGL_BAD_NATIVE_PIXMAP
		mrb_define_const(mrb, constants, "EGL_BAD_NATIVE_PIXMAP", mrb_fixnum_value(EGL_BAD_NATIVE_PIXMAP));
#endif
#ifdef EGL_BAD_NATIVE_WINDOW
		mrb_define_const(mrb, constants, "EGL_BAD_NATIVE_WINDOW", mrb_fixnum_value(EGL_BAD_NATIVE_WINDOW));
#endif
#ifdef EGL_BAD_PARAMETER
		mrb_define_const(mrb, constants, "EGL_BAD_PARAMETER", mrb_fixnum_value(EGL_BAD_PARAMETER));
#endif
#ifdef EGL_BAD_SURFACE
		mrb_define_const(mrb, constants, "EGL_BAD_SURFACE", mrb_fixnum_value(EGL_BAD_SURFACE));
#endif
#ifdef EGL_CONTEXT_LOST
		mrb_define_const(mrb, constants, "EGL_CONTEXT_LOST", mrb_fixnum_value(EGL_CONTEXT_LOST));
#endif
#ifdef EGL_BUFFER_SIZE
		mrb_define_const(mrb, constants, "EGL_BUFFER_SIZE", mrb_fixnum_value(EGL_BUFFER_SIZE));
#endif
#ifdef EGL_ALPHA_SIZE
		mrb_define_const(mrb, constants, "EGL_ALPHA_SIZE", mrb_fixnum_value(EGL_ALPHA_SIZE));
#endif
#ifdef EGL_BLUE_SIZE
		mrb_define_const(mrb, constants, "EGL_BLUE_SIZE", mrb_fixnum_value(EGL_BLUE_SIZE));
#endif
#ifdef EGL_GREEN_SIZE
		mrb_define_const(mrb, constants, "EGL_GREEN_SIZE", mrb_fixnum_value(EGL_GREEN_SIZE));
#endif
#ifdef EGL_RED_SIZE
		mrb_define_const(mrb, constants, "EGL_RED_SIZE", mrb_fixnum_value(EGL_RED_SIZE));
#endif
#ifdef EGL_DEPTH_SIZE
		mrb_define_const(mrb, constants, "EGL_DEPTH_SIZE", mrb_fixnum_value(EGL_DEPTH_SIZE));
#endif
#ifdef EGL_STENCIL_SIZE
		mrb_define_const(mrb, constants, "EGL_STENCIL_SIZE", mrb_fixnum_value(EGL_STENCIL_SIZE));
#endif
#ifdef EGL_CONFIG_CAVEAT
		mrb_define_const(mrb, constants, "EGL_CONFIG_CAVEAT", mrb_fixnum_value(EGL_CONFIG_CAVEAT));
#endif
#ifdef EGL_CONFIG_ID
		mrb_define_const(mrb, constants, "EGL_CONFIG_ID", mrb_fixnum_value(EGL_CONFIG_ID));
#endif
#ifdef EGL_LEVEL
		mrb_define_const(mrb, constants, "EGL_LEVEL", mrb_fixnum_value(EGL_LEVEL));
#endif
#ifdef EGL_MAX_PBUFFER_HEIGHT
		mrb_define_const(mrb, constants, "EGL_MAX_PBUFFER_HEIGHT", mrb_fixnum_value(EGL_MAX_PBUFFER_HEIGHT));
#endif
#ifdef EGL_MAX_PBUFFER_PIXELS
		mrb_define_const(mrb, constants, "EGL_MAX_PBUFFER_PIXELS", mrb_fixnum_value(EGL_MAX_PBUFFER_PIXELS));
#endif
#ifdef EGL_MAX_PBUFFER_WIDTH
		mrb_define_const(mrb, constants, "EGL_MAX_PBUFFER_WIDTH", mrb_fixnum_value(EGL_MAX_PBUFFER_WIDTH));
#endif
#ifdef EGL_NATIVE_RENDERABLE
		mrb_define_const(mrb, constants, "EGL_NATIVE_RENDERABLE", mrb_fixnum_value(EGL_NATIVE_RENDERABLE));
#endif
#ifdef EGL_NATIVE_VISUAL_ID
		mrb_define_const(mrb, constants, "EGL_NATIVE_VISUAL_ID", mrb_fixnum_value(EGL_NATIVE_VISUAL_ID));
#endif
#ifdef EGL_NATIVE_VISUAL_TYPE
		mrb_define_const(mrb, constants, "EGL_NATIVE_VISUAL_TYPE", mrb_fixnum_value(EGL_NATIVE_VISUAL_TYPE));
#endif
#ifdef EGL_SAMPLES
		mrb_define_const(mrb, constants, "EGL_SAMPLES", mrb_fixnum_value(EGL_SAMPLES));
#endif
#ifdef EGL_SAMPLE_BUFFERS
		mrb_define_const(mrb, constants, "EGL_SAMPLE_BUFFERS", mrb_fixnum_value(EGL_SAMPLE_BUFFERS));
#endif
#ifdef EGL_SURFACE_TYPE
		mrb_define_const(mrb, constants, "EGL_SURFACE_TYPE", mrb_fixnum_value(EGL_SURFACE_TYPE));
#endif
#ifdef EGL_TRANSPARENT_TYPE
		mrb_define_const(mrb, constants, "EGL_TRANSPARENT_TYPE", mrb_fixnum_value(EGL_TRANSPARENT_TYPE));
#endif
#ifdef EGL_TRANSPARENT_BLUE_VALUE
		mrb_define_const(mrb, constants, "EGL_TRANSPARENT_BLUE_VALUE", mrb_fixnum_value(EGL_TRANSPARENT_BLUE_VALUE));
#endif
#ifdef EGL_TRANSPARENT_GREEN_VALUE
		mrb_define_const(mrb, constants, "EGL_TRANSPARENT_GREEN_VALUE", mrb_fixnum_value(EGL_TRANSPARENT_GREEN_VALUE));
#endif
#ifdef EGL_TRANSPARENT_RED_VALUE
		mrb_define_const(mrb, constants, "EGL_TRANSPARENT_RED_VALUE", mrb_fixnum_value(EGL_TRANSPARENT_RED_VALUE));
#endif
#ifdef EGL_NONE
		mrb_define_const(mrb, constants, "EGL_NONE", mrb_fixnum_value(EGL_NONE));
#endif
#ifdef EGL_BIND_TO_TEXTURE_RGB
		mrb_define_const(mrb, constants, "EGL_BIND_TO_TEXTURE_RGB", mrb_fixnum_value(EGL_BIND_TO_TEXTURE_RGB));
#endif
#ifdef EGL_BIND_TO_TEXTURE_RGBA
		mrb_define_const(mrb, constants, "EGL_BIND_TO_TEXTURE_RGBA", mrb_fixnum_value(EGL_BIND_TO_TEXTURE_RGBA));
#endif
#ifdef EGL_MIN_SWAP_INTERVAL
		mrb_define_const(mrb, constants, "EGL_MIN_SWAP_INTERVAL", mrb_fixnum_value(EGL_MIN_SWAP_INTERVAL));
#endif
#ifdef EGL_MAX_SWAP_INTERVAL
		mrb_define_const(mrb, constants, "EGL_MAX_SWAP_INTERVAL", mrb_fixnum_value(EGL_MAX_SWAP_INTERVAL));
#endif
#ifdef EGL_LUMINANCE_SIZE
		mrb_define_const(mrb, constants, "EGL_LUMINANCE_SIZE", mrb_fixnum_value(EGL_LUMINANCE_SIZE));
#endif
#ifdef EGL_ALPHA_MASK_SIZE
		mrb_define_const(mrb, constants, "EGL_ALPHA_MASK_SIZE", mrb_fixnum_value(EGL_ALPHA_MASK_SIZE));
#endif
#ifdef EGL_COLOR_BUFFER_TYPE
		mrb_define_const(mrb, constants, "EGL_COLOR_BUFFER_TYPE", mrb_fixnum_value(EGL_COLOR_BUFFER_TYPE));
#endif
#ifdef EGL_RENDERABLE_TYPE
		mrb_define_const(mrb, constants, "EGL_RENDERABLE_TYPE", mrb_fixnum_value(EGL_RENDERABLE_TYPE));
#endif
#ifdef EGL_MATCH_NATIVE_PIXMAP
		mrb_define_const(mrb, constants, "EGL_MATCH_NATIVE_PIXMAP", mrb_fixnum_value(EGL_MATCH_NATIVE_PIXMAP));
#endif
#ifdef EGL_CONFORMANT
		mrb_define_const(mrb, constants, "EGL_CONFORMANT", mrb_fixnum_value(EGL_CONFORMANT));
#endif
#ifdef EGL_SLOW_CONFIG
		mrb_define_const(mrb, constants, "EGL_SLOW_CONFIG", mrb_fixnum_value(EGL_SLOW_CONFIG));
#endif
#ifdef EGL_NON_CONFORMANT_CONFIG
		mrb_define_const(mrb, constants, "EGL_NON_CONFORMANT_CONFIG", mrb_fixnum_value(EGL_NON_CONFORMANT_CONFIG));
#endif
#ifdef EGL_TRANSPARENT_RGB
		mrb_define_const(mrb, constants, "EGL_TRANSPARENT_RGB", mrb_fixnum_value(EGL_TRANSPARENT_RGB));
#endif
#ifdef EGL_RGB_BUFFER
		mrb_define_const(mrb, constants, "EGL_RGB_BUFFER", mrb_fixnum_value(EGL_RGB_BUFFER));
#endif
#ifdef EGL_LUMINANCE_BUFFER
		mrb_define_const(mrb, constants, "EGL_LUMINANCE_BUFFER", mrb_fixnum_value(EGL_LUMINANCE_BUFFER));
#endif
#ifdef EGL_NO_TEXTURE
		mrb_define_const(mrb, constants, "EGL_NO_TEXTURE", mrb_fixnum_value(EGL_NO_TEXTURE));
#endif
#ifdef EGL_TEXTURE_RGB
		mrb_define_const(mrb, constants, "EGL_TEXTURE_RGB", mrb_fixnum_value(EGL_TEXTURE_RGB));
#endif
#ifdef EGL_TEXTURE_RGBA
		mrb_define_const(mrb, constants, "EGL_TEXTURE_RGBA", mrb_fixnum_value(EGL_TEXTURE_RGBA));
#endif
#ifdef EGL_TEXTURE_2D
		mrb_define_const(mrb, constants, "EGL_TEXTURE_2D", mrb_fixnum_value(EGL_TEXTURE_2D));
#endif
#ifdef EGL_PBUFFER_BIT
		mrb_define_const(mrb, constants, "EGL_PBUFFER_BIT", mrb_fixnum_value(EGL_PBUFFER_BIT));
#endif
#ifdef EGL_PIXMAP_BIT
		mrb_define_const(mrb, constants, "EGL_PIXMAP_BIT", mrb_fixnum_value(EGL_PIXMAP_BIT));
#endif
#ifdef EGL_WINDOW_BIT
		mrb_define_const(mrb, constants, "EGL_WINDOW_BIT", mrb_fixnum_value(EGL_WINDOW_BIT));
#endif
#ifdef EGL_VG_COLORSPACE_LINEAR_BIT
		mrb_define_const(mrb, constants, "EGL_VG_COLORSPACE_LINEAR_BIT", mrb_fixnum_value(EGL_VG_COLORSPACE_LINEAR_BIT));
#endif
#ifdef EGL_VG_ALPHA_FORMAT_PRE_BIT
		mrb_define_const(mrb, constants, "EGL_VG_ALPHA_FORMAT_PRE_BIT", mrb_fixnum_value(EGL_VG_ALPHA_FORMAT_PRE_BIT));
#endif
#ifdef EGL_MULTISAMPLE_RESOLVE_BOX_BIT
		mrb_define_const(mrb, constants, "EGL_MULTISAMPLE_RESOLVE_BOX_BIT", mrb_fixnum_value(EGL_MULTISAMPLE_RESOLVE_BOX_BIT));
#endif
#ifdef EGL_SWAP_BEHAVIOR_PRESERVED_BIT
		mrb_define_const(mrb, constants, "EGL_SWAP_BEHAVIOR_PRESERVED_BIT", mrb_fixnum_value(EGL_SWAP_BEHAVIOR_PRESERVED_BIT));
#endif
#ifdef EGL_OPENGL_ES_BIT
		mrb_define_const(mrb, constants, "EGL_OPENGL_ES_BIT", mrb_fixnum_value(EGL_OPENGL_ES_BIT));
#endif
#ifdef EGL_OPENVG_BIT
		mrb_define_const(mrb, constants, "EGL_OPENVG_BIT", mrb_fixnum_value(EGL_OPENVG_BIT));
#endif
#ifdef EGL_OPENGL_ES2_BIT
		mrb_define_const(mrb, constants, "EGL_OPENGL_ES2_BIT", mrb_fixnum_value(EGL_OPENGL_ES2_BIT));
#endif
#ifdef EGL_OPENGL_BIT
		mrb_define_const(mrb, constants, "EGL_OPENGL_BIT", mrb_fixnum_value(EGL_OPENGL_BIT));
#endif
#ifdef EGL_VENDOR
		mrb_define_const(mrb, constants, "EGL_VENDOR", mrb_fixnum_value(EGL_VENDOR));
#endif
#ifdef EGL_VERSION
		mrb_define_const(mrb, constants, "EGL_VERSION", mrb_fixnum_value(EGL_VERSION));
#endif
#ifdef EGL_EXTENSIONS
		mrb_define_const(mrb, constants, "EGL_EXTENSIONS", mrb_fixnum_value(EGL_EXTENSIONS));
#endif
#ifdef EGL_CLIENT_APIS
		mrb_define_const(mrb, constants, "EGL_CLIENT_APIS", mrb_fixnum_value(EGL_CLIENT_APIS));
#endif
#ifdef EGL_HEIGHT
		mrb_define_const(mrb, constants, "EGL_HEIGHT", mrb_fixnum_value(EGL_HEIGHT));
#endif
#ifdef EGL_WIDTH
		mrb_define_const(mrb, constants, "EGL_WIDTH", mrb_fixnum_value(EGL_WIDTH));
#endif
#ifdef EGL_LARGEST_PBUFFER
		mrb_define_const(mrb, constants, "EGL_LARGEST_PBUFFER", mrb_fixnum_value(EGL_LARGEST_PBUFFER));
#endif
#ifdef EGL_TEXTURE_FORMAT
		mrb_define_const(mrb, constants, "EGL_TEXTURE_FORMAT", mrb_fixnum_value(EGL_TEXTURE_FORMAT));
#endif
#ifdef EGL_TEXTURE_TARGET
		mrb_define_const(mrb, constants, "EGL_TEXTURE_TARGET", mrb_fixnum_value(EGL_TEXTURE_TARGET));
#endif
#ifdef EGL_MIPMAP_TEXTURE
		mrb_define_const(mrb, constants, "EGL_MIPMAP_TEXTURE", mrb_fixnum_value(EGL_MIPMAP_TEXTURE));
#endif
#ifdef EGL_MIPMAP_LEVEL
		mrb_define_const(mrb, constants, "EGL_MIPMAP_LEVEL", mrb_fixnum_value(EGL_MIPMAP_LEVEL));
#endif
#ifdef EGL_RENDER_BUFFER
		mrb_define_const(mrb, constants, "EGL_RENDER_BUFFER", mrb_fixnum_value(EGL_RENDER_BUFFER));
#endif
#ifdef EGL_VG_COLORSPACE
		mrb_define_const(mrb, constants, "EGL_VG_COLORSPACE", mrb_fixnum_value(EGL_VG_COLORSPACE));
#endif
#ifdef EGL_VG_ALPHA_FORMAT
		mrb_define_const(mrb, constants, "EGL_VG_ALPHA_FORMAT", mrb_fixnum_value(EGL_VG_ALPHA_FORMAT));
#endif
#ifdef EGL_HORIZONTAL_RESOLUTION
		mrb_define_const(mrb, constants, "EGL_HORIZONTAL_RESOLUTION", mrb_fixnum_value(EGL_HORIZONTAL_RESOLUTION));
#endif
#ifdef EGL_VERTICAL_RESOLUTION
		mrb_define_const(mrb, constants, "EGL_VERTICAL_RESOLUTION", mrb_fixnum_value(EGL_VERTICAL_RESOLUTION));
#endif
#ifdef EGL_PIXEL_ASPECT_RATIO
		mrb_define_const(mrb, constants, "EGL_PIXEL_ASPECT_RATIO", mrb_fixnum_value(EGL_PIXEL_ASPECT_RATIO));
#endif
#ifdef EGL_SWAP_BEHAVIOR
		mrb_define_const(mrb, constants, "EGL_SWAP_BEHAVIOR", mrb_fixnum_value(EGL_SWAP_BEHAVIOR));
#endif
#ifdef EGL_MULTISAMPLE_RESOLVE
		mrb_define_const(mrb, constants, "EGL_MULTISAMPLE_RESOLVE", mrb_fixnum_value(EGL_MULTISAMPLE_RESOLVE));
#endif
#ifdef EGL_BACK_BUFFER
		mrb_define_const(mrb, constants, "EGL_BACK_BUFFER", mrb_fixnum_value(EGL_BACK_BUFFER));
#endif
#ifdef EGL_SINGLE_BUFFER
		mrb_define_const(mrb, constants, "EGL_SINGLE_BUFFER", mrb_fixnum_value(EGL_SINGLE_BUFFER));
#endif
#ifdef EGL_VG_COLORSPACE_sRGB
		mrb_define_const(mrb, constants, "EGL_VG_COLORSPACE_sRGB", mrb_fixnum_value(EGL_VG_COLORSPACE_sRGB));
#endif
#ifdef EGL_VG_COLORSPACE_LINEAR
		mrb_define_const(mrb, constants, "EGL_VG_COLORSPACE_LINEAR", mrb_fixnum_value(EGL_VG_COLORSPACE_LINEAR));
#endif
#ifdef EGL_VG_ALPHA_FORMAT_NONPRE
		mrb_define_const(mrb, constants, "EGL_VG_ALPHA_FORMAT_NONPRE", mrb_fixnum_value(EGL_VG_ALPHA_FORMAT_NONPRE));
#endif
#ifdef EGL_VG_ALPHA_FORMAT_PRE
		mrb_define_const(mrb, constants, "EGL_VG_ALPHA_FORMAT_PRE", mrb_fixnum_value(EGL_VG_ALPHA_FORMAT_PRE));
#endif
#ifdef EGL_DISPLAY_SCALING
		mrb_define_const(mrb, constants, "EGL_DISPLAY_SCALING", mrb_fixnum_value(EGL_DISPLAY_SCALING));
#endif
#ifdef EGL_UNKNOWN
		mrb_define_const(mrb, constants, "EGL_UNKNOWN", mrb_fixnum_value(EGL_UNKNOWN));
#endif
#ifdef EGL_BUFFER_PRESERVED
		mrb_define_const(mrb, constants, "EGL_BUFFER_PRESERVED", mrb_fixnum_value(EGL_BUFFER_PRESERVED));
#endif
#ifdef EGL_BUFFER_DESTROYED
		mrb_define_const(mrb, constants, "EGL_BUFFER_DESTROYED", mrb_fixnum_value(EGL_BUFFER_DESTROYED));
#endif
#ifdef EGL_OPENVG_IMAGE
		mrb_define_const(mrb, constants, "EGL_OPENVG_IMAGE", mrb_fixnum_value(EGL_OPENVG_IMAGE));
#endif
#ifdef EGL_CONTEXT_CLIENT_TYPE
		mrb_define_const(mrb, constants, "EGL_CONTEXT_CLIENT_TYPE", mrb_fixnum_value(EGL_CONTEXT_CLIENT_TYPE));
#endif
#ifdef EGL_CONTEXT_CLIENT_VERSION
		mrb_define_const(mrb, constants, "EGL_CONTEXT_CLIENT_VERSION", mrb_fixnum_value(EGL_CONTEXT_CLIENT_VERSION));
#endif
#ifdef EGL_MULTISAMPLE_RESOLVE_DEFAULT
		mrb_define_const(mrb, constants, "EGL_MULTISAMPLE_RESOLVE_DEFAULT", mrb_fixnum_value(EGL_MULTISAMPLE_RESOLVE_DEFAULT));
#endif
#ifdef EGL_MULTISAMPLE_RESOLVE_BOX
		mrb_define_const(mrb, constants, "EGL_MULTISAMPLE_RESOLVE_BOX", mrb_fixnum_value(EGL_MULTISAMPLE_RESOLVE_BOX));
#endif
#ifdef EGL_OPENGL_ES_API
		mrb_define_const(mrb, constants, "EGL_OPENGL_ES_API", mrb_fixnum_value(EGL_OPENGL_ES_API));
#endif
#ifdef EGL_OPENVG_API
		mrb_define_const(mrb, constants, "EGL_OPENVG_API", mrb_fixnum_value(EGL_OPENVG_API));
#endif
#ifdef EGL_OPENGL_API
		mrb_define_const(mrb, constants, "EGL_OPENGL_API", mrb_fixnum_value(EGL_OPENGL_API));
#endif
#ifdef EGL_DRAW
		mrb_define_const(mrb, constants, "EGL_DRAW", mrb_fixnum_value(EGL_DRAW));
#endif
#ifdef EGL_READ
		mrb_define_const(mrb, constants, "EGL_READ", mrb_fixnum_value(EGL_READ));
#endif
#ifdef EGL_CORE_NATIVE_ENGINE
		mrb_define_const(mrb, constants, "EGL_CORE_NATIVE_ENGINE", mrb_fixnum_value(EGL_CORE_NATIVE_ENGINE));
#endif
#ifdef EGL_COLORSPACE
		mrb_define_const(mrb, constants, "EGL_COLORSPACE", mrb_fixnum_value(EGL_COLORSPACE));
#endif
#ifdef EGL_ALPHA_FORMAT
		mrb_define_const(mrb, constants, "EGL_ALPHA_FORMAT", mrb_fixnum_value(EGL_ALPHA_FORMAT));
#endif
#ifdef EGL_COLORSPACE_sRGB
		mrb_define_const(mrb, constants, "EGL_COLORSPACE_sRGB", mrb_fixnum_value(EGL_COLORSPACE_sRGB));
#endif
#ifdef EGL_COLORSPACE_LINEAR
		mrb_define_const(mrb, constants, "EGL_COLORSPACE_LINEAR", mrb_fixnum_value(EGL_COLORSPACE_LINEAR));
#endif
#ifdef EGL_ALPHA_FORMAT_NONPRE
		mrb_define_const(mrb, constants, "EGL_ALPHA_FORMAT_NONPRE", mrb_fixnum_value(EGL_ALPHA_FORMAT_NONPRE));
#endif
#ifdef EGL_ALPHA_FORMAT_PRE
		mrb_define_const(mrb, constants, "EGL_ALPHA_FORMAT_PRE", mrb_fixnum_value(EGL_ALPHA_FORMAT_PRE));
#endif

	return constants;
}
예제 #18
0
static mrb_value
mrb_addrinfo_getaddrinfo(mrb_state *mrb, mrb_value klass)
{
  struct addrinfo hints, *res0, *res;
  mrb_value ai, ary, family, lastai, nodename, protocol, sa, service, socktype;
  mrb_int flags;
  int arena_idx, error;
  const char *hostname = NULL, *servname = NULL;

  ary = mrb_ary_new(mrb);
  arena_idx = mrb_gc_arena_save(mrb);  /* ary must be on arena! */

  family = socktype = protocol = mrb_nil_value();
  flags = 0;
  mrb_get_args(mrb, "oo|oooi", &nodename, &service, &family, &socktype, &protocol, &flags);

  if (mrb_string_p(nodename)) {
    hostname = mrb_str_to_cstr(mrb, nodename);
  } else if (mrb_nil_p(nodename)) {
    hostname = NULL;
  } else {
    mrb_raise(mrb, E_TYPE_ERROR, "nodename must be String or nil");
  }

  if (mrb_string_p(service)) {
    servname = mrb_str_to_cstr(mrb, service);
  } else if (mrb_fixnum_p(service)) {
    servname = mrb_str_to_cstr(mrb, mrb_funcall(mrb, service, "to_s", 0));
  } else if (mrb_nil_p(service)) {
    servname = NULL;
  } else {
    mrb_raise(mrb, E_TYPE_ERROR, "service must be String, Fixnum, or nil");
  }

  memset(&hints, 0, sizeof(hints));
  hints.ai_flags = flags;

  if (mrb_fixnum_p(family)) {
    hints.ai_family = mrb_fixnum(family);
  }

  if (mrb_fixnum_p(socktype)) {
    hints.ai_socktype = mrb_fixnum(socktype);
  }

  lastai = mrb_cv_get(mrb, klass, mrb_intern_lit(mrb, "_lastai"));
  if (mrb_cptr_p(lastai)) {
    freeaddrinfo(mrb_cptr(lastai));
    mrb_cv_set(mrb, klass, mrb_intern_lit(mrb, "_lastai"), mrb_nil_value());
  }

  error = getaddrinfo(hostname, servname, &hints, &res0);
  if (error) {
    mrb_raisef(mrb, E_SOCKET_ERROR, "getaddrinfo: %S", mrb_str_new_cstr(mrb, gai_strerror(error)));
  }
  mrb_cv_set(mrb, klass, mrb_intern_lit(mrb, "_lastai"), mrb_cptr_value(mrb, res0));

  for (res = res0; res != NULL; res = res->ai_next) {
    sa = mrb_str_new(mrb, (void *)res->ai_addr, res->ai_addrlen);
    ai = mrb_funcall(mrb, klass, "new", 4, sa, mrb_fixnum_value(res->ai_family), mrb_fixnum_value(res->ai_socktype), mrb_fixnum_value(res->ai_protocol));
    mrb_ary_push(mrb, ary, ai);
    mrb_gc_arena_restore(mrb, arena_idx);
  }

  freeaddrinfo(res0);
  mrb_cv_set(mrb, klass, mrb_intern_lit(mrb, "_lastai"), mrb_nil_value());

  return ary;
}