<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Can Ruby, Python and Objective-C Co-exist in a Single Application?</title>
	<atom:link href="http://www.friday.com/bbum/2007/11/25/can-ruby-python-an-objective-c-co-exist-in-a-single-application/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.friday.com/bbum/2007/11/25/can-ruby-python-an-objective-c-co-exist-in-a-single-application/</link>
	<description>...so google can index my head.</description>
	<lastBuildDate>Fri, 19 Mar 2010 04:34:11 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: sbwoodside</title>
		<link>http://www.friday.com/bbum/2007/11/25/can-ruby-python-an-objective-c-co-exist-in-a-single-application/comment-page-1/#comment-190045</link>
		<dc:creator>sbwoodside</dc:creator>
		<pubDate>Tue, 10 Feb 2009 07:52:38 +0000</pubDate>
		<guid isPermaLink="false">http://www.friday.com/bbum/2007/11/25/can-ruby-python-an-objective-c-co-exist-in-a-single-application/#comment-190045</guid>
		<description>Thanks for posting this. &lt;a href=&quot;http://simonwoodside.com/weblog/2009/2/10/wondeful_joy_mix_ruby_and/&quot;&gt;I&#039;m doing the same thing between MacRuby ruby and Objective-C&lt;/a&gt;. I figured it out with clues from here:</description>
		<content:encoded><![CDATA[<p>Thanks for posting this. <a href="http://simonwoodside.com/weblog/2009/2/10/wondeful_joy_mix_ruby_and/">I&#8217;m doing the same thing between MacRuby ruby and Objective-C</a>. I figured it out with clues from here:</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: red</title>
		<link>http://www.friday.com/bbum/2007/11/25/can-ruby-python-an-objective-c-co-exist-in-a-single-application/comment-page-1/#comment-186002</link>
		<dc:creator>red</dc:creator>
		<pubDate>Wed, 26 Mar 2008 23:25:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.friday.com/bbum/2007/11/25/can-ruby-python-an-objective-c-co-exist-in-a-single-application/#comment-186002</guid>
		<description>WOOOHOOOO!
       Okay, for those of you who internet searched to get here (&#039;cause you were suffering the same level of documentation void that I have been suffering) --- I have some explanation of 2 days of struggling and trial and (lots of) error.   PyObjC really does bridge both ways, even if the examples fail to show this (which they do), you can call Python from within Objective-C code.

        Repeating that:  Yes, you can indeed instantiate a python class object (as demo&#039;d by Bob in his attached source code) and call all sorts of instance methods on that object. 

        &lt;b&gt;Example 1:  NSStrings across the bridge are easy&lt;/b&gt; if you declare a python function:      &lt;code&gt;  def myPyStringFun_(self, astring):     print &quot;The passed type is &quot; + str(type(aNumber)) &lt;/code&gt;  you will find that the Objective-C call &lt;code&gt; [mypythonobject myPyStringFun: myNSString] &lt;/code&gt; works just fine and the you&#039;ll see:   &lt;code&gt; The passed type is  &lt;/code&gt;

    &lt;b&gt; Example 2:  we run into a snag trying to pass an int across the bridge&lt;/b&gt;
       However, if you try to do something like  
&lt;code&gt; def myPyIntegerFun_(self, aNumber): 
print &quot;The passed type is &quot; + str(type(aNumber)) &lt;/code&gt;  
you&#039;ll be surprised like me to find that 
&lt;code&gt;int myInteger =  42;   
[mypythonobject myPyIntegerFun: myInteger]; &lt;/code&gt;  
completely fails.   The debugger will just exit and freak out with bad address warnings, etc -- it won&#039;t even enter the first line of your python function to tell you what was passed into it.

&lt;b&gt;Example 3:  Successfully getting an int across the PyObjC bridge&lt;/b&gt;
The bridge, as described in the documents works &lt;i&gt;bi-directionally&lt;/i&gt; (although bidirectional examples are &lt;i&gt;very difficult&lt;/i&gt; to find) using the types on Objective-C end.   In other words if you have 
&lt;code&gt; def myPyIntegerFun_(self, aNumber): 
print &quot;The passed type is &quot; + str(type(aNumber))  &lt;/code&gt;   
and you setup your Objective-C with:  
&lt;code&gt;NSNumber * tempint = [[NSNumber alloc] initWithInt:42;
tempString = [gamerObject outputAsBinary:tempint];&lt;/code&gt;&lt;code&gt;
you will be rewarded with a &lt;b&gt;happy&lt;/b&gt; Python and a log that reads
&lt;/code&gt;&lt;code&gt;The passed type is &lt;/code&gt;

&lt;b&gt;In summary:&lt;/b&gt;
(a)  From Objective-C  use an NSNumber in your method call to receive an int on the python end of things (or float, I assume).
(b)  This was done on Leopard with XCode 3 and Interface Builder 3......
(c)  By using Objective-C for the controller aspect, it makes the interface builder hooks and/or bindings straightforward    
(d)  And more importantly.... this should help keep the Python code clean and (mostly) pure python.    I have a bunch of little python tools that I want to throw front ends onto ---I&#039;d hate to re-code them with random  objc.ivar() stuff littered all over the place ---  thanks to Bob&#039;s example above and a little trial and lots of error, it&#039;s easy enough to instantiate python objects from the Objective-C side and feed those objects the values they need.

Hope that helps some more of you Python Objective-C XCode people</description>
		<content:encoded><![CDATA[<p>WOOOHOOOO!<br />
       Okay, for those of you who internet searched to get here (&#8217;cause you were suffering the same level of documentation void that I have been suffering) &#8212; I have some explanation of 2 days of struggling and trial and (lots of) error.   PyObjC really does bridge both ways, even if the examples fail to show this (which they do), you can call Python from within Objective-C code.</p>
<p>        Repeating that:  Yes, you can indeed instantiate a python class object (as demo&#8217;d by Bob in his attached source code) and call all sorts of instance methods on that object. </p>
<p>        <b>Example 1:  NSStrings across the bridge are easy</b> if you declare a python function:      <code>  def myPyStringFun_(self, astring):     print "The passed type is " + str(type(aNumber)) </code>  you will find that the Objective-C call <code> [mypythonobject myPyStringFun: myNSString] </code> works just fine and the you&#8217;ll see:   <code> The passed type is  </code></p>
<p>    <b> Example 2:  we run into a snag trying to pass an int across the bridge</b><br />
       However, if you try to do something like<br />
<code> def myPyIntegerFun_(self, aNumber):<br />
print "The passed type is " + str(type(aNumber)) </code><br />
you&#8217;ll be surprised like me to find that<br />
<code>int myInteger =  42;<br />
[mypythonobject myPyIntegerFun: myInteger]; </code><br />
completely fails.   The debugger will just exit and freak out with bad address warnings, etc &#8212; it won&#8217;t even enter the first line of your python function to tell you what was passed into it.</p>
<p><b>Example 3:  Successfully getting an int across the PyObjC bridge</b><br />
The bridge, as described in the documents works <i>bi-directionally</i> (although bidirectional examples are <i>very difficult</i> to find) using the types on Objective-C end.   In other words if you have<br />
<code> def myPyIntegerFun_(self, aNumber):<br />
print "The passed type is " + str(type(aNumber))  </code><br />
and you setup your Objective-C with:<br />
<code>NSNumber * tempint = [[NSNumber alloc] initWithInt:42;<br />
tempString = [gamerObject outputAsBinary:tempint];</code><code><br />
you will be rewarded with a <b>happy</b> Python and a log that reads<br />
</code><code>The passed type is </code></p>
<p><b>In summary:</b><br />
(a)  From Objective-C  use an NSNumber in your method call to receive an int on the python end of things (or float, I assume).<br />
(b)  This was done on Leopard with XCode 3 and Interface Builder 3&#8230;&#8230;<br />
(c)  By using Objective-C for the controller aspect, it makes the interface builder hooks and/or bindings straightforward<br />
(d)  And more importantly&#8230;. this should help keep the Python code clean and (mostly) pure python.    I have a bunch of little python tools that I want to throw front ends onto &#8212;I&#8217;d hate to re-code them with random  objc.ivar() stuff littered all over the place &#8212;  thanks to Bob&#8217;s example above and a little trial and lots of error, it&#8217;s easy enough to instantiate python objects from the Objective-C side and feed those objects the values they need.</p>
<p>Hope that helps some more of you Python Objective-C XCode people</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: red</title>
		<link>http://www.friday.com/bbum/2007/11/25/can-ruby-python-an-objective-c-co-exist-in-a-single-application/comment-page-1/#comment-186001</link>
		<dc:creator>red</dc:creator>
		<pubDate>Wed, 26 Mar 2008 22:55:29 +0000</pubDate>
		<guid isPermaLink="false">http://www.friday.com/bbum/2007/11/25/can-ruby-python-an-objective-c-co-exist-in-a-single-application/#comment-186001</guid>
		<description>Okay -- I got if figured out (for those watching these comments).
    To explain to us newbies to Objective-C:   Bob is using the @class   directive to forward declare the class.   The next line is adding a category to NSObject classes so that later on the compiler won&#039;t freak.
     
    Now -- one important thing to note is that line 57 will compile but will NOT work if you don&#039;t edit the &quot;main.py&quot; file included when you created the XCode project.   Specifically you need to make sure to import your python class declarations *BEFORE* the AppHelper line launches everything.   In the standard template you&#039;ll see the import pyxxxAppDelegate       line.    

     So far so good -- now if I could only find a way to pass an Objective-C (int) to a python instance method.</description>
		<content:encoded><![CDATA[<p>Okay &#8212; I got if figured out (for those watching these comments).<br />
    To explain to us newbies to Objective-C:   Bob is using the @class   directive to forward declare the class.   The next line is adding a category to NSObject classes so that later on the compiler won&#8217;t freak.</p>
<p>    Now &#8212; one important thing to note is that line 57 will compile but will NOT work if you don&#8217;t edit the &#8220;main.py&#8221; file included when you created the XCode project.   Specifically you need to make sure to import your python class declarations *BEFORE* the AppHelper line launches everything.   In the standard template you&#8217;ll see the import pyxxxAppDelegate       line.    </p>
<p>     So far so good &#8212; now if I could only find a way to pass an Objective-C (int) to a python instance method.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: red</title>
		<link>http://www.friday.com/bbum/2007/11/25/can-ruby-python-an-objective-c-co-exist-in-a-single-application/comment-page-1/#comment-186000</link>
		<dc:creator>red</dc:creator>
		<pubDate>Wed, 26 Mar 2008 22:55:29 +0000</pubDate>
		<guid isPermaLink="false">http://www.friday.com/bbum/2007/11/25/can-ruby-python-an-objective-c-co-exist-in-a-single-application/#comment-186000</guid>
		<description>Okay -- I got if figured out (for those watching these comments).
    To explain to us newbies to Objective-C:   Bob is using the @class   directive to forward declare the class.   The next line is adding a category to NSObject classes so that later on the compiler won&#039;t freak.
     
    Now -- one important thing to note is that line 57 will compile but will NOT work if you don&#039;t edit the &quot;main.py&quot; file included when you created the XCode project.   Specifically you need to make sure to import your python class declarations *BEFORE* the AppHelper line launches everything.   In the standard template you&#039;ll see the import pyxxxAppDelegate       line.    

     So far so good -- now if I could only find a way to pass an Objective-C (int) to a python instance method.</description>
		<content:encoded><![CDATA[<p>Okay &#8212; I got if figured out (for those watching these comments).<br />
    To explain to us newbies to Objective-C:   Bob is using the @class   directive to forward declare the class.   The next line is adding a category to NSObject classes so that later on the compiler won&#8217;t freak.</p>
<p>    Now &#8212; one important thing to note is that line 57 will compile but will NOT work if you don&#8217;t edit the &#8220;main.py&#8221; file included when you created the XCode project.   Specifically you need to make sure to import your python class declarations *BEFORE* the AppHelper line launches everything.   In the standard template you&#8217;ll see the import pyxxxAppDelegate       line.    </p>
<p>     So far so good &#8212; now if I could only find a way to pass an Objective-C (int) to a python instance method.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: red</title>
		<link>http://www.friday.com/bbum/2007/11/25/can-ruby-python-an-objective-c-co-exist-in-a-single-application/comment-page-1/#comment-185953</link>
		<dc:creator>red</dc:creator>
		<pubDate>Wed, 26 Mar 2008 01:23:43 +0000</pubDate>
		<guid isPermaLink="false">http://www.friday.com/bbum/2007/11/25/can-ruby-python-an-objective-c-co-exist-in-a-single-application/#comment-185953</guid>
		<description>WOW... you just saved me.  I&#039;ve been hunting around for hours trying to find how to actually implement the bi-directionality of the PyObjC bridge.  Specifically -- how can I have an Objective C controller referencing a Python model class.     This totally should be possible, right?      

The problem, is that every single PyObjC example has basically done the *entire* project in Python -- or they had some nasty setup scripting and bundle plugin loading crud.   This can be a pain in the butt -- I&#039;d like to use Objective-C for certain controller areas and leave Python to the data crunching.

Your example seems to work (on the python side) for dynamically loading the python class into Objective C syntax.    

Could you please explain some of the details of your AppDelegate.m  a little more (in the PyRu sample)?   I&#039;m a total noob and the learning curve is steep....   I&#039;m specifically wondering if lines 11-15 are needed for working with the python sublcass.    Or -- at line 57,  Is all that is needed is the NSClassFromString call?      Or is it a combination of both.

Once again, since this is the first actual example I found of Objective-C utilizing a Python class --- I&#039;m sure there are others out there interested.  THANKS.</description>
		<content:encoded><![CDATA[<p>WOW&#8230; you just saved me.  I&#8217;ve been hunting around for hours trying to find how to actually implement the bi-directionality of the PyObjC bridge.  Specifically &#8212; how can I have an Objective C controller referencing a Python model class.     This totally should be possible, right?      </p>
<p>The problem, is that every single PyObjC example has basically done the *entire* project in Python &#8212; or they had some nasty setup scripting and bundle plugin loading crud.   This can be a pain in the butt &#8212; I&#8217;d like to use Objective-C for certain controller areas and leave Python to the data crunching.</p>
<p>Your example seems to work (on the python side) for dynamically loading the python class into Objective C syntax.    </p>
<p>Could you please explain some of the details of your AppDelegate.m  a little more (in the PyRu sample)?   I&#8217;m a total noob and the learning curve is steep&#8230;.   I&#8217;m specifically wondering if lines 11-15 are needed for working with the python sublcass.    Or &#8212; at line 57,  Is all that is needed is the NSClassFromString call?      Or is it a combination of both.</p>
<p>Once again, since this is the first actual example I found of Objective-C utilizing a Python class &#8212; I&#8217;m sure there are others out there interested.  THANKS.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jason</title>
		<link>http://www.friday.com/bbum/2007/11/25/can-ruby-python-an-objective-c-co-exist-in-a-single-application/comment-page-1/#comment-183930</link>
		<dc:creator>Jason</dc:creator>
		<pubDate>Mon, 17 Dec 2007 15:18:10 +0000</pubDate>
		<guid isPermaLink="false">http://www.friday.com/bbum/2007/11/25/can-ruby-python-an-objective-c-co-exist-in-a-single-application/#comment-183930</guid>
		<description>This is a major bummer, as it would seem to rule out writing any sort of loadable bundle using RubyCocoa or PyObjC, unless you could be sure one and only one bridge would be loaded into the application.  So long RubyCocoa/PyObjC PreferencePanes, Mail plugin bundles, etc.  Many useful Mail.app plugin bundles on Tiger used PyObjC, for example.  Hope this is high on the list of stuff to be fixed in the next update!</description>
		<content:encoded><![CDATA[<p>This is a major bummer, as it would seem to rule out writing any sort of loadable bundle using RubyCocoa or PyObjC, unless you could be sure one and only one bridge would be loaded into the application.  So long RubyCocoa/PyObjC PreferencePanes, Mail plugin bundles, etc.  Many useful Mail.app plugin bundles on Tiger used PyObjC, for example.  Hope this is high on the list of stuff to be fixed in the next update!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Clint</title>
		<link>http://www.friday.com/bbum/2007/11/25/can-ruby-python-an-objective-c-co-exist-in-a-single-application/comment-page-1/#comment-183242</link>
		<dc:creator>Clint</dc:creator>
		<pubDate>Mon, 26 Nov 2007 16:51:19 +0000</pubDate>
		<guid isPermaLink="false">http://www.friday.com/bbum/2007/11/25/can-ruby-python-an-objective-c-co-exist-in-a-single-application/#comment-183242</guid>
		<description>Hey, I&#039;ve actually been looking around for the past week for a objc - python combination example and have yet to find one.  This works enough for me, though i don&#039;t care for ruby at the moment.  Thanks!</description>
		<content:encoded><![CDATA[<p>Hey, I&#8217;ve actually been looking around for the past week for a objc &#8211; python combination example and have yet to find one.  This works enough for me, though i don&#8217;t care for ruby at the moment.  Thanks!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ahruman</title>
		<link>http://www.friday.com/bbum/2007/11/25/can-ruby-python-an-objective-c-co-exist-in-a-single-application/comment-page-1/#comment-183211</link>
		<dc:creator>Ahruman</dc:creator>
		<pubDate>Sun, 25 Nov 2007 14:03:25 +0000</pubDate>
		<guid isPermaLink="false">http://www.friday.com/bbum/2007/11/25/can-ruby-python-an-objective-c-co-exist-in-a-single-application/#comment-183211</guid>
		<description>Oh, wait, old version of Python.framework in /Library. (This could be a bit of a problem for a real user, though…)</description>
		<content:encoded><![CDATA[<p>Oh, wait, old version of Python.framework in /Library. (This could be a bit of a problem for a real user, though…)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ahruman</title>
		<link>http://www.friday.com/bbum/2007/11/25/can-ruby-python-an-objective-c-co-exist-in-a-single-application/comment-page-1/#comment-183210</link>
		<dc:creator>Ahruman</dc:creator>
		<pubDate>Sun, 25 Nov 2007 13:58:52 +0000</pubDate>
		<guid isPermaLink="false">http://www.friday.com/bbum/2007/11/25/can-ruby-python-an-objective-c-co-exist-in-a-single-application/#comment-183210</guid>
		<description>So, er, should I be seeing an empty table and the following log messages?

&lt;blockquote&gt;Traceback (most recent call last):
  File &quot;/Users/jayton/Downloads/PyRu/build/Release/PyRu.app/Contents/Resources/main.py&quot;, line 10, in 
    import objc
ImportError: No module named objc
2007-11-25 14:56:18.660 PyRu[383:10b] /Users/jayton/Downloads/PyRu/AppDelegate.m:48 main() PyRun_SimpleFile failed with file &#039;/Users/jayton/Downloads/PyRu/build/Release/PyRu.app/Contents/Resources/main.py&#039;.  See console for errors.&lt;/blockquote&gt;</description>
		<content:encoded><![CDATA[<p>So, er, should I be seeing an empty table and the following log messages?</p>
<blockquote><p>Traceback (most recent call last):<br />
  File &#8220;/Users/jayton/Downloads/PyRu/build/Release/PyRu.app/Contents/Resources/main.py&#8221;, line 10, in<br />
    import objc<br />
ImportError: No module named objc<br />
2007-11-25 14:56:18.660 PyRu[383:10b] /Users/jayton/Downloads/PyRu/AppDelegate.m:48 main() PyRun_SimpleFile failed with file &#8216;/Users/jayton/Downloads/PyRu/build/Release/PyRu.app/Contents/Resources/main.py&#8217;.  See console for errors.</p></blockquote>
]]></content:encoded>
	</item>
	<item>
		<title>By: psu</title>
		<link>http://www.friday.com/bbum/2007/11/25/can-ruby-python-an-objective-c-co-exist-in-a-single-application/comment-page-1/#comment-183209</link>
		<dc:creator>psu</dc:creator>
		<pubDate>Sun, 25 Nov 2007 12:31:21 +0000</pubDate>
		<guid isPermaLink="false">http://www.friday.com/bbum/2007/11/25/can-ruby-python-an-objective-c-co-exist-in-a-single-application/#comment-183209</guid>
		<description>You should totally add perl too.</description>
		<content:encoded><![CDATA[<p>You should totally add perl too.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
