[MacRuby-devel] gen_bridge_metadata

Larry Wilson lwilson at mac.com
Mon Oct 18 22:34:27 PDT 2010


Laurent,

Thanks for pointing out that I was calling it as a class method.  The object I'm trying to call a method on is actually instantiated as part of the nib loading process (since its defined in the .nib file), so  I changed the name in the nib file to uiController, and then tried this...

    uiController.testCall1(10)

That didn't work either.  

Wouldn't MacRuby be able to find uiController at runtime via introspection, though? The uiController object exists before the MacRuby code that is attempting to access it gets called.  Does there have to be a pointer to the object somewhere in the sources for MacRuby to find it via introspection?  I"m not sure just how much the introspection process is able to know/understand about what exists at runtime.

gen_bridge_metadata probably isn't able to parse .nib files, correct?

-Larry

On Oct 18, 2010, at 9:49 PM, Laurent Sansonetti wrote:

> Hi Larry,
> 
> Sorry, I missed your original question.
> 
> So, you need to wrap up your private API with BridgeSupport files. Using gen_bridge_metadata is the way to go. Please note that it will generate XML files that annotate non-introspectable APIs, such as C enums, constants, structures, functions, and so on. Pure Objective-C methods will not be wrapped, as MacRuby can introspect them at runtime. This could explain why you did not see anything in the files (in this case, you probably don't even need BridgeSupport).
> 
> Regarding your testCall1 example, it seems that this is defined as an instance method in Objective-C, but you try to call it as a class method instead.
> 
>>     m = MyController
>>     x = m.testCall1.testCall1(10)
> 
> Did you try allocating a MyController instance then calling testCall1?
> 
> Laurent
> 
> On Oct 18, 2010, at 9:43 PM, Larry Wilson wrote:
> 
>> I'm still searching for some answers to my original question regarding calling across from objective-C to MacRuby, and vice-versa.  I've done some experimenting, and had some success with a private framework, but still haven't figured out some of the bridging stuff...
>> 
>> I created an objective-C framework, and I can instantiate an object of a class (Foo) defined in the framework (linked into the EmbeddedMacRuby project), and am able to call a method on that class from a MacRuby script...
>> 
>>     f = Foo.new()
>>     x = f.doLoopTest1(10)
>> 
>> However, I'm unable to call a method on my objective-C UI controller class.  I'm working off the EmbeddedMacRuby project, and have added a method to MyController (which is the objective-C class controller for the UI).
>> 
>> The method is defined as:
>> 
>> - (int) testCall1:(int) loopCount
>> 
>> I've tried various methods of calling it..
>> 
>>     m = MyController
>>     x = m.testCall1.testCall1(10)
>> 
>> However, I'm getting the following error message (indicating that it doesn't know about the method)...
>> 
>>     NoMethodError: undefined method `testCall1' for MyController:Class (NoMethodError)
>> 
>>     (null)
>> 
>> How do I expose methods of an objective-C class (not in a framework, but in the main application) to MacRuby code so that I can call into it from MacRuby?  I've tried gen_bridge_metadata (see original message) with no success.  I'm not sure if gen_bride_metadata is required to expose the objective-c controller object to the MacRuby code, or if I'm just not setting something else up properly.
>> 
>> I'm also still curious about how to call from objective-C code in my application (from MyController, for instance) to a MacRuby function, and then grab the return value in objective-C when the MacRuby function returns.  Can anyone point me to some sample code?
>> 
>> I've updated to the latest version of MacRuby.
>> 
>> Thanks.
>> 
>> -Larry
>> 
>> 
>> On Oct 14, 2010, at 6:58 PM, Larry Wilson wrote:
>> 
>>> 
>>> I've been playing around with the EmbeddedMacRuby project.  
>>> 
>>> I'd like to be able to:
>>> 
>>>  a) Run user scripts (written in Ruby) from within a cocoa application (so far, so good)
>>>  b) Call ruby functions from objective-c
>>>  c) Call my private objective-c API's from Ruby functions and scripts
>>> 
>>> I'm having problems with b & c.
>>> 
>>> I'm assuming that the mechanism for b & c is different than that used to execute a Ruby script.  It looks like gen_bridge_metadata script should be used to make my objective-c class and methods visible to Ruby.
>>> 
>>> However, when I try to run gen_bridge_metadata on a simple header file that declares an objective-c class and a couple of test methods, gen_bridge_metadata doesn't produce anything in the output file other than the 3 lines of header information...
>>> 
>>>  1 <?xml version='1.0'?>
>>>  2 <!DOCTYPE signatures SYSTEM "file://localhost/System/Library/DTDs/BridgeSupport.dtd">
>>>  3 <signatures version='0.9'/>
>>> 
>>> I'm running the tool as follows (I've also tried a number of other variations):
>>> 
>>> 	gen_bridge_metadata -c '-I.' MyController.h -o MyController.bridgesupport 
>>> 
>>> I'm running 10.6.4,   ruby 1.8.7 , with macRuby 0.7 installed.
>>> 
>>> I also have ruby1.9 installed.
>>> 
>>> Questions...
>>> 
>>> 1) Shouldn't this produce at least simple output with information regarding the class and method calls?
>>> 
>>> 2) Is there some documentation (or examples) somewhere that shows how to set things up properly to enable items b & c?  I haven't been able to find anything in the documentation, or on the web that actually demonstrates how to do this, and gen_bridge_metadata doesn't seem to be cooperating.
>>> 
>>> Any pointers or suggestions welcome.
>>> 
>>> 
>>> Thanks.
>>> 
>>> -Larry
>>> 
>>> _______________________________________________
>>> MacRuby-devel mailing list
>>> MacRuby-devel at lists.macosforge.org
>>> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
>> 
>> _______________________________________________
>> MacRuby-devel mailing list
>> MacRuby-devel at lists.macosforge.org
>> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
> 
> _______________________________________________
> MacRuby-devel mailing list
> MacRuby-devel at lists.macosforge.org
> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-devel/attachments/20101018/436cecf9/attachment-0001.html>


More information about the MacRuby-devel mailing list