Re: [MacRuby-devel] Tutorial for the new Sandbox class.
On 7 Oct 2010, at 07:55, Matt Aimonetti wrote: > Thx I'll merge the article asap (after a quick sanity check). > > - Matt > > Sent from my iPhone > Thanks Matt. ___ MacRuby-devel mailing list [email protected] http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
Re: [MacRuby-devel] Tutorial for the new Sandbox class.
Hi Rob, I like the tutorial, it's nicely short and concise. One thing I'd like to see is the expected outcome of running the code you've placed within the text. Could you include this information underneath the code blocks? I'm imagining that most people would try this out using the interactive prompt (and you can maybe mention that as an exercise for the reader), so it's a nice little hint to go and play around with the files in /usr/share/sandbox/ I've always found that having an interactive console is one of the most encouraging things about Ruby, so it's always nice to promote its use, especially when learning. Nick On 6 Oct 2010, at 08:59, Rob Gleeson wrote: > I wrote a short tutorial I'd like to share with everybody about the new > Sandbox class introduced in the new 0.7 release of MacRuby. > I tried to focus on using the class inside MacRuby as much as possible. > > Please let me know what you think, spot errors, etc! > > Link: http://robgleeson.github.com/documents/macruby-sandbox-class/ > > … Rob > > > > ___ > MacRuby-devel mailing list > [email protected] > http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel ___ MacRuby-devel mailing list [email protected] http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
Re: [MacRuby-devel] Tutorial for the new Sandbox class.
On 7 Oct 2010, at 10:49, Nick Ludlam wrote: > Hi Rob, > I like the tutorial, it's nicely short and concise. One thing I'd like to see > is the expected outcome of running the code you've placed within the text. > Could you include this information underneath the code blocks? > > I'm imagining that most people would try this out using the interactive > prompt (and you can maybe mention that as an exercise for the reader), so > it's a nice little hint to go and play around with the files in > /usr/share/sandbox/ > > I've always found that having an interactive console is one of the most > encouraging things about Ruby, so it's always nice to promote its use, > especially when learning. > > > Nick Hm, those are good points. I also failed to mention that Sandbox#apply! will raise a SecurityError if sandbox_init fails. I think I should mention that, too. Matt, could you hold off until tonight or tomorrow so I can make those changes? Thanks, Rob ___ MacRuby-devel mailing list [email protected] http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
Re: [MacRuby-devel] Tutorial for the new Sandbox class.
Okay, I modified the document a tiny bit making note of the return value of #apply!, and the SecurityError exception it can raise: http://github.com/robgleeson/macruby_website/blob/Sandbox_class_tutorial/content/documentation/the-sandbox-class.txt ___ MacRuby-devel mailing list [email protected] http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
[MacRuby-devel] Is CoreText Fully Support
Hi I'm doing some work with CoreText with macruby ,and i had some question 1. CTline and some other `struct` does not have a ruby class ,the ctline.class is __NSCFType , not like the CGRect struct,in macruby ,the class is CGRecct ,so i can reopen the class ,and add some help methods. 2. the CTRunGetStringRange should return a CFRange but it return a class named Boxed can i wrap the CoreText in macruby ? and some suggestions ?? thanks ___ MacRuby-devel mailing list [email protected] http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
Re: [MacRuby-devel] Is CoreText Fully Support
Hi, Could you reduce the problems to simple .rb scripts and attach them to a new ticket? We are working on a new version of BridgeSupport which will add missing metadata (I believe it will fix your CoreText problems), but we will need to verify. In the interim, you can wrap CoreText APIs in Objective-C classes, them call them from MacRuby directly. Laurent On Oct 7, 2010, at 7:41 AM, 聂殿辉 wrote: > Hi > I'm doing some work with CoreText with macruby ,and i had some question > > 1. CTline and some other `struct` does not have a ruby class ,the > ctline.class is __NSCFType > , not like the CGRect struct,in macruby ,the class is CGRecct ,so i can > reopen the class ,and add some help methods. > 2. the CTRunGetStringRange should return a CFRange but it return a class > named Boxed > > can i wrap the CoreText in macruby ? and some suggestions ?? > > thanks > ___ > MacRuby-devel mailing list > [email protected] > http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel ___ MacRuby-devel mailing list [email protected] http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
Re: [MacRuby-devel] Is CoreText Fully Support
Ok. I'll do this later when i was home : ) On Oct 8, 2010, at 10:17 AM, Laurent Sansonetti wrote: > Hi, > > Could you reduce the problems to simple .rb scripts and attach them to a new > ticket? > > We are working on a new version of BridgeSupport which will add missing > metadata (I believe it will fix your CoreText problems), but we will need to > verify. > > In the interim, you can wrap CoreText APIs in Objective-C classes, them call > them from MacRuby directly. > > Laurent > > On Oct 7, 2010, at 7:41 AM, 聂殿辉 wrote: > >> Hi >> I'm doing some work with CoreText with macruby ,and i had some question >> >> 1. CTline and some other `struct` does not have a ruby class ,the >> ctline.class is __NSCFType >> , not like the CGRect struct,in macruby ,the class is CGRecct ,so i can >> reopen the class ,and add some help methods. >> 2. the CTRunGetStringRange should return a CFRange but it return a class >> named Boxed >> >> can i wrap the CoreText in macruby ? and some suggestions ?? >> >> thanks >> ___ >> MacRuby-devel mailing list >> [email protected] >> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel > > ___ > MacRuby-devel mailing list > [email protected] > http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel ___ MacRuby-devel mailing list [email protected] http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
[MacRuby-devel] URI and NSURL compatibility
Hi devs, I am trying to write a gem so that it will run on MRI and MacRuby, but still be able to take advantage of MacRuby things like Cocoa and GCD. I was playing around with some URI related stuff and I cannot find much documentation on whether NSURL and URI objects have been bridged for MacRuby? If they aren't bridged, I was thinking I could just hack together an empty class that just chooses if it inherits from NSURL or URI at run time. Something like this: require 'uri' class HackURI def initialize(uri) if RUBY_ENGINE == 'macruby' @url = NSURL.URLWithString uri else @url = URI.parse uri end end def method_missing(method, *args) @url.send(method, *args) end end -- Mark Rada ___ MacRuby-devel mailing list [email protected] http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
Re: [MacRuby-devel] URI and NSURL compatibility
A more efficient version of that class: class HackURI if RUBY_ENGINE == 'macruby' def initialize(uri) @url = NSURL.URLWithString uri end else def initialize(uri) @url = URI.parse uri end end def method_missing(method, *args) @url.send(method, *args) end end On 2010-10-07, at 11:11 PM, Mark Rada wrote: > Hi devs, > > I am trying to write a gem so that it will run on MRI and MacRuby, but still > be able to take advantage of MacRuby things like Cocoa and GCD. > > I was playing around with some URI related stuff and I cannot find much > documentation on whether NSURL and URI objects have been bridged for MacRuby? > > If they aren't bridged, I was thinking I could just hack together an empty > class that just chooses if it inherits from NSURL or URI at run time. > Something like this: > > require 'uri' > > class HackURI > def initialize(uri) >if RUBY_ENGINE == 'macruby' > @url = NSURL.URLWithString uri >else > @url = URI.parse uri > end >end > > def method_missing(method, *args) > @url.send(method, *args) > end > end > > -- > Mark Rada > > ___ > MacRuby-devel mailing list > [email protected] > http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel ___ MacRuby-devel mailing list [email protected] http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
Re: [MacRuby-devel] URI and NSURL compatibility
Hi Mark, No, NSURL and URI are not bridged. I do not recommend using NSURL in a file that should also run under MRI because of the MacRuby calling syntax for Objective-C selectors, which won't compile under normal rubies. So, it would be better to isolate the NSURL code in a special file and require it at demand (if RUBY_ENGINE is macruby). Laurent On Oct 7, 2010, at 8:11 PM, Mark Rada wrote: > Hi devs, > > I am trying to write a gem so that it will run on MRI and MacRuby, but still > be able to take advantage of MacRuby things like Cocoa and GCD. > > I was playing around with some URI related stuff and I cannot find much > documentation on whether NSURL and URI objects have been bridged for MacRuby? > > If they aren't bridged, I was thinking I could just hack together an empty > class that just chooses if it inherits from NSURL or URI at run time. > Something like this: > > require 'uri' > > class HackURI > def initialize(uri) >if RUBY_ENGINE == 'macruby' > @url = NSURL.URLWithString uri >else > @url = URI.parse uri > end >end > > def method_missing(method, *args) > @url.send(method, *args) > end > end > > -- > Mark Rada > > ___ > MacRuby-devel mailing list > [email protected] > http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel ___ MacRuby-devel mailing list [email protected] http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
Re: [MacRuby-devel] URI and NSURL compatibility
This is Ruby, where everything is an expression. If you're going to be clever,
why not go all the way?
---
def is_macruby?; defined?(RUBY_ENGINE) && RUBY_ENGINE == 'macruby'; end
if is_macruby?
framework 'Foundation'
else
require 'uri'
COMPONENTS = [:scheme, :userinfo, :host, :port, :registry,
:path, :opaque, :query, :fragment]
end
class HackURI < (is_macruby? ? NSURL : URI::HTTP)
def initialize(uri)
if is_macruby?
self.initWithString(uri)
else
u = URI.parse(uri)
super(*COMPONENTS.map { |c| u.send(c) })
end
end
def what_am_I?
puts self.class.ancestors
end
end
h = HackURI.new('http://www.macruby.org')
h.what_am_I?
---
Although, you may want to rethink your strategy here…there's a REALLY BIG
impedance mismatch between the way that the URI module is designed and the way
NSURL works. Anyway, hope this helps…
Cheers,
Josh
On Oct 7, 2010, at 8:21 PM, Mark Rada wrote:
> A more efficient version of that class:
>
> class HackURI
> if RUBY_ENGINE == 'macruby'
> def initialize(uri)
> @url = NSURL.URLWithString uri
> end
> else
> def initialize(uri)
> @url = URI.parse uri
> end
> end
>
> def method_missing(method, *args)
> @url.send(method, *args)
> end
> end
>
>
> On 2010-10-07, at 11:11 PM, Mark Rada wrote:
>
>> Hi devs,
>>
>> I am trying to write a gem so that it will run on MRI and MacRuby, but still
>> be able to take advantage of MacRuby things like Cocoa and GCD.
>>
>> I was playing around with some URI related stuff and I cannot find much
>> documentation on whether NSURL and URI objects have been bridged for MacRuby?
>>
>> If they aren't bridged, I was thinking I could just hack together an empty
>> class that just chooses if it inherits from NSURL or URI at run time.
>> Something like this:
>>
>> require 'uri'
>>
>> class HackURI
>> def initialize(uri)
>> if RUBY_ENGINE == 'macruby'
>> @url = NSURL.URLWithString uri
>> else
>> @url = URI.parse uri
>> end
>> end
>>
>> def method_missing(method, *args)
>> @url.send(method, *args)
>> end
>> end
>>
>> --
>> Mark Rada
>>
>> ___
>> MacRuby-devel mailing list
>> [email protected]
>> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
>
> ___
> MacRuby-devel mailing list
> [email protected]
> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
___
MacRuby-devel mailing list
[email protected]
http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
