On 10/17/07, Paolo Molaro <[EMAIL PROTECTED]> wrote:
>
>
> The python API requires a couple dozen structure definitions plus a few
> dozen dllimport declarations. This can be about 200 lines of trivial
> to write declarative stuff.


I'm having trouble understanding what you mean by this.  Let's say I've got
an extension method that looks like this:

PyObject * ModifyColumns(PyObject * self, PyObject * args)
{
    PyObject * columns;
    if (!PyArg_ParseTuple(args, "O", &columns))
    {
        return NULL;
    }

    if (!PySequence_Check(columns))
    {
        PyErr_SetString(PyExc_ValueError, "parameter must be a sequence");
        return NULL;
    }

    PyObject * result = PyTuple_New(PySequence_Length(columns));
    for (int i = 0; i < PySequence_Length(columns); i++)
    {
        PyObject * value = PySequence_GetItem(sequence, i);
        // Do something to value
        // And make sure you don't screw up the reference count
        PySequence_SetItem(result, i, value);
    }

    return result;
}

In order to use this extension from IronPython, I need C implementations of
each of those API functions.  The PySequence_ methods should to be able to
understand CLR arrays or any other IEnumerable-like object.  I'm not sure
what PyTuple_New should return, but whatever it is will need to have
PyObject*-like semantics.

How does DllImport fit into this picture?  How can I avoid implementing all
these functions in C or C++?

--
Curt Hagenlocher
[EMAIL PROTECTED]
_______________________________________________
Users mailing list
Users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

Reply via email to