[MacRuby-devel] gen_bridge_metadata

Larry Wilson lwilson at mac.com
Mon Oct 18 21:43:09 PDT 2010


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

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


More information about the MacRuby-devel mailing list