SeedValue seed_mpfr_nexttoward (SeedContext ctx,
                                SeedObject function,
                                SeedObject this_object,
                                gsize argument_count,
                                const SeedValue args[],
                                SeedException *exception)
{
    mpfr_ptr rop, op;

    CHECK_ARG_COUNT("mpfr.nexttoward", 1);

    rop = seed_object_get_private(this_object);

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

    mpfr_nexttoward(rop, op);

    return seed_make_null(ctx);
}
SeedValue seed_mpfr_remainder (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;

    CHECK_ARG_COUNT("mpfr.remainder", 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) &&
         seed_value_is_object_of_class(ctx, args[1], mpfr_class))
    {
        op1 = seed_object_get_private(args[0]);
        op2 = seed_object_get_private(args[1]);
    }
    else
    {
        TYPE_EXCEPTION("mpfr.remainder", "mpfr_t");
    }

    ret = mpfr_remainder(rop, op1, op2, rnd);

    return seed_value_from_int(ctx, ret, exception);
}
Beispiel #3
0
static PyObject* py_glIsProgram(PyObject *, PyObject *args) {
  CHECK_ARG_COUNT(args, 1);
  Uint prg(PyTuple_GetItem(args, 0));
  PyObject *rv = (glIsProgram(prg) == GL_TRUE ? Py_True : Py_False);
  Py_INCREF(rv);
  return rv;
}
SeedValue seed_mpfr_sub (SeedContext ctx,
                         SeedObject function,
                         SeedObject this_object,
                         gsize argument_count,
                         const SeedValue args[],
                         SeedException *exception)
{
    mpfr_rnd_t rnd;
    mpfr_ptr rop, op1, op2;
    gdouble dop1, dop2;
    gint ret;
    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.sub", 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_sub(rop, op1, op2, rnd);
    }
    else if ( (argt1 | argt2) == (SEED_MPFR_MPFR | SEED_MPFR_DOUBLE) )
    {
        /* a double and an mpfr_t. Figure out the order */
        if ( argt1 == SEED_MPFR_MPFR )
        {
            op1 = seed_object_get_private(args[0]);
            dop2 = seed_value_to_double(ctx, args[1], exception);
            mpfr_sub_d(rop, op1, dop2, rnd);
        }
        else
        {
            dop1 = seed_value_to_double(ctx, args[0], exception);
            op2 = seed_object_get_private(args[1]);
            mpfr_d_sub(rop, dop1, op2, rnd);
        }
    }
    else if ( (argt1 & argt2) == SEED_MPFR_DOUBLE )
    {
        /* 2 doubles. hopefully doesn't happen */
        dop1 = seed_value_to_double(ctx, args[0], exception);
        dop2 = seed_value_to_double(ctx, args[1], exception);
        ret = mpfr_set_d(rop, dop1 - dop2, rnd);
    }
    else
    {
        TYPE_EXCEPTION("mpfr.sub", "double or mpfr_t");
    }

    return seed_value_from_int(ctx, ret, exception);
}
Beispiel #5
0
SeedValue seed_mpfr_cmpabs (SeedContext ctx,
                            SeedObject function,
                            SeedObject this_object,
                            gsize argument_count,
                            const SeedValue args[],
                            SeedException *exception)
{
    mpfr_ptr rop, op;
    gint ret;

    CHECK_ARG_COUNT("mpfr.cmpabs", 1);

    rop = seed_object_get_private(this_object);

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

    ret = mpfr_cmpabs(rop, op);

    return seed_value_from_int(ctx, ret, exception);
}
Beispiel #6
0
static PyObject* py_glGetVertexAttrib(PyObject *, PyObject *args) {
  CHECK_ARG_COUNT(args, 2);
  PyObject *rv = 0;
  Uint attrib(PyTuple_GetItem(args, 0));
  Enum pname(PyTuple_GetItem(args, 1));
  switch (pname) {
    case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING:
    case GL_VERTEX_ATTRIB_ARRAY_ENABLED:
    case GL_VERTEX_ATTRIB_ARRAY_SIZE:
    case GL_VERTEX_ATTRIB_ARRAY_STRIDE:
    case GL_VERTEX_ATTRIB_ARRAY_TYPE:
    case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED: {
      GLint value;
      glGetVertexAttribiv(attrib, pname, &value);
      rv = PyInt_FromLong(value);
      break;
    }
    case GL_CURRENT_VERTEX_ATTRIB: {
      Array1D<Float> values(4);
      glGetVertexAttribfv(attrib, pname, values);
      rv = values.toPy();
      break;
    }
    default:
      PyErr_SetString(PyExc_RuntimeError, "gl.GetVertexAttrib: invalid parameter name");
  }
  return rv;
}
Beispiel #7
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;
}
Beispiel #8
0
static PyObject* py_glIsShader(PyObject *, PyObject *args) {
  CHECK_ARG_COUNT(args, 1);
  Uint shader(PyTuple_GetItem(args, 0));
  PyObject *rv = (glIsShader(shader) == GL_TRUE ? Py_True : Py_False);
  Py_INCREF(rv);
  return rv;
}
Beispiel #9
0
SeedValue
seed_gtk_builder_connect_signals(SeedContext ctx,
				 SeedObject function,
				 SeedObject this_object,
				 gsize argument_count,
				 const SeedValue arguments[],
				 SeedException *exception)
{
  builder_ud ud;
  GtkBuilder *b;
  
  CHECK_ARG_COUNT("GtkBuilder.connect_signals", 1);

  if (!seed_value_is_object (ctx, arguments[0]))
    {
      seed_make_exception (ctx, exception, "TypeError",
			   "connect_signals expects one object as the first argument");
      return seed_make_undefined (ctx);
    }

  b = GTK_BUILDER (seed_value_to_object (ctx, this_object, exception));
  ud.ctx = ctx;
  ud.obj = arguments[0];
  if (argument_count == 2)
    ud.user_data = arguments[1];
  else
    ud.user_data = NULL;
  gtk_builder_connect_signals_full(b, seed_builder_connect_func, &ud);

  return seed_make_undefined (ctx);
}
Beispiel #10
0
static PyObject* py_glDrawBuffers(PyObject *, PyObject *args) {
  CHECK_ARG_COUNT(args, 1);
  Array1D<Enum> buffers;
  if (buffers.fromPy(PyTuple_GetItem(args, 0))) {
    glDrawBuffers(buffers.size(), buffers);
  }
  Py_RETURN_NONE;
}
Beispiel #11
0
static PyObject* py_glGetVertexAttribPointer(PyObject *, PyObject *args) {
  CHECK_ARG_COUNT(args, 2);
  Uint prg(PyTuple_GetItem(args, 0));
  Enum param(PyTuple_GetItem(args, 1));
  GLvoid *ptr = 0;
  glGetVertexAttribPointerv(prg, param, &ptr);
  return PyCObject_FromVoidPtr(ptr, NULL);
}
Beispiel #12
0
static PyObject* py_glShaderSource(PyObject *, PyObject *args) {
  CHECK_ARG_COUNT(args, 2);
  Uint shader(PyTuple_GetItem(args, 0));
  Array1D<String> strings;
  if (strings.fromPy(PyTuple_GetItem(args, 1))) {
    glShaderSource(shader, strings.size(), strings, 0);
  }
  Py_RETURN_NONE;
}
Beispiel #13
0
static int lua_glLoadTransposeMatrixf(lua_State *L) {
  CHECK_ARG_COUNT(L, 1);
  Array1D<Float> m(L, 1);
  if (m.size() != 16) {
    luaL_error(L, "gl.LoadTransposeMatrixf: invalid matrix data");
  }
  glLoadTransposeMatrixf(m);
  return 0;
}
Beispiel #14
0
static int lua_glMultTransposeMatrixd(lua_State *L) {
  CHECK_ARG_COUNT(L, 1);
  Array1D<Double> m(L, 1);
  if (m.size() != 16) {
    luaL_error(L, "gl.MultTransposeMatrixd: invalid matrix data");
  }
  glMultTransposeMatrixd(m);
  return 0;
}
Beispiel #15
0
static PyObject* py_glGetShaderSource(PyObject *, PyObject *args) {
  CHECK_ARG_COUNT(args, 1);
  Uint shader(PyTuple_GetItem(args, 0));
  GLint len=0;
  glGetShaderiv(shader, GL_SHADER_SOURCE_LENGTH, &len);
  //GLchar *src = new GLchar[len+1];
  Array1D<Char> src(len+1);
  glGetShaderSource(shader, len, NULL, src);
  return PyString_FromString(src);
  //delete[] src;
}
Beispiel #16
0
static PyObject* py_glGetShaderInfoLog(PyObject *, PyObject *args) {
  CHECK_ARG_COUNT(args, 1);
  Uint shader(PyTuple_GetItem(args, 0));
  GLint len=0;
  glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &len);
  //GLchar *log = new GLchar[len+1];
  Array1D<Char> log(len+1);
  glGetShaderInfoLog(shader, len, NULL, log);
  return PyString_FromString(log);
  //delete[] log;
}
Beispiel #17
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);
}
Beispiel #18
0
static SeedValue
seed_rl_done(SeedContext ctx,
	     SeedObject function,
	     SeedObject this_object,
	     size_t argument_count,
	     const SeedValue arguments[],
	     SeedValue * exception)
{
  CHECK_ARG_COUNT("readline.done", 0);
  rl_done = 1;
  return seed_make_null (ctx);
}
Beispiel #19
0
static PyObject* py_glGetAttachedShaders(PyObject *, PyObject *args) {
  CHECK_ARG_COUNT(args, 1);
  Uint prg(PyTuple_GetItem(args, 0));
  GLint count=0;
  glGetProgramiv(prg, GL_ATTACHED_SHADERS, &count);
  if (count == 0) {
    return PyList_New(0);
  } else {
    Array1D<Uint> shaders(count);
    glGetAttachedShaders(prg, count, NULL, shaders);
    return shaders.toPy();
  }
}
Beispiel #20
0
SeedValue seed_mpfr_integer_p (SeedContext ctx,
                               SeedObject function,
                               SeedObject this_object,
                               gsize argument_count,
                               const SeedValue args[],
                               SeedException *exception)
{
    mpfr_ptr rop;
    gboolean ret;

    CHECK_ARG_COUNT("mpfr.integer", 0);
    rop = seed_object_get_private(this_object);
    ret = mpfr_integer_p(rop);

    return seed_value_from_boolean(ctx, ret, exception);
}
Beispiel #21
0
SeedValue seed_mpfr_nextabove (SeedContext ctx,
                               SeedObject function,
                               SeedObject this_object,
                               gsize argument_count,
                               const SeedValue args[],
                               SeedException *exception)
{
    mpfr_ptr rop;

    CHECK_ARG_COUNT("mpfr.nextabove", 0);

    rop = seed_object_get_private(this_object);

    mpfr_nextabove(rop);
    return seed_make_null(ctx);
}
Beispiel #22
0
SeedObject seed_construct_pipe(SeedContext ctx,
			       SeedObject constructor,
			       size_t argument_count,
			       const SeedValue arguments[],
			       SeedException * exception)
{
  SeedObject jsone, jstwo, jsret;
  int fd1[2], fd2[2];
  pipe_priv *priv_one, *priv_two;
  
  CHECK_ARG_COUNT("multiprocessing.pipe constructor", 0);

  if (pipe(fd1) < 0)
    {
      perror("Pipe failed. Make me a javascript exception");
      return seed_make_null(ctx);
    }
  if (pipe(fd2) < 0)
    {
      perror("Pipe failed. Make me a javascript exception");
      return seed_make_null(ctx);
    }

  priv_one = g_new0(pipe_priv, 1);
  priv_two = g_new0(pipe_priv, 1);

  priv_one->read = g_io_channel_unix_new(fd1[0]);
  priv_one->write = g_io_channel_unix_new(fd2[1]);
  priv_two->read = g_io_channel_unix_new(fd2[0]);
  priv_two->write = g_io_channel_unix_new(fd1[1]);

  g_io_channel_set_close_on_unref(priv_one->read, TRUE);
  g_io_channel_set_close_on_unref(priv_one->write, TRUE);
  g_io_channel_set_close_on_unref(priv_two->read, TRUE);
  g_io_channel_set_close_on_unref(priv_two->write, TRUE);

  jsret = seed_make_object(ctx, 0, 0);
  jsone = seed_make_object(ctx, pipe_class, priv_one);
  jstwo = seed_make_object(ctx, pipe_class, priv_two);

  seed_object_set_property_at_index(ctx, jsret, 0, jsone, exception);
  seed_object_set_property_at_index(ctx, jsret, 1, jstwo, exception);

  return jsret;
}
Beispiel #23
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;
}
Beispiel #24
0
static PyObject* py_glGetActiveUniform(PyObject *, PyObject *args) {
  CHECK_ARG_COUNT(args, 2);
  Uint prg(PyTuple_GetItem(args, 0));
  Uint idx(PyTuple_GetItem(args, 1));
  GLint len = 0;
  glGetProgramiv(prg, GL_ACTIVE_UNIFORM_MAX_LENGTH, &len);
  //GLchar *name = new GLchar[len+1];
  Array1D<Char> name(len+1);
  GLint size;
  GLenum type;
  glGetActiveUniform(prg, idx, len, NULL, &size, &type, name);
  PyObject *rv = PyTuple_New(3);
  PyTuple_SetItem(rv, 0, PyInt_FromLong(size));
  PyTuple_SetItem(rv, 1, PyInt_FromLong(type));
  PyTuple_SetItem(rv, 2, PyString_FromString(name));
  //delete[] name;
  return rv;
}
Beispiel #25
0
static SeedValue
seed_rl_insert(SeedContext ctx,
	       SeedObject function,
	       SeedObject this_object,
	       size_t argument_count,
	       const SeedValue arguments[],
	       SeedValue * exception)
{
  gchar *ins;
  gint ret;
  
  CHECK_ARG_COUNT("readline.insert", 1);
  
  ins = seed_value_to_string (ctx, arguments[0], exception);
  ret = rl_insert_text (ins);
  g_free (ins);

  return seed_value_from_int (ctx, ret, exception);
}
Beispiel #26
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;
}
Beispiel #27
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;
}
Beispiel #28
0
static PyObject* py_glGetShader(PyObject *, PyObject *args) {
  CHECK_ARG_COUNT(args, 2);
  PyObject *rv = 0;
  Uint prg(PyTuple_GetItem(args, 0));
  Enum pname(PyTuple_GetItem(args, 1));
  GLint dim = PyGL::Instance().getParamDim(PyGL::Shaderiv, pname);
  if (dim > 0) {
    Array1D<Int> param(dim);
    glGetShaderiv(prg, pname, param);
    if (dim == 1) {
      rv = PyInt_FromLong(param[0]);
    } else {
      rv = param.toPy();
    }
  }
  if (dim == 0) {
    PyErr_SetString(PyExc_RuntimeError, "gl.GetShader: invalid parameter name");
  }
  return rv;
}
Beispiel #29
0
SeedValue seed_pipe_write(SeedContext ctx,
			  SeedObject function,
			  SeedObject this_object,
			  size_t argument_count,
			  const SeedValue arguments[],
			  SeedException * exception)
{
  gchar *data;
  gsize written;
  gchar eol = '\n';
  GET_CHANNEL;
  
  CHECK_ARG_COUNT("multiprocessing.pipe.write", 1);

  data = seed_value_to_string(ctx, arguments[0], exception);
  g_io_channel_write_chars(priv->write, data, -1, &written, 0);
  g_io_channel_write_chars(priv->write, &eol, 1, 0, 0);
  g_io_channel_flush(priv->write, 0);

  return seed_value_from_int(ctx, written, exception);
}
Beispiel #30
0
static SeedValue
seed_readline_bind(SeedContext ctx,
		   SeedObject function,
		   SeedObject this_object,
		   size_t argument_count,
		   const SeedValue arguments[], SeedValue * exception)
{
  gchar *key;
  ffi_closure *c;
  
  CHECK_ARG_COUNT("readline.bind", 2);

  key = seed_value_to_string(ctx, arguments[0], exception);
  c = seed_make_rl_closure((SeedObject) arguments[1]);

  rl_bind_key(*key, (rl_command_func_t *) c);

  g_free(key);

  return seed_make_null(ctx);
}