<div><span class="gmail_quote">On 10/17/07, <b class="gmail_sendername">Joe Mason</b> <<a href="mailto:joe@notcharles.ca">joe@notcharles.ca</a>> wrote:</span>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">On 10/17/07, Keith J. Farmer <<a href="mailto:kfarmer@thuban.org">kfarmer@thuban.org</a>> wrote:<br>
> Forgive my non-C-ness (it's been a long time since I wrote a native module<br>> for Python), but aren't you now buying into a major re-implementation of all<br>> the native Python standard library into C#?
<br><br>Couldn't the C/C# API just use IronPython objects and methods to<br>"implement" the Python standard library?</blockquote>
<div> </div>
<div>Yes, that would be the idea.</div>
<div> </div>
<div>I think it's best when thinking about the architecture to have a specific example to refer to. With that in mind, I'm going to repeat some code I wrote earlier in the thread (with a few modifications).</div>
<div> </div>
<div>
<div><font face="courier new,monospace">PyObject * ReverseSequence(PyObject * self, PyObject * args)</font></div>
<div><font face="courier new,monospace">{</font></div>
<div><font face="courier new,monospace"> PyObject * columns;</font></div>
<div><font face="courier new,monospace"> if (!PyArg_ParseTuple(args, "O", &columns))</font></div>
<div><font face="courier new,monospace"> {</font></div>
<div><font face="courier new,monospace"> return NULL;</font></div>
<div><font face="courier new,monospace"> }</font></div>
<div><font face="courier new,monospace"> </font></div>
<div><font face="courier new,monospace"> if (!PySequence_Check(columns))</font></div>
<div><font face="courier new,monospace"> {</font></div>
<div><font face="courier new,monospace"> PyErr_SetString(PyExc_ValueError, "must be a sequence");</font></div>
<div><font face="courier new,monospace"> return NULL;</font></div>
<div><font face="courier new,monospace"> }</font></div>
<div><font face="courier new,monospace"></font> </div>
<div><font face="Courier New"> int length = PySequence_Length(columns);</font></div>
<div><font face="courier new,monospace"> PyObject * result = PyTuple_New(length);</font></div>
<div><font face="courier new,monospace"> for (int i = 0; i < <font face="Courier New">length</font>; i++)</font></div>
<div><font face="courier new,monospace"> {</font></div>
<div><font face="courier new,monospace"> PyObject * value = PySequence_GetItem(sequence, i);</font></div>
<div><font face="courier new,monospace"> // Don't remember if I need to INCREF value</font></div>
<div><font face="courier new,monospace"> PySequence_SetItem(result, <font face="Courier New">length - </font>i - 1, value);</font></div>
<div><font face="courier new,monospace"> }</font></div>
<div><font face="courier new,monospace"> </font></div>
<div><font face="courier new,monospace"> return result;<br>}</font></div>
<div> </div>
<div>Obviously, this isn't a "real-world" example, but it does show a few requirements for the compatibility layer.</div>
<div>1) The code expects a sequence. What kind of data should we be allowed to pass to it from IronPython?</div>
<div>2) The code returns a "tuple". How will this tuple be translated into a CLR object for consumption by IronPython?</div>
<div> </div></div>
<div>--</div>
<div>Curt Hagenlocher</div>
<div><a href="mailto:curt@hagenlocher.org">curt@hagenlocher.org</a></div></div>