Esempio n. 1
0
CAMLprim value mlsdlevent_poll(value unit)
{
  SDL_Event evt;
  value v = Val_none;
  if(SDL_PollEvent(&evt) == 1)
    v = Val_some( value_of_SDLEvent(evt) );
  return v;
}
Esempio n. 2
0
CAMLprim value mapi_query_stub(value conn, value query)
{
    MapiHdl hdl = mapi_query((Mapi) conn, String_val(query));
    if (hdl == NULL) {
	return Val_int(0);
    } else {
	return Val_some((value) hdl);
    }
}
Esempio n. 3
0
CAMLextern_C value
caml_sfWindow_pollEvent(value win)
{
    sf::Event event;
    const char func_name[] = "SFWindow.pollEvent";
    bool isev = SfWindow_val(win)->pollEvent(event);
    if (isev) return Val_some(Val_sfEvent(event, func_name));
    else return Val_none;
}
Esempio n. 4
0
CAMLprim value mapi_fetch_row_stub(value hdl)
{
    int nr_fields = mapi_fetch_row((MapiHdl) hdl);
    if (nr_fields == 0) {
	return Val_int(0);
    } else {
	return Val_some(Val_int(nr_fields));
    }
}
Esempio n. 5
0
CAMLprim value mapi_fetch_field_stub(value hdl, value index)
{
    char *res = mapi_fetch_field((MapiHdl) hdl, Int_val(index));
    if (res) {
	return Val_some(caml_copy_string(res));
    } else {
	return Val_int(0);
    }
}
Esempio n. 6
0
/* ctypes_dlopen : filename:string -> flags:int -> library option */
value ctypes_dlopen(value filename, value flag)
{
  CAMLparam2(filename, flag);

  char *cfilename = filename == Val_none ? NULL : String_val(Some_val(filename));
  int cflag = Int_val(flag);

  void *handle = dlopen(cfilename, cflag);
  CAMLreturn (handle != NULL ? Val_some((value)handle) : Val_none);
}
Esempio n. 7
0
File: bv.c Progetto: amnh/phylocaml
CAMLprim value bv_CAML_eltint( value vbv, value vi ) /** BROKEN 32/64 bits **/
{
  CAMLparam2( vbv, vi );
  CAMLlocal1( vres );
  int res;
  vect* v;
  v = Vect_val(vbv);
  res = v->data[Int_val(vi)];
  vres = Val_some( Val_int(res) );
  CAMLreturn( vres );
}
Esempio n. 8
0
CAMLprim value mapi_get_name_stub(value ml_handle, value ml_index)
{
    int index = Int_val(ml_index);
    MapiHdl handle = (MapiHdl) ml_handle;
    assert(index < mapi_get_field_count(handle));
    char *fname = mapi_get_name(handle, index);
    if (fname) {
	return Val_some(caml_copy_string(fname));
    } else {
	return Val_none;
    }
}
Esempio n. 9
0
CAMLextern_C value
caml_sfIntRect_intersection(value rect1, value rect2)
{
    sf::IntRect intersection;
    bool inter =
        SfIntRect_val(rect1).intersects(SfIntRect_val(rect2), intersection);
    if (inter) {
        return Val_some(caml_copy_sfIntRect(intersection));
    } else {
        return Val_none;
    }
}
Esempio n. 10
0
/* ctypes_dlsym : ?handle:library -> symbol:string -> cvalue option */
value ctypes_dlsym(value handle_option, value symbol)
{
  CAMLparam2(handle_option, symbol);

  void *handle = handle_option == Val_none
    ? RTLD_DEFAULT
    : (void *)Some_val(handle_option);

  char *s = String_val(symbol);
  void *result = dlsym(handle, s);
  CAMLreturn(result == NULL
             ? Val_none
             : Val_some(caml_copy_int64((intptr_t)result)));
}
Esempio n. 11
0
CAMLprim value
caml_sfIntRect_intersection(value rect1, value rect2)
{
    sfIntRect _rect1;
    sfIntRect _rect2;
    sfIntRect intersection;
    SfIntRect_val(&_rect1, rect1);
    SfIntRect_val(&_rect2, rect2);
    sfBool inter = sfIntRect_intersects(&_rect1, &_rect2, &intersection);
    if (inter) {
        return Val_some(caml_copy_sfIntRect(&intersection));
    } else {
        return Val_none;
    }
}
Esempio n. 12
0
CAMLprim value segment_intersect_line(value segment1, value segment2) {
  CAMLparam2(segment1, segment2);
  CAMLlocal1(record_vector);
  Segment s = Segment_val(segment1);
  Segment s2 = Segment_val(segment2);
  Vector out;
  if (s.intersect_line(s2, out)) {
    record_vector = caml_alloc_small(2, Double_array_tag);
    Double_field(record_vector, 0) = out.x;
    Double_field(record_vector, 1) = out.y;
    CAMLreturn(Val_some(record_vector));
  } else {
    CAMLreturn(Val_none);
  }
}
Esempio n. 13
0
File: realpath.c Progetto: 2bj/hhvm
CAMLprim value
caml_realpath(value v) {
  char *input;
  char output[PATH_MAX];
  char *result;

  CAMLparam1(v);

  input = String_val(v);
  result = realpath(input, output);
  if (result == NULL) {
    CAMLreturn(Val_none);
  } else {
    CAMLreturn(Val_some(caml_copy_string(output)));
  }
}
Esempio n. 14
0
CAMLprim value mapi_connect_stub_bc(value *argv, int argn)
{
    assert(argn == 6);
    const char *host_str = String_val(argv[0]);
    const int port_i = Int_val(argv[1]);
    assert(port_i > 0 && port_i < 65536);
    const char *user_str = String_val(argv[2]);
    const char *passwd_str = String_val(argv[3]);
    const char *lang_str = String_val(argv[4]);
    const char *db_str = String_val(argv[5]);
    Mapi conn = mapi_connect(host_str, port_i, user_str, passwd_str, lang_str, db_str);
    if (conn) {
	return Val_some((value) conn);
    } else {
	return Val_none;
    }
}
Esempio n. 15
0
CAMLprim value mapi_connect_stub_native(value host, value port, value user, 
					value passwd, value lang, value db)
{
    const char *host_str = String_val(host);
    const int port_i = Int_val(port);
    assert(port_i > 0 && port_i < 65536);
    const char *user_str = String_val(user);
    const char *passwd_str = String_val(passwd);
    const char *lang_str = String_val(lang);
    const char *db_str = String_val(db);
    Mapi conn = mapi_connect(host_str, port_i, user_str, passwd_str, lang_str, db_str);
    if (conn) {
	return Val_some((value) conn);
    } else {
	return Val_none;
    }
}
Esempio n. 16
0
CAMLprim value mapi_fetch_field_list_stub(value handle)
{
    CAMLparam1(handle);
    CAMLlocal2(cli, cons);
    char **fields = mapi_fetch_field_array((MapiHdl) handle);
    int nr_fields = mapi_get_field_count((MapiHdl) handle);

    if (fields != NULL) {
	cli = Val_emptylist;

	int i = 0;

	for (i = (nr_fields - 1); i >= 0; --i) {
	    cons = caml_alloc(2, 0);
	    Store_field(cons, 0, caml_copy_string(fields[i]));
	    Store_field(cons, 1, cli);
	    cli = cons;
	}
    
	CAMLreturn(Val_some(cli));
    } else {
	CAMLreturn(Val_none);
    }
}
Esempio n. 17
0
/* ctypes_dlerror : unit -> string option */
value ctypes_dlerror(value unit)
{
  CAMLparam1(unit);
  const char *error = dlerror();
  CAMLreturn (error != NULL ? Val_some(caml_copy_string(error)) : Val_none);
}
static value Val_errno(int errnoval)
{
	if (errnoval == -1)
		return Val_none;
	return Val_some(Val_int(errnoval));
}
static value Val_context(const char *context)
{
	if (context == NULL)
		return Val_none;
	return Val_some(caml_copy_string(context));
}