示例#1
0
static JSValueRef
seed_gobject_signal_disconnect (JSContextRef ctx,
				JSObjectRef function,
				JSObjectRef thisObject,
				size_t argumentCount,
				const JSValueRef arguments[],
				JSValueRef * exception)
{
  gulong id;
  if (argumentCount != 1)
    {
      seed_make_exception (ctx, exception, "ArgumentError",
			   "Signal disconnection expects 1 argument"
			   " got %zd", argumentCount);
      return JSValueMakeUndefined (ctx);
    }
  id = seed_value_to_ulong (ctx, arguments[0], exception);
  g_signal_handler_disconnect (JSObjectGetPrivate (thisObject), id);

  return JSValueMakeUndefined (ctx);
}
示例#2
0
SeedValue seed_mpfr_root (SeedContext ctx,
                         SeedObject function,
                         SeedObject this_object,
                         gsize argument_count,
                         const SeedValue args[],
                         SeedException *exception)
{
    mpfr_rnd_t rnd;
    mpfr_ptr rop, op;
    gint ret;
    gulong k;

    CHECK_ARG_COUNT("mpfr.root", 3);

    rop = seed_object_get_private(this_object);
    rnd = seed_value_to_mpfr_rnd_t(ctx, args[2], exception);

    if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
    {
        op = seed_object_get_private(args[0]);
    }
    else
    {
        TYPE_EXCEPTION("mpfr.root", "mpfr_t");
    }

    if ( seed_value_is_number(ctx, args[1]) )
    {
        k = seed_value_to_ulong(ctx, args[1], exception);
    }
    else
    {
        TYPE_EXCEPTION("mpfr.root", "unsigned long int");
    }


    ret = mpfr_root(rop, op, k, rnd);

    return seed_value_from_int(ctx, ret, exception);
}
示例#3
0
SeedValue seed_mpfr_cmp_si_2exp (SeedContext ctx,
                                 SeedObject function,
                                 SeedObject this_object,
                                 gsize argument_count,
                                 const SeedValue args[],
                                 SeedException *exception)
{
    mpfr_ptr op1;
    gulong op2;
    mp_exp_t exp;
    gint ret;

    CHECK_ARG_COUNT("mpfr.cmp_si_2exp", 2);

    op1 = seed_object_get_private(this_object);

    if ( seed_value_is_number(ctx, args[0]) )
    {
        op2 = seed_value_to_ulong(ctx, args[0], exception);
    }
    else
    {
        TYPE_EXCEPTION("mpfr.cmp_si_2exp", "long int");
    }

    if ( seed_value_is_number(ctx, args[1]) )
    {
        exp = seed_value_to_mp_exp_t(ctx, args[1], exception);
    }
    else
    {
        TYPE_EXCEPTION("mpfr.cmp_si_2exp", "mp_exp_t");
    }

    ret = mpfr_cmp_si_2exp(op1, op2, exp);

    return seed_value_from_int(ctx, ret, exception);
}
示例#4
0
文件: seed-ffi.c 项目: dannote/seed
static ffi_type *
gtype_to_ffi_type (SeedContext ctx, 
		   SeedValue value,
		   GType otype,
		   GArgument *garg,
		   gpointer *arg,
		   SeedException *exception)
{
  ffi_type *return_type;
  GType type = g_type_fundamental (otype);
  g_assert (type != G_TYPE_INVALID);

  switch (type)
    {
    case G_TYPE_BOOLEAN:
    case G_TYPE_CHAR:
    case G_TYPE_INT:
      return_type = &ffi_type_sint;
      garg->v_int = seed_value_to_int (ctx, value, exception);
      *arg = (gpointer)garg;
      break;
    case G_TYPE_UCHAR:
    case G_TYPE_UINT:
      return_type = &ffi_type_uint;
      garg->v_uint = seed_value_to_uint (ctx, value, exception);
      *arg = (gpointer)garg;
      break;
    case G_TYPE_STRING:
      return_type = &ffi_type_pointer;
      garg->v_pointer = seed_value_to_string (ctx, value, exception);
      *arg = (gpointer)garg;
      break;
    case G_TYPE_OBJECT:
      //    case G_TYPE_BOXED:
    case G_TYPE_POINTER:
      return_type = &ffi_type_pointer;
      garg->v_pointer = seed_pointer_get_pointer (ctx, value);
      *arg = (gpointer)garg;
      break;
    case G_TYPE_FLOAT:
      return_type = &ffi_type_float;
      garg->v_float = seed_value_to_float (ctx, value, exception);
      *arg = (gpointer)garg;
      break;
    case G_TYPE_DOUBLE:
      return_type = &ffi_type_double;
      garg->v_double = seed_value_to_double (ctx, value, exception);
      *arg = (gpointer)garg;
      break;
    case G_TYPE_LONG:
      return_type = &ffi_type_slong;
      garg->v_uint = seed_value_to_uint (ctx, value, exception);
      *arg = (gpointer)garg;
      break;
    case G_TYPE_ULONG:
      return_type = &ffi_type_ulong;
      garg->v_ulong = seed_value_to_ulong (ctx, value, exception);
      *arg = (gpointer)garg;
      break;
    case G_TYPE_INT64:
      return_type = &ffi_type_sint64;
      garg->v_int64 = seed_value_to_int64 (ctx, value, exception);
      *arg = (gpointer)garg;
      break;
    case G_TYPE_UINT64:
      return_type = &ffi_type_uint64;
      garg->v_uint64 = seed_value_to_uint64 (ctx, value, exception);
      *arg = (gpointer)garg;
      break;
    default:
      g_warning ("Unsupported fundamental in type: %s", g_type_name (type));
      return_type = &ffi_type_pointer;
      garg->v_pointer = NULL;
      *arg = (garg->v_pointer);
      break;
    }
  return return_type;
}
示例#5
0
void basic_types(TestSimpleFixture * fixture, gconstpointer _data)
{
	// bool to/from JS equality

	gboolean bool_test_in = TRUE;
	SeedValue *bool_test = seed_value_from_boolean(fixture->context,
												   bool_test_in, NULL);
	gboolean bool_test_out = seed_value_to_boolean(fixture->context,
												   bool_test, NULL);

	g_assert(bool_test_in == bool_test_out);

	// uint to/from JS equality

	guint uint_test_in = 2946623;
	SeedValue *uint_test = seed_value_from_uint(fixture->context,
												uint_test_in, NULL);
	guint uint_test_out = seed_value_to_uint(fixture->context,
											 uint_test, NULL);

	g_assert(uint_test_in == uint_test_out);

	// int to/from JS equality

	gint int_test_in = -54374;
	SeedValue *int_test = seed_value_from_int(fixture->context,
											  int_test_in, NULL);
	gint int_test_out = seed_value_to_int(fixture->context,
										  int_test, NULL);

	g_assert(int_test_in == int_test_out);

	// char to/from JS equality

	gchar char_test_in = -126;
	SeedValue *char_test = seed_value_from_char(fixture->context,
												char_test_in, NULL);
	gchar char_test_out = seed_value_to_char(fixture->context,
											 char_test, NULL);

	g_assert(char_test_in == char_test_out);

	// uchar to/from JS equality

	guchar uchar_test_in = 250;
	SeedValue *uchar_test = seed_value_from_uchar(fixture->context,
												  uchar_test_in, NULL);
	guchar uchar_test_out = seed_value_to_uchar(fixture->context,
												uchar_test, NULL);

	g_assert(uchar_test_in == uchar_test_out);

	// long to/from JS equality

	glong long_test_in = -454250;
	SeedValue *long_test = seed_value_from_long(fixture->context,
												long_test_in, NULL);
	glong long_test_out = seed_value_to_long(fixture->context,
											 long_test, NULL);

	g_assert(long_test_in == long_test_out);

	// ulong to/from JS equality

	gulong ulong_test_in = 250;
	SeedValue *ulong_test = seed_value_from_ulong(fixture->context,
												  ulong_test_in, NULL);
	gulong ulong_test_out = seed_value_to_ulong(fixture->context,
												ulong_test, NULL);

	g_assert(ulong_test_in == ulong_test_out);

	// int64 to/from JS equality

	gint64 int64_test_in = -54374;
	SeedValue *int64_test = seed_value_from_int64(fixture->context,
												  int64_test_in, NULL);
	gint64 int64_test_out = seed_value_to_int64(fixture->context,
												int64_test, NULL);

	g_assert(int64_test_in == int64_test_out);

	// uint64 to/from JS equality

	guint64 uint64_test_in = 2946623;
	SeedValue *uint64_test = seed_value_from_uint64(fixture->context,
													uint64_test_in, NULL);
	guint64 uint64_test_out = seed_value_to_uint64(fixture->context,
												   uint64_test, NULL);

	g_assert(uint64_test_in == uint64_test_out);

	// float to/from JS equality

	gfloat float_test_in = 1.618;
	SeedValue *float_test = seed_value_from_float(fixture->context,
												  float_test_in, NULL);
	gfloat float_test_out = seed_value_to_float(fixture->context,
												float_test, NULL);

	g_assert(float_test_in == float_test_out);

	// double to/from JS equality

	gdouble double_test_in = 1.6134857638;
	SeedValue *double_test = seed_value_from_double(fixture->context,
													double_test_in, NULL);
	gdouble double_test_out = seed_value_to_double(fixture->context,
												   double_test, NULL);

	g_assert(double_test_in == double_test_out);

	// string to/from JS equality

	gchar *string_test_in = "Hello, world!";
	SeedValue *string_test = seed_value_from_string(fixture->context,
													string_test_in, NULL);
	gchar *string_test_out = seed_value_to_string(fixture->context,
												  string_test, NULL);

	g_assert(strncmp(string_test_in, string_test_out,
					 strlen(string_test_in)) == 0);

	// filename to/from JS equality

	gchar *filename_test_in = "/bin";
	SeedValue *filename_test = seed_value_from_filename(fixture->context,
														filename_test_in,
														NULL);
	gchar *filename_test_out = seed_value_to_filename(fixture->context,
													  filename_test, NULL);

	g_assert(strncmp(filename_test_in, filename_test_out,
					 strlen(filename_test_in)) == 0);
	SeedValue si[2];
	si[0] = seed_value_from_string (fixture->context, "Hi", NULL);
	si[1] = seed_value_from_int (fixture->context, 1, NULL);
	gint ni;
	gchar *ns;

	seed_value_to_format (fixture->context, "si", si, NULL, &ns, &ni, NULL);
	g_assert (ni == 1);
	g_assert (!strcmp(ns, "Hi"));


}
示例#6
0
SeedValue seed_mpfr_pow (SeedContext ctx,
                         SeedObject function,
                         SeedObject this_object,
                         gsize argument_count,
                         const SeedValue args[],
                         SeedException * exception)
{
    mpfr_rnd_t rnd;
    mpfr_ptr rop, op1, op2;
    gint ret;
    glong iop;
    gulong uiop1, uiop2;
    seed_mpfr_t argt1, argt2;
    /* only want 1 double argument. alternatively, could accept 2,
       add those, and set from the result*/

    CHECK_ARG_COUNT("mpfr.pow", 3);

    rop = seed_object_get_private(this_object);
    rnd = seed_value_to_mpfr_rnd_t(ctx, args[2], exception);

    argt1 = seed_mpfr_arg_type(ctx, args[0], exception);
    argt2 = seed_mpfr_arg_type(ctx, args[1], exception);

    if ( (argt1 & argt2) == SEED_MPFR_MPFR )
    {
        /* both mpfr_t */
        op1 = seed_object_get_private(args[0]);
        op2 = seed_object_get_private(args[1]);
        ret = mpfr_pow(rop, op1, op2, rnd);
    }
    else if ( (argt1 | argt2) == (SEED_MPFR_MPFR | SEED_MPFR_DOUBLE) )
    {
        /* a double and an mpfr_t. Figure out the order */
        /* FIXME: is this switching ui and si bad? si_pow doesn't exist,
           and it's all from double anyway */
        if ( argt1 == SEED_MPFR_MPFR )
        {
            op1 = seed_object_get_private(args[0]);
            iop = seed_value_to_long(ctx, args[1], exception);
            ret = mpfr_pow_si(rop, op1, iop, rnd);
        }
        else
        {
            uiop1 = seed_value_to_ulong(ctx, args[0], exception);
            op2 = seed_object_get_private(args[1]);
            ret = mpfr_ui_pow(rop, uiop1, op2, rnd);
        }
    }
    else if ( (argt1 & argt2) == SEED_MPFR_DOUBLE )
    {
        /* pretend both ui */
        uiop1 = seed_value_to_ulong(ctx, args[0], exception);
        uiop2 = seed_value_to_ulong(ctx, args[1], exception);
        ret = mpfr_ui_pow_ui(rop, uiop1, uiop2, rnd);
    }
    else
    {
        TYPE_EXCEPTION("mpfr.pow", "int or unsigned int and mpfr_t");
    }

    return seed_value_from_int(ctx, ret, exception);
}