Esempio n. 1
0
static int seed_sqlite_exec_callback(SeedObject function,
				     int argc,
				     gchar ** argv, gchar ** azColName)
{
  SeedGlobalContext ctx;
  SeedObject hash;
  int i;

  if (!function)
    return 0;

  ctx = seed_context_create(eng->group, NULL);

  hash = seed_make_object(ctx, 0, 0);
  for (i = 0; i < argc; i++)
    {
      seed_object_set_property(ctx, hash,
			       azColName[i],
			       seed_value_from_string(ctx, argv[i], 0));
    }

  seed_object_call(ctx, function, 0, 1, &hash, 0);

  seed_context_unref(ctx);

  return 0;
}
Esempio n. 2
0
static SeedValue
seed_gettext_dcngettext (SeedContext ctx,
                         SeedObject function,
                         SeedObject this_object,
                         gsize argument_count,
                         const SeedValue args[],
                         SeedException * exception)
{
	gchar * domainname, * msgid, * msgid_plural;
	guint n;
	gint category;
	SeedValue ret;

	CHECK_ARG_COUNT("gettext.dcngettext", 5);

	domainname = seed_value_to_string (ctx, args[0], exception);
	msgid = seed_value_to_string (ctx, args[1], exception);
	msgid_plural = seed_value_to_string (ctx, args[2], exception);
	n = seed_value_to_uint (ctx, args[3], exception);
	category = seed_value_to_int (ctx, args[4], exception);

	ret = seed_value_from_string (ctx,
	                              dcngettext(domainname, msgid, msgid_plural, n, category),
	                              exception);
	g_free(domainname);
	g_free(msgid);
	g_free(msgid_plural);

	return ret;
}
Esempio n. 3
0
static SeedValue
seed_xml_node_get_name (SeedContext ctx,
			SeedObject object,
			SeedString property_name,
			SeedException *exception)
{
  xmlNodePtr node = XML_NODE_PRIV (object);
  return seed_value_from_string (ctx, (gchar *)node->name, exception);
}
Esempio n. 4
0
static SeedValue
value_from_ffi_type (SeedContext ctx, 
		     GType otype,
		     GArgument *value, 
		     SeedException *exception)
{
  switch (g_type_fundamental (otype))
    {
    case G_TYPE_INT:
      return seed_value_from_int (ctx, value->v_int, exception);
      break;
    case G_TYPE_FLOAT:
      return seed_value_from_float (ctx, value->v_float, exception);
      break;
    case G_TYPE_DOUBLE:
      return seed_value_from_double (ctx, value->v_double, exception);
      break;
    case G_TYPE_BOOLEAN:
      return seed_value_from_boolean (ctx, value->v_boolean, exception);
      break;
    case G_TYPE_STRING:
      return seed_value_from_string (ctx, value->v_pointer, exception);
      break;
    case G_TYPE_CHAR:
      return seed_value_from_char (ctx, value->v_int, exception);
      break;
    case G_TYPE_UCHAR:
      return seed_value_from_uchar (ctx, value->v_uint, exception);
      break;
    case G_TYPE_UINT:
      return seed_value_from_uint (ctx, value->v_uint, exception);
      break;
    case G_TYPE_POINTER:
      return seed_make_pointer (ctx, value->v_pointer);
      break;
    case G_TYPE_LONG:
      return seed_value_from_long (ctx, value->v_long, exception);
      break;
    case G_TYPE_ULONG:
      return seed_value_from_ulong (ctx, value->v_ulong, exception);
      break;
    case G_TYPE_INT64:
      return seed_value_from_int64 (ctx, value->v_int64, exception);
      break;
    case G_TYPE_UINT64:
      return seed_value_from_uint64 (ctx, value->v_uint64, exception);
      break;
    case G_TYPE_NONE:
      return seed_make_null (ctx);
    default:
      g_warning ("Unsupported fundamental type in value_from_ffi_type: %s",
		 g_type_name(g_type_fundamental (otype)));
      return seed_make_null (ctx);
    }
}
Esempio n. 5
0
static SeedValue
seed_rl_buffer(SeedContext ctx,
	     SeedObject function,
	     SeedObject this_object,
	     size_t argument_count,
	     const SeedValue arguments[],
	     SeedValue * exception)
{
  CHECK_ARG_COUNT("readline.buffer", 0);
  return seed_value_from_string (ctx, rl_line_buffer, exception);
}
Esempio n. 6
0
static SeedValue
seed_xml_node_get_type (SeedContext ctx,
			SeedObject object,
			SeedString property_name,
			SeedException *exception)
{
  xmlNodePtr node = XML_NODE_PRIV (object);

  return seed_value_from_string (ctx,
				 seed_xml_element_type_to_string
				 (node->type), exception);
}
Esempio n. 7
0
static SeedValue
seed_xml_node_get_content (SeedContext ctx,
			SeedObject object,
			SeedString property_name,
			SeedException *exception)
{
  SeedValue ret;
  gchar *content;
  xmlNodePtr node = XML_NODE_PRIV (object);

  content = (gchar *)xmlNodeGetContent (node);
  ret = seed_value_from_string (ctx, content, exception);
  g_free (content);

  return ret;
}
Esempio n. 8
0
SeedValue
seed_cairo_status_to_string (SeedContext ctx,
			     SeedObject function,
			     SeedObject this_object,
			     gsize argument_count,
			     const SeedValue arguments[],
			     SeedException *exception)
{
  cairo_status_t status;

  if (argument_count != 1)
    {
      EXPECTED_EXCEPTION("status_to_string", "1 argument");
    }
  status = seed_value_to_long (ctx, arguments[0], exception);

  return seed_value_from_string (ctx, cairo_status_to_string (status), exception);
}
Esempio n. 9
0
SeedValue seed_pipe_read(SeedContext ctx,
			 SeedObject function,
			 SeedObject this_object,
			 size_t argument_count,
			 const SeedValue arguments[], SeedException * exception)
{
  SeedValue ret;
  gchar *read;
  GET_CHANNEL;
  
  CHECK_ARG_COUNT("multiprocessing.pipe.read", 0);

  g_io_channel_read_line(priv->read, &read, 0, 0, 0);
  ret = seed_value_from_string(ctx, read, exception);
  g_free(read);

  return ret;
}
Esempio n. 10
0
static SeedValue
seed_readline(SeedContext ctx,
	      SeedObject function,
	      SeedObject this_object,
	      size_t argument_count,
	      const SeedValue arguments[], SeedValue * exception)
{
  SeedValue valstr = 0;
  gchar *str = NULL;
  gchar *buf;
  const gchar *histfname = g_get_home_dir();
  gchar *path = g_build_filename(histfname, ".seed_history", NULL);

  if (!readline_has_initialized)
    {
      read_history(path);
      readline_has_initialized = TRUE;
    }

  CHECK_ARG_COUNT("readline.readline", 1);

  buf = seed_value_to_string(ctx, arguments[0], exception);

  str = readline(buf);
  if (str && *str)
    {
      add_history(str);
      valstr = seed_value_from_string(ctx, str, exception);
      g_free(str);
    }

  write_history(path);
  history_truncate_file(path, 1000);

  g_free(buf);
  g_free(path);

  if (valstr == 0)
    valstr = seed_make_null(ctx);

  return valstr;
}
Esempio n. 11
0
static SeedValue
seed_gettext_textdomain (SeedContext ctx,
                         SeedObject function,
                         SeedObject this_object,
                         gsize argument_count,
                         const SeedValue arguments[],
                         SeedException * exception)
{
	gchar * domain_name;
	SeedValue ret;

	CHECK_ARG_COUNT("gettext.textdomain", 1);

	domain_name = seed_value_to_string (ctx, arguments[0], exception);

	ret = seed_value_from_string (ctx, textdomain(domain_name), exception);
	g_free(domain_name);

	return ret;
}
Esempio n. 12
0
static SeedValue
seed_gettext_gettext (SeedContext ctx,
                      SeedObject function,
                      SeedObject this_object,
                      gsize argument_count,
                      const SeedValue arguments[],
                      SeedException * exception)
{
	gchar * msgid;
	SeedValue ret;

	CHECK_ARG_COUNT("gettext.gettext", 1);

	msgid = seed_value_to_string (ctx, arguments[0], exception);

	ret = seed_value_from_string (ctx, gettext(msgid), exception);

	g_free(msgid);

	return ret;
}
Esempio n. 13
0
static SeedValue
seed_gettext_setlocale (SeedContext ctx,
                        SeedObject function,
                        SeedObject this_object,
                        gsize argument_count,
                        const SeedValue args[],
                        SeedException * exception)
{
	gchar * locale;
	gint category;
	SeedValue ret;

	CHECK_ARG_COUNT("gettext.setlocale", 2);

	category = seed_value_to_int (ctx, args[0], exception);
	locale = seed_value_to_string (ctx, args[1], exception);

	ret = seed_value_from_string (ctx,
	                              setlocale(category, locale),
	                              exception);
	g_free(locale);

	return ret;
}
Esempio n. 14
0
static SeedValue
seed_gettext_bind_textdomain_codeset (SeedContext ctx,
                                      SeedObject function,
                                      SeedObject this_object,
                                      gsize argument_count,
                                      const SeedValue args[],
                                      SeedException * exception)
{
	gchar * domainname, * codeset;
	SeedValue ret;

	CHECK_ARG_COUNT("gettext.bind_textdomain_codeset", 2);

	domainname = seed_value_to_string (ctx, args[0], exception);
	codeset = seed_value_to_string (ctx, args[1], exception);

	ret = seed_value_from_string (ctx,
	                              bind_textdomain_codeset(domainname, codeset),
	                              exception);
	g_free(domainname);
	g_free(codeset);

	return ret;
}
Esempio n. 15
0
static SeedValue
seed_gettext_ngettext (SeedContext ctx,
                       SeedObject function,
                       SeedObject this_object,
                       gsize argument_count,
                       const SeedValue args[],
                       SeedException * exception)
{
	gchar * msgid, * msgid_plural;
	guint n;
	SeedValue ret;

	CHECK_ARG_COUNT("gettext.ngettext", 3);

	msgid = seed_value_to_string (ctx, args[0], exception);
	msgid_plural = seed_value_to_string (ctx, args[1], exception);
	n = seed_value_to_uint (ctx, args[2], exception);

	ret = seed_value_from_string (ctx, ngettext(msgid, msgid_plural, n), exception);
	g_free(msgid);
	g_free(msgid_plural);

	return ret;
}
Esempio n. 16
0
/* returns an error message or NULL */
static DBusMessage *
invoke_js_async_from_dbus(SeedContext ctx,
                          DBusBusType  bus_type,
                          DBusMessage *method_call,
			  SeedObject this_obj,
			  SeedObject method_obj,
			  SeedException *exception)
{
    DBusMessage *reply;
    int argc;
    SeedValue *argv;
    DBusMessageIter arg_iter;
    GArray *values;
    SeedObject callback_object;
    SeedValue sender_string, signature_string;
    gboolean thrown;
    SeedValue ignored;
    const char *signature;

    reply = NULL;
    thrown = FALSE;
    argc = 0;
    argv = NULL;

    if (!seed_js_values_from_dbus(ctx, &arg_iter, &values, exception))
      {
	if (!dbus_reply_from_exception(ctx, method_call, &reply, exception))
	  g_warning ("conversion of dbus method arg failed but no exception was set?");
        return reply;
      }

    /* we will add an argument, the callback */
    callback_object = seed_make_function(ctx, async_call_callback,
					 "" /* anonymous */);

    g_assert(callback_object);

    g_array_append_val(values, callback_object);

    /* We attach the DBus sender and serial as properties to
     * callback, so we don't need to bother with memory managing them
     * if the callback is never called and just discarded.*/
    sender_string = seed_value_from_string (ctx, dbus_message_get_sender (method_call), exception);
    if (!sender_string)
      {
        thrown = TRUE;
        goto out;
      }

    seed_object_set_property (ctx, callback_object, "_dbusSender", sender_string);
    seed_object_set_property (ctx, callback_object, "_dbusSerial",
			      seed_value_from_int (ctx, dbus_message_get_serial (method_call),
						   exception));
    seed_object_set_property (ctx, callback_object, "_dbusBusType",
			      seed_value_from_int (ctx, bus_type, exception));

    if (!signature_from_method(ctx,
                               method_obj,
                               &signature,
			       exception))
      {
        thrown = TRUE;
        goto out;
      }

    signature_string = seed_value_from_string (ctx, signature, exception);
    if (!signature_string)
      {
        thrown = TRUE;
        goto out;
      }
    seed_object_set_property (ctx, callback_object, "_dbusOutSignature",
			      signature_string);
    argc = values->len;
    argv = (SeedValue *)values->data;

    seed_object_call (ctx, method_obj, this_obj, argc,
		      argv, &ignored);
out:
    if (thrown)
      {
        if (!dbus_reply_from_exception(ctx, method_call, &reply, exception))
	  g_warning("conversion of dbus method arg failed but no exception was set?");
      }

    g_array_free (values, TRUE);

    return reply;
}
Esempio n. 17
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"));


}